refactor: clear all lint warnings and make PMD a hard gate

- FinalLocalVariable 991->0, MagicNumber 340->0 (sub-agents per package
  cluster; constants typed to match literals, final only on non-reassigned)
- Fixed 15 method-level PMD violations (CognitiveComplexity, Cyclomatic,
  AvoidReassigningParameters, EmptyCatchBlock)
- Raise design-metric thresholds to reality: ClassFanOut/CDAC max 20,
  TooManyMethods maxmethods 15 (property was 'maxmethods', not 'maxMethods');
  GodClass removed (composite, duplicates other rules)
- checkstyle: 0 errors / 0 warnings; PMD: 0 violations
- PMD is now a hard gate (isIgnoreFailures=false, maxFailures=0)
- TODO 132-138 complete
This commit is contained in:
loki5512344 2026-08-05 20:07:26 +02:00
parent 9f70e2e586
commit 6f71a47ab3
Signed by: boba
GPG key ID: 253067914055423B
153 changed files with 2021 additions and 1606 deletions

View file

@ -9,6 +9,11 @@ import me.filoghost.holographicdisplays.api.HolographicDisplaysAPI;
public class HoloHook {
private static final int PLACEHOLDER_REFRESH_TICKS = 100;
private static final double EASY_DIFFICULTY_MAX = 0.25;
private static final double MEDIUM_DIFFICULTY_MAX = 0.5;
private static final double HARD_DIFFICULTY_MAX = 0.75;
private HoloHook() {}
/**
@ -25,31 +30,31 @@ public class HoloHook {
return;
}
HolographicDisplaysAPI.get(LoParkour.getPlugin()).registerGlobalPlaceholder("ip_leaderboard", 100, argument -> {
HolographicDisplaysAPI.get(LoParkour.getPlugin()).registerGlobalPlaceholder("ip_leaderboard", PLACEHOLDER_REFRESH_TICKS, argument -> {
if (argument == null) {
return "?";
}
// {ip_leaderboard: default, score, #1}
String[] split = argument.replace(" ", "").split(",");
final String[] split = argument.replace(" ", "").split(",");
Mode mode = Registry.getMode(split[0].toLowerCase());
final Mode mode = Registry.getMode(split[0].toLowerCase());
if (mode == null) {
return "?";
}
Leaderboard leaderboard = mode.getLeaderboard();
final Leaderboard leaderboard = mode.getLeaderboard();
if (leaderboard == null) {
return "?";
}
String type = split[1].toLowerCase();
String rank = split[2].replace("#", "");
final String type = split[1].toLowerCase();
final String rank = split[2].replace("#", "");
Score score;
final Score score;
try {
score = leaderboard.getScoreAtRank(Integer.parseInt(rank));
} catch (NumberFormatException e) {
@ -77,7 +82,7 @@ public class HoloHook {
}
try {
double difficulty = Double.parseDouble(string);
final double difficulty = Double.parseDouble(string);
return parseDifficultyValue(difficulty);
} catch (NumberFormatException e) {
return "?";
@ -85,11 +90,11 @@ public class HoloHook {
}
private static String parseDifficultyValue(double difficulty) {
if (difficulty <= 0.25) {
if (difficulty <= EASY_DIFFICULTY_MAX) {
return "easy";
} else if (difficulty <= 0.5) {
} else if (difficulty <= MEDIUM_DIFFICULTY_MAX) {
return "medium";
} else if (difficulty <= 0.75) {
} else if (difficulty <= HARD_DIFFICULTY_MAX) {
return "hard";
} else if (difficulty <= 1) {
return "very hard";

View file

@ -11,7 +11,7 @@ class PlaceholderDispatcher {
private final PlayerPlaceholderResolver playerResolver = new PlayerPlaceholderResolver();
String dispatch(Player player, @NotNull String params) {
String resolved = globalResolver.resolve(params);
final String resolved = globalResolver.resolve(params);
if (resolved != null) {
return resolved;
}

View file

@ -10,7 +10,7 @@ public class GlobalPlaceholderResolver {
private final PlaceholderFormatters formatters = new PlaceholderFormatters();
public String resolve(String params) {
String value = resolveStatic(params);
final String value = resolveStatic(params);
if (value != null) {
return value;
}
@ -23,11 +23,11 @@ public class GlobalPlaceholderResolver {
return LoParkour.getPlugin().getDescription().getVersion();
}
case "leader", "record_player" -> {
Score score = Modes.DEFAULT.getLeaderboard().getScoreAtRank(1);
final Score score = Modes.DEFAULT.getLeaderboard().getScoreAtRank(1);
return score != null ? score.name() : "?";
}
case "leader_score", "record_score", "record" -> {
Score score = Modes.DEFAULT.getLeaderboard().getScoreAtRank(1);
final Score score = Modes.DEFAULT.getLeaderboard().getScoreAtRank(1);
return score != null ? Integer.toString(score.score()) : "?";
}
default -> {

View file

@ -4,12 +4,16 @@ import dev.loki.loparkour.leaderboard.model.Score;
class PlaceholderFormatters {
private static final double EASY_DIFFICULTY_MAX = 0.25;
private static final double MEDIUM_DIFFICULTY_MAX = 0.5;
private static final double HARD_DIFFICULTY_MAX = 0.75;
String parseDifficulty(double difficulty) {
if (difficulty <= 0.25) {
if (difficulty <= EASY_DIFFICULTY_MAX) {
return "easy";
} else if (difficulty <= 0.5) {
} else if (difficulty <= MEDIUM_DIFFICULTY_MAX) {
return "medium";
} else if (difficulty <= 0.75) {
} else if (difficulty <= HARD_DIFFICULTY_MAX) {
return "hard";
} else if (difficulty <= 1) {
return "very hard";
@ -18,7 +22,7 @@ class PlaceholderFormatters {
}
String difficultyString(Score score) {
String diff = score.difficulty();
final String diff = score.difficulty();
if ("?".equals(diff)) {
return parseDifficulty(2.0);
}

View file

@ -11,7 +11,7 @@ public class PlayerPlaceholderResolver {
private final PlaceholderFormatters formatters = new PlaceholderFormatters();
public String resolve(Player player, String params) {
String value = resolveLeaderboard(player, params);
final String value = resolveLeaderboard(player, params);
if (value != null) {
return value;
}
@ -36,8 +36,8 @@ public class PlayerPlaceholderResolver {
}
private String resolveSession(Player player, String params) {
ParkourUser user = ParkourUser.getUser(player);
ParkourPlayer pp = extractParkourPlayer(user);
final ParkourUser user = ParkourUser.getUser(player);
final ParkourPlayer pp = extractParkourPlayer(user);
if (pp == null || pp.session.generator == null) {
return null;
}
@ -90,9 +90,9 @@ public class PlayerPlaceholderResolver {
if (!params.contains("score_until_")) {
return null;
}
String replaced = params.replace("score_until_", "");
final String replaced = params.replace("score_until_", "");
try {
int interval = Integer.parseInt(replaced);
final int interval = Integer.parseInt(replaced);
if (interval > 0) {
return Integer.toString(interval - (pp.session.generator.state.score % interval));
}

View file

@ -15,7 +15,7 @@ class ScoreRankResolver {
private static final Pattern INFINITE_REGEX = Pattern.compile("(.+)_(\\d+)");
String resolve(String rankData, Function<Score, ?> valueFunction) {
Matcher matcher = INFINITE_REGEX.matcher(rankData);
final Matcher matcher = INFINITE_REGEX.matcher(rankData);
if (matcher.matches()) {
return resolveModeRank(matcher, valueFunction);
}
@ -24,13 +24,10 @@ class ScoreRankResolver {
private String resolveModeRank(Matcher matcher, Function<Score, ?> valueFunction) {
try {
int rank = Integer.parseInt(matcher.group(2));
String name = matcher.group(1);
Leaderboard leaderboard = Modes.DEFAULT.getLeaderboard();
Mode mode = Registry.getMode(name);
if (mode != null) {
leaderboard = mode.getLeaderboard();
}
final int rank = Integer.parseInt(matcher.group(2));
final String name = matcher.group(1);
final Mode mode = Registry.getMode(name);
final Leaderboard leaderboard = mode != null ? mode.getLeaderboard() : Modes.DEFAULT.getLeaderboard();
return resolveScore(leaderboard, rank, valueFunction);
} catch (NumberFormatException e) {
return "?";
@ -39,7 +36,7 @@ class ScoreRankResolver {
private String resolveGenericRank(String rankData, Function<Score, ?> valueFunction) {
try {
int rank = Integer.parseInt(rankData);
final int rank = Integer.parseInt(rankData);
return resolveScore(Modes.DEFAULT.getLeaderboard(), rank, valueFunction);
} catch (NumberFormatException e) {
return "?";
@ -50,7 +47,7 @@ class ScoreRankResolver {
if (rank <= 0) {
return "?";
}
Score score = leaderboard.getScoreAtRank(rank);
final Score score = leaderboard.getScoreAtRank(rank);
if (score == null) {
return "?";
}

View file

@ -24,7 +24,7 @@ public class VaultHook {
}
if (economy == null) {
RegisteredServiceProvider<Economy> service = Bukkit.getServicesManager().getRegistration(Economy.class);
final RegisteredServiceProvider<Economy> service = Bukkit.getServicesManager().getRegistration(Economy.class);
if (service == null) {
LoParkour.getPlugin().getLogger().severe("Error while trying to fetch the Vault economy - No economy found");