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

@ -19,6 +19,11 @@ import java.util.Map;
*/
public class OptionGeneral {
private static final int MAX_LEAD = 128;
private static final int MIN_AXIS_VALUES = 4;
private static final int WORLD_VALUE_INDEX = 3;
private static final int FALLBACK_Y = 100;
private OptionGeneral() {
}
@ -41,55 +46,66 @@ public class OptionGeneral {
}
public static void initOptions() {
List<ParkourOption> options = new ArrayList<>(Arrays.asList(ParkourOption.values()));
final List<ParkourOption> options = new ArrayList<>(Arrays.asList(ParkourOption.values()));
options.remove(ParkourOption.JOIN);
options.remove(ParkourOption.ADMIN);
OPTIONS_DEFAULTS = new HashMap<>();
OPTIONS_ENABLED = new HashMap<>();
for (ParkourOption option : options) {
String parent = "default-values." + option.path;
OPTIONS_ENABLED.put(option, Config.CONFIG.getBoolean(parent + ".enabled"));
for (final ParkourOption option : options) {
applyOption(option);
}
}
String defaultPath = parent + ".default";
if (Config.CONFIG.isPath(defaultPath)) {
String value = Config.CONFIG.getString(defaultPath);
private static void applyOption(ParkourOption option) {
final String parent = "default-values." + option.path;
OPTIONS_ENABLED.put(option, Config.CONFIG.getBoolean(parent + ".enabled"));
// Sanitize legacy Boolean values for LANG option
if (option == ParkourOption.LANG &&
("true".equals(value) || "false".equals(value) || "1".equals(value) || "0".equals(value))) {
value = "en";
LoParkour.getPlugin().getLogger().warning(
"LANG option had invalid Boolean value, reset to 'en'");
}
final String defaultPath = parent + ".default";
if (Config.CONFIG.isPath(defaultPath)) {
applyDefaultValue(option, defaultPath);
} else {
warnMissingDefault(option, defaultPath);
}
}
// Debug logging
if (option == ParkourOption.LANG) {
LoParkour.getPlugin().getLogger().info(
"LANG option: path=" + defaultPath + ", value=" + value);
}
private static void applyDefaultValue(ParkourOption option, String defaultPath) {
String value = Config.CONFIG.getString(defaultPath);
if (value != null && !value.isEmpty()) {
OPTIONS_DEFAULTS.put(option, value);
}
} else {
// Debug: path not found
if (option == ParkourOption.LANG) {
LoParkour.getPlugin().getLogger().warning("LANG default path not found: " + defaultPath);
LoParkour.getPlugin().getLogger().warning(
"Available keys: " + Config.CONFIG.fileConfiguration.getKeys(true));
}
}
// Sanitize legacy Boolean values for LANG option
if (option == ParkourOption.LANG &&
("true".equals(value) || "false".equals(value) || "1".equals(value) || "0".equals(value))) {
value = "en";
LoParkour.getPlugin().getLogger().warning(
"LANG option had invalid Boolean value, reset to 'en'");
}
// Debug logging
if (option == ParkourOption.LANG) {
LoParkour.getPlugin().getLogger().info(
"LANG option: path=" + defaultPath + ", value=" + value);
}
if (value != null && !value.isEmpty()) {
OPTIONS_DEFAULTS.put(option, value);
}
}
private static void warnMissingDefault(ParkourOption option, String defaultPath) {
if (option == ParkourOption.LANG) {
LoParkour.getPlugin().getLogger().warning("LANG default path not found: " + defaultPath);
LoParkour.getPlugin().getLogger().warning(
"Available keys: " + Config.CONFIG.fileConfiguration.getKeys(true));
}
}
private static void initGoBackLocation() {
GO_BACK_LOC = parseLocation(Config.CONFIG.getString("bungeecord.go-back"));
try {
String axesRaw = Config.CONFIG.getString("bungeecord.go-back-axes");
final String axesRaw = Config.CONFIG.getString("bungeecord.go-back-axes");
if (!axesRaw.isEmpty()) {
String[] axes = axesRaw.split(",");
final String[] axes = axesRaw.split(",");
if (axes.length >= 2) {
GO_BACK_LOC.setPitch(Float.parseFloat(axes[0].trim()));
GO_BACK_LOC.setYaw(Float.parseFloat(axes[1].trim()));
@ -102,8 +118,8 @@ public class OptionGeneral {
private static void initLeads() {
POSSIBLE_LEADS = Config.CONFIG.getIntList("options.leads.amount");
for (int lead : new ArrayList<>(POSSIBLE_LEADS)) {
if (lead < 1 || lead > 128) {
for (final int lead : new ArrayList<>(POSSIBLE_LEADS)) {
if (lead < 1 || lead > MAX_LEAD) {
LoParkour.getPlugin().getLogger().severe(
"Invalid lead: %d. Must be 1–128.".formatted(lead));
POSSIBLE_LEADS.remove((Object) lead);
@ -112,7 +128,7 @@ public class OptionGeneral {
}
private static void initHeading() {
String heading = Config.GENERATION.getString("advanced.island.parkour.heading");
final String heading = Config.GENERATION.getString("advanced.island.parkour.heading");
HEADING = switch (heading.toLowerCase()) {
case "north" -> BlockFace.NORTH;
case "south" -> BlockFace.SOUTH;
@ -127,11 +143,11 @@ public class OptionGeneral {
private static Location parseLocation(String location) {
try {
String[] values = location.replaceAll("[()]", "").replaceAll("[, ]", " ").trim().split("\\s+");
if (values.length < 4) {
final String[] values = location.replaceAll("[()]", "").replaceAll("[, ]", " ").trim().split("\\s+");
if (values.length < MIN_AXIS_VALUES) {
throw new IllegalArgumentException("Expected 4 values (x,y,z,world), got " + values.length);
}
World world = Bukkit.getWorld(values[3]);
World world = Bukkit.getWorld(values[WORLD_VALUE_INDEX]);
if (world == null) {
world = Bukkit.getWorlds().get(0);
}
@ -140,8 +156,8 @@ public class OptionGeneral {
} catch (Exception ex) {
LoParkour.getPlugin().getLogger().warning(
"Invalid bungeecord.go-back value '" + location + "'. Falling back to spawn world origin.");
World fallback = Bukkit.getWorlds().isEmpty() ? null : Bukkit.getWorlds().get(0);
return new Location(fallback, 0, 100, 0);
final World fallback = Bukkit.getWorlds().isEmpty() ? null : Bukkit.getWorlds().get(0);
return new Location(fallback, 0, FALLBACK_Y, 0);
}
}
}