- 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
104 lines
3.4 KiB
Java
104 lines
3.4 KiB
Java
package dev.loki.loparkour.hook.holo;
|
|
|
|
import dev.loki.loparkour.LoParkour;
|
|
import dev.loki.loparkour.api.core.Registry;
|
|
import dev.loki.loparkour.leaderboard.core.Leaderboard;
|
|
import dev.loki.loparkour.leaderboard.model.Score;
|
|
import dev.loki.loparkour.mode.base.Mode;
|
|
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() {}
|
|
|
|
/**
|
|
* Initializes this hook.
|
|
*/
|
|
public static void init() {
|
|
try {
|
|
Class.forName("me.filoghost.holographicdisplays.api.HolographicDisplaysAPI");
|
|
} catch (Exception ex) {
|
|
LoParkour.getPlugin().getLogger().warning("##");
|
|
LoParkour.getPlugin().getLogger().warning("## LoParkour only supports Holographic Displays v3.0.0 or higher!");
|
|
LoParkour.getPlugin().getLogger().warning("## This hook will now be disabled.");
|
|
LoParkour.getPlugin().getLogger().warning("##");
|
|
return;
|
|
}
|
|
|
|
HolographicDisplaysAPI.get(LoParkour.getPlugin()).registerGlobalPlaceholder("ip_leaderboard", PLACEHOLDER_REFRESH_TICKS, argument -> {
|
|
|
|
if (argument == null) {
|
|
return "?";
|
|
}
|
|
|
|
// {ip_leaderboard: default, score, #1}
|
|
final String[] split = argument.replace(" ", "").split(",");
|
|
|
|
final Mode mode = Registry.getMode(split[0].toLowerCase());
|
|
|
|
if (mode == null) {
|
|
return "?";
|
|
}
|
|
|
|
final Leaderboard leaderboard = mode.getLeaderboard();
|
|
|
|
if (leaderboard == null) {
|
|
return "?";
|
|
}
|
|
|
|
final String type = split[1].toLowerCase();
|
|
final String rank = split[2].replace("#", "");
|
|
|
|
final Score score;
|
|
try {
|
|
score = leaderboard.getScoreAtRank(Integer.parseInt(rank));
|
|
} catch (NumberFormatException e) {
|
|
return "?";
|
|
}
|
|
|
|
if (score == null) {
|
|
return "?";
|
|
}
|
|
|
|
return switch (type) {
|
|
case "score" -> Integer.toString(score.score());
|
|
case "name" -> score.name();
|
|
case "time" -> score.time();
|
|
case "difficulty" -> score.difficulty();
|
|
case "difficulty_string" -> parseDifficulty(score.difficulty());
|
|
default -> "?";
|
|
};
|
|
});
|
|
}
|
|
|
|
private static String parseDifficulty(String string) {
|
|
if (string.contains("?")) {
|
|
return "?";
|
|
}
|
|
|
|
try {
|
|
final double difficulty = Double.parseDouble(string);
|
|
return parseDifficultyValue(difficulty);
|
|
} catch (NumberFormatException e) {
|
|
return "?";
|
|
}
|
|
}
|
|
|
|
private static String parseDifficultyValue(double difficulty) {
|
|
if (difficulty <= EASY_DIFFICULTY_MAX) {
|
|
return "easy";
|
|
} else if (difficulty <= MEDIUM_DIFFICULTY_MAX) {
|
|
return "medium";
|
|
} else if (difficulty <= HARD_DIFFICULTY_MAX) {
|
|
return "hard";
|
|
} else if (difficulty <= 1) {
|
|
return "very hard";
|
|
}
|
|
return "?";
|
|
}
|
|
}
|