From 9da4cda01ea673e9ee4ea30927018e57ab131457 Mon Sep 17 00:00:00 2001 From: Triassic Date: Thu, 17 Oct 2024 21:58:47 +0300 Subject: [PATCH] Minor cleaning, remove redundant comments --- .../geyserdebuginfo/GeyserDebugInfo.java | 18 ++++---- .../command/commands/ReloadCommand.java | 1 - .../configuration/ConfigurationContainer.java | 42 ++++--------------- .../manager/BossBarManager.java | 35 ---------------- .../manager/PlaceholderManager.java | 10 +++++ .../manager/PlayerDataManager.java | 30 ------------- .../placeholder/ModifierProvider.java | 5 --- .../placeholder/PlaceholderProvider.java | 5 --- 8 files changed, 27 insertions(+), 119 deletions(-) diff --git a/src/main/java/com/triassic/geyserdebuginfo/GeyserDebugInfo.java b/src/main/java/com/triassic/geyserdebuginfo/GeyserDebugInfo.java index 3da3251..ced18e1 100644 --- a/src/main/java/com/triassic/geyserdebuginfo/GeyserDebugInfo.java +++ b/src/main/java/com/triassic/geyserdebuginfo/GeyserDebugInfo.java @@ -58,7 +58,14 @@ public void onPreInitialize(GeyserPreInitializeEvent event) { return; } - this.configContainer = new ConfigurationContainer(dataFolder, logger, Configuration.class); + this.configContainer = new ConfigurationContainer(dataFolder, logger); + + if (!configContainer.load(Configuration.class)) { + logger.error("Failed to load the configuration. Please check config.yml for issues."); + extensionManager().disable(this); + return; + } + this.config = configContainer.get(); if (config == null) { @@ -85,9 +92,6 @@ public void onPreInitialize(GeyserPreInitializeEvent event) { logger.info("Enabled in " + (System.currentTimeMillis() - startTime) + "ms"); } - /** - * Defines and registers commands for the extension. - */ @Subscribe public void onDefineCommands(GeyserDefineCommandsEvent event) { Stream.of( @@ -96,10 +100,6 @@ public void onDefineCommands(GeyserDefineCommandsEvent event) { ).forEach(command -> event.register(command.createCommand())); } - /** - * Called during the shutdown process. - * Cleans up resources and saves player data. - */ @Subscribe public void onShutdown(GeyserShutdownEvent event) { bossBarManager.shutdown(); @@ -107,7 +107,7 @@ public void onShutdown(GeyserShutdownEvent event) { } public boolean reloadConfig() { - boolean reloaded = configContainer.reload(); + boolean reloaded = configContainer.load(configContainer.get().getClass()); if (reloaded) this.config = configContainer.get(); diff --git a/src/main/java/com/triassic/geyserdebuginfo/command/commands/ReloadCommand.java b/src/main/java/com/triassic/geyserdebuginfo/command/commands/ReloadCommand.java index 34c0284..3888051 100644 --- a/src/main/java/com/triassic/geyserdebuginfo/command/commands/ReloadCommand.java +++ b/src/main/java/com/triassic/geyserdebuginfo/command/commands/ReloadCommand.java @@ -31,7 +31,6 @@ public org.geysermc.geyser.api.command.Command createCommand() { private void execute(@NonNull CommandSource commandSource, org.geysermc.geyser.api.command.Command command, @NonNull String[] strings) { if (instance.reloadConfig()) { commandSource.sendMessage("§aGeyserDebugInfo configuration has been reloaded."); - System.out.println(instance.getConfig().getConfigVersion()); } else { commandSource.sendMessage("§cFailed to reload GeyserDebugInfo configuration, check console for details."); } diff --git a/src/main/java/com/triassic/geyserdebuginfo/configuration/ConfigurationContainer.java b/src/main/java/com/triassic/geyserdebuginfo/configuration/ConfigurationContainer.java index 7da81ba..d1f19d5 100644 --- a/src/main/java/com/triassic/geyserdebuginfo/configuration/ConfigurationContainer.java +++ b/src/main/java/com/triassic/geyserdebuginfo/configuration/ConfigurationContainer.java @@ -23,15 +23,13 @@ public class ConfigurationContainer { private final Path configFile; private final ExtensionLogger logger; private final YamlConfigurationLoader loader; - private final Class configClass; private final AtomicReference config = new AtomicReference<>(); public ConfigurationContainer( final Path dataFolder, - final ExtensionLogger logger, - final Class configClass) { + final ExtensionLogger logger + ) { this.logger = logger; - this.configClass = configClass; this.configFile = dataFolder.resolve("config.yml"); this.loader = YamlConfigurationLoader.builder() @@ -42,19 +40,11 @@ public ConfigurationContainer( .shouldCopyDefaults(true) .header(HEADER)) .build(); - - this.load(); } - /** - * Loads the configuration from the file. - * If loading fails, the previous configuration is retained. - * - * @return true if the configuration was loaded successfully, false otherwise. - */ - private boolean load() { + public boolean load(Class clazz) { try { - final Configuration loadedConfig = loadConfig(); + final Configuration loadedConfig = load0(clazz); config.set(loadedConfig); return true; } catch (Throwable e) { @@ -63,34 +53,18 @@ private boolean load() { } } - /** - * Loads the configuration from the file and creates a new Configuration object. - * - * @return the loaded Configuration object. - * @throws IOException if an error occurs while reading or parsing the file. - */ - private Configuration loadConfig() throws IOException { - CommentedConfigurationNode node = loader.load(); - Configuration loadedConfig = node.get(configClass); + private Configuration load0(Class clazz) throws IOException { + final CommentedConfigurationNode node = loader.load(); + final Configuration loadedConfig = node.get(clazz); if (Files.notExists(configFile)) { - node.set(configClass, loadedConfig); + node.set(clazz, loadedConfig); loader.save(node); } return loadedConfig; } - /** - * Reloads the configuration from the file. - * If reloading fails, the previous configuration is retained. - * - * @return true if the configuration was reloaded successfully, false otherwise. - */ - public boolean reload() { - return load(); - } - @Nullable public Configuration get() { return config.get(); diff --git a/src/main/java/com/triassic/geyserdebuginfo/manager/BossBarManager.java b/src/main/java/com/triassic/geyserdebuginfo/manager/BossBarManager.java index 0ec566f..bc18ce2 100644 --- a/src/main/java/com/triassic/geyserdebuginfo/manager/BossBarManager.java +++ b/src/main/java/com/triassic/geyserdebuginfo/manager/BossBarManager.java @@ -15,9 +15,6 @@ import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; -/** - * This class is responsible for creating, updating, and removing boss bars for each player. - */ public class BossBarManager { private final GeyserDebugInfo instance; @@ -38,12 +35,6 @@ public BossBarManager( executor.scheduleAtFixedRate(this::updateAllBossBars, 0, instance.getConfig().getDisplay().getBossBar().getRefreshInterval(), TimeUnit.MILLISECONDS); } - /** - * Creates a boss bar for the specified player if it doesn't already exist. - * - * @param player The player for whom to create the boss bar. - * @throws IllegalArgumentException if the player is null. - */ public void createBossBar(final @NotNull SessionPlayerEntity player) { final GeyserSession session = player.getSession(); @@ -57,24 +48,10 @@ public void createBossBar(final @NotNull SessionPlayerEntity player) { bossBars.put(player, bossBar); } - /** - * Removes the boss bar for the specified player and updates the player data - * to indicate that the F3 feature is disabled by default. - * - * @param player The player whose boss bar is to be removed. - * @throws IllegalArgumentException if the player is null. - */ public void removeBossBar(final @NotNull SessionPlayerEntity player) { removeBossBar(player, true); } - /** - * Removes the boss bar for the specified player. - * - * @param player The player whose boss bar is to be removed. - * @param updatePlayerData Whether to update the player data to indicate that the F3 feature is disabled. - * @throws IllegalArgumentException if the player is null. - */ public void removeBossBar(final @NotNull SessionPlayerEntity player, boolean updatePlayerData) { BossBar bossBar = bossBars.remove(player); if (bossBar != null) @@ -84,21 +61,12 @@ public void removeBossBar(final @NotNull SessionPlayerEntity player, boolean upd playerDataManager.setF3Enabled(player.getUuid(), false); } - /** - * Requests a bossbar update for all tracked bossbars. - */ private void updateAllBossBars() { for (Map.Entry entry : bossBars.entrySet()) { updateBossBar(entry.getKey()); } } - /** - * Updates the boss bar with current up-to-date data. - * - * @param player The player whose boss bar is to be updated. - * @throws IllegalArgumentException if the player is null. - */ private void updateBossBar(final @NotNull SessionPlayerEntity player) { BossBar bossBar = bossBars.get(player); @@ -113,9 +81,6 @@ private void updateBossBar(final @NotNull SessionPlayerEntity player) { } } - /** - * Shuts down the executor service, stopping all updates. - */ public void shutdown() { executor.shutdown(); } diff --git a/src/main/java/com/triassic/geyserdebuginfo/manager/PlaceholderManager.java b/src/main/java/com/triassic/geyserdebuginfo/manager/PlaceholderManager.java index a75c4d2..e3eba11 100644 --- a/src/main/java/com/triassic/geyserdebuginfo/manager/PlaceholderManager.java +++ b/src/main/java/com/triassic/geyserdebuginfo/manager/PlaceholderManager.java @@ -22,6 +22,16 @@ public void registerProvider(ModifierProvider provider) { } } + public void unregisterProvider(PlaceholderProvider provider) { + providers.remove(provider.getIdentifier()); + } + + public void unregisterProvider(ModifierProvider provider) { + for (String modifier : provider.getModifiers()) { + modifiers.remove(modifier); + } + } + /** * Resolves placeholders in the given text based on the provided Geyser session. * Placeholders should be formatted as %provider_placeholder% (e.g., %chunk_x% or %position_x%). diff --git a/src/main/java/com/triassic/geyserdebuginfo/manager/PlayerDataManager.java b/src/main/java/com/triassic/geyserdebuginfo/manager/PlayerDataManager.java index 74b9529..6074a46 100644 --- a/src/main/java/com/triassic/geyserdebuginfo/manager/PlayerDataManager.java +++ b/src/main/java/com/triassic/geyserdebuginfo/manager/PlayerDataManager.java @@ -19,13 +19,6 @@ public class PlayerDataManager { private final Map playerF3States; private final boolean defaultEnabled; - /** - * Constructs a new PlayerDataManager and loads player data from the YAML file. - * - * @param dataFolder The data folder to use for storing the player data file. - * @param logger The logger used for logging errors and information during operations. - * @param defaultEnabled If true, track players with F3 disabled; otherwise, track players with F3 enabled. - */ public PlayerDataManager( final File dataFolder, final ExtensionLogger logger, @@ -40,11 +33,6 @@ public PlayerDataManager( loadPlayerData(); } - /** - * Creates DumperOptions for the YAML configuration. - * - * @return DumperOptions configured for the YAML. - */ private DumperOptions createDumperOptions() { DumperOptions options = new DumperOptions(); options.setIndent(2); @@ -52,9 +40,6 @@ private DumperOptions createDumperOptions() { return options; } - /** - * Loads player data from the YAML file. - */ private void loadPlayerData() { if (!playerDataFile.exists()) return; @@ -70,9 +55,6 @@ private void loadPlayerData() { } } - /** - * Saves the current player F3 states to the YAML file. - */ public void savePlayerData() { try (FileWriter writer = new FileWriter(playerDataFile)) { Map data = new HashMap<>(); @@ -88,12 +70,6 @@ public void savePlayerData() { } } - /** - * Sets the F3 enabled state for a player. - * - * @param playerUuid The UUID of the player. - * @param enabled The F3 enabled state to set. - */ public void setF3Enabled(UUID playerUuid, boolean enabled) { if ((defaultEnabled && enabled) || (!defaultEnabled && !enabled)) { playerF3States.remove(playerUuid); @@ -103,12 +79,6 @@ public void setF3Enabled(UUID playerUuid, boolean enabled) { savePlayerData(); } - /** - * Checks if F3 is enabled for the specified player. - * - * @param playerUuid The UUID of the player. - * @return true if F3 is enabled, false otherwise. - */ public boolean isF3Enabled(UUID playerUuid) { return playerF3States.getOrDefault(playerUuid, defaultEnabled); } diff --git a/src/main/java/com/triassic/geyserdebuginfo/placeholder/ModifierProvider.java b/src/main/java/com/triassic/geyserdebuginfo/placeholder/ModifierProvider.java index 091a7b2..5c96bed 100644 --- a/src/main/java/com/triassic/geyserdebuginfo/placeholder/ModifierProvider.java +++ b/src/main/java/com/triassic/geyserdebuginfo/placeholder/ModifierProvider.java @@ -6,11 +6,6 @@ import java.util.Collections; import java.util.List; -/** - * Abstract class for defining modifier providers. - * Subclasses can provide specific modifier values - * to be used within text by the Geyser session. - */ public abstract class ModifierProvider { /** diff --git a/src/main/java/com/triassic/geyserdebuginfo/placeholder/PlaceholderProvider.java b/src/main/java/com/triassic/geyserdebuginfo/placeholder/PlaceholderProvider.java index 60a016f..2524281 100644 --- a/src/main/java/com/triassic/geyserdebuginfo/placeholder/PlaceholderProvider.java +++ b/src/main/java/com/triassic/geyserdebuginfo/placeholder/PlaceholderProvider.java @@ -4,11 +4,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -/** - * Abstract class for defining placeholder providers. - * Subclasses can provide specific placeholder values - * to be used within text by the Geyser session. - */ public abstract class PlaceholderProvider { /**