LoParkour/src/main/java/dev/loki/loparkour/LoParkour.java
loki5512344 02e2947f47
refactor(player): encapsulate game state behind PlayerSettings, clear VisibilityModifier and HiddenField
- ParkourUser/ParkourPlayer/GeneratorState public mutable fields -> private + short accessors
- per-player settings extracted to player/data/PlayerSettings (ParkourPlayer 188 -> 96 lines,
  PMD-counted methods 20 -> 9); this is what fixed the TooManyMethods violation that the
  encapsulation itself introduced — by decomposition, not by lowering the threshold
- disk storage reads and writes the same canonical 12-key map as the SQL JSON column;
  legacy key names normalized on read, @Expose dropped from domain classes
- 39 settings call sites rewritten across 7 files
- HiddenField backlog cleared (Config, ObstacleGenerator, GhostService, Leaderboard,
  PagedMenu, Reward, ParticleData, World)
- checkstyle ratchet: VisibilityModifier, HiddenField, EmptyLineSeparator and
  MissingDeprecated flipped to error once their counters hit zero; suppressions.xml empty
- javac -Xmaxwarns raised so NullAway/Error Prone counts are honest
  (baseline 165/289, now 164/265)

checkstyle 0 errors / 135 warnings, PMD 0 violations, tests 94/0 fail, ./gradlew check green.
TODO.md: items 30 and 107 updated, new items 167-170, ПРОГРЕСС-6/7 recorded.
2026-10-06 18:57:39 +02:00

132 lines
3.8 KiB
Java

package dev.loki.loparkour;
import dev.loki.loparkour.bootstrap.PluginBootstrap;
import dev.loki.loparkour.config.core.Config;
import dev.loki.loparkour.ghost.service.GhostService;
import dev.loki.loparkour.hook.papi.PAPIHook;
import dev.loki.loparkour.mode.base.Modes;
import dev.loki.loparkour.player.core.ParkourUser;
import dev.loki.loparkour.reward.core.Rewards;
import dev.loki.loparkour.schematic.core.SchematicManager;
import dev.loki.loparkour.storage.Storage;
import dev.loki.loparkour.world.core.Divider;
import dev.loki.loparkour.world.core.World;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.util.ArrayList;
import java.util.logging.Level;
/**
* Main class of LoParkour
*
* @author loki
*/
public final class LoParkour extends JavaPlugin {
public static final String NAME = "&#FF6464&lLoParkour&r";
public static final String PREFIX = NAME + " &#404040» &#A0A0A0";
private static final Gson GSON = new GsonBuilder()
.setPrettyPrinting()
.excludeFieldsWithoutExposeAnnotation()
.create();
private static LoParkour instance;
private static SchematicManager schematicManager;
private static GhostService ghostService;
@Nullable
private static PAPIHook placeholderHook;
public static Gson getGson() {
return GSON;
}
public static void log(String message) {
if (Config.CONFIG.getBoolean("debug")) {
LoParkour.getPlugin().getLogger().info("[Debug] " + message);
}
}
public static File getInFolder(String child) {
return new File(instance.getDataFolder(), child);
}
public static LoParkour getPlugin() {
return instance;
}
@Nullable
public static PAPIHook getPlaceholderHook() {
return placeholderHook;
}
public static SchematicManager getSchematicManager() {
return schematicManager;
}
public static GhostService getGhostService() {
return ghostService;
}
public void setSchematicManager(@NotNull SchematicManager manager) {
schematicManager = manager;
}
public void setGhostService(@NotNull GhostService service) {
ghostService = service;
}
public void setPlaceholderHook(@Nullable PAPIHook hook) {
placeholderHook = hook;
}
@Override
public void onEnable() {
instance = this;
PluginBootstrap.enable(this);
}
@Override
public void onDisable() {
PluginBootstrap.disable(this);
}
/** Called from {@link PluginBootstrap} on shutdown. */
public void runShutdownSequence() {
try {
new ArrayList<>(Divider.SECTIONS.keySet()).forEach(session -> {
try {
session.onAllPlayersLeft();
} catch (Exception e) {
getLogger().warning("Error cleaning up session: " + e.getMessage());
}
});
new ArrayList<>(Divider.SECTIONS.keySet()).forEach(Divider::remove);
for (final ParkourUser user : ParkourUser.getUsers()) {
ParkourUser.leave(user);
}
if (Modes.defaultMode() != null && Modes.defaultMode().getLeaderboard() != null) {
Modes.defaultMode().getLeaderboard().write(false);
}
Rewards.clear();
dev.loki.loparkour.adaptive.bootstrap.AdaptiveServices.shutdown();
if (ghostService != null) {
ghostService.shutdown();
}
Storage.close();
World.delete();
} catch (Throwable t) {
getLogger().log(Level.SEVERE, "Error during plugin shutdown: " + t.getMessage(), t);
}
}
}