From 122b4b064cbce652eca7e45cf099fe7ce2fa2541 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beatrice=20Dellac=C3=A0?= Date: Sat, 11 Feb 2023 20:57:29 +0100 Subject: [PATCH] Rename config entries class --- .../java/wtf/beatrice/hubthat/HubThat.java | 24 ++++++++--------- .../beatrice/hubthat/commands/HubCommand.java | 2 +- .../hubthat/commands/SpawnCommand.java | 2 +- .../hubthat/listeners/PlayerChatListener.java | 4 +-- .../hubthat/listeners/PlayerJoinListener.java | 12 ++++----- .../hubthat/listeners/PlayerMoveListener.java | 4 +-- .../listeners/PlayerRespawnListener.java | 8 +++--- .../{ConfigEntries.java => ConfigEntry.java} | 4 +-- .../hubthat/utils/files/FileUtils.java | 8 +++--- .../utils/files/OldConfigConversion.java | 26 +++++++++---------- 10 files changed, 47 insertions(+), 47 deletions(-) rename src/main/java/wtf/beatrice/hubthat/utils/{ConfigEntries.java => ConfigEntry.java} (94%) diff --git a/src/main/java/wtf/beatrice/hubthat/HubThat.java b/src/main/java/wtf/beatrice/hubthat/HubThat.java index 9a1f7eb..86d6fb5 100644 --- a/src/main/java/wtf/beatrice/hubthat/HubThat.java +++ b/src/main/java/wtf/beatrice/hubthat/HubThat.java @@ -7,7 +7,7 @@ import wtf.beatrice.hubthat.listeners.PlayerChatListener; import wtf.beatrice.hubthat.listeners.PlayerJoinListener; import wtf.beatrice.hubthat.listeners.PlayerMoveListener; import wtf.beatrice.hubthat.listeners.PlayerRespawnListener; -import wtf.beatrice.hubthat.utils.ConfigEntries; +import wtf.beatrice.hubthat.utils.ConfigEntry; import wtf.beatrice.hubthat.utils.Debugger; import wtf.beatrice.hubthat.utils.TeleportUtils; import wtf.beatrice.hubthat.utils.files.FileUtils; @@ -141,19 +141,19 @@ public class HubThat extends JavaPlugin Metrics metrics = new Metrics(this); YamlConfiguration config = FileUtils.FileType.CONFIG_YAML.yaml; - metrics.addCustomChart(new Metrics.SimplePie("respawn-handler", () -> config.getString(ConfigEntries.TELEPORTATION_RESPAWN_HANDLER.path))); - metrics.addCustomChart(new Metrics.SimplePie("world-related-chat", () -> config.getString(ConfigEntries.WORLD_RELATED_CHAT.path))); - metrics.addCustomChart(new Metrics.SimplePie("update-notify", () -> config.getString(ConfigEntries.UPDATE_CHECKER_ENABLED.path))); - metrics.addCustomChart(new Metrics.SimplePie("set-gamemode-on-join", () -> config.getString(ConfigEntries.GAMEMODE_SET_ON_JOIN.path))); - metrics.addCustomChart(new Metrics.SimplePie("tp-hub-on-join", () -> config.getString(ConfigEntries.TELEPORTATION_TP_HUB_ON_JOIN.path))); - metrics.addCustomChart(new Metrics.SimplePie("tp-hub-on-respawn", () -> config.getString(ConfigEntries.TELEPORTATION_TP_HUB_ON_RESPAWN.path))); - metrics.addCustomChart(new Metrics.SimplePie("multiverse-bypass", () -> config.getString(ConfigEntries.MULTIVERSE_BYPASS.path))); - metrics.addCustomChart(new Metrics.SimplePie("send-tp-message-on-join", () -> config.getString(ConfigEntries.TELEPORTATION_TP_MESSAGE_ON_JOIN.path))); - metrics.addCustomChart(new Metrics.SimplePie("fix-invisible-after-tp", () -> config.getString(ConfigEntries.INVISIBILITY_FIX.path))); + metrics.addCustomChart(new Metrics.SimplePie("respawn-handler", () -> config.getString(ConfigEntry.TELEPORTATION_RESPAWN_HANDLER.path))); + metrics.addCustomChart(new Metrics.SimplePie("world-related-chat", () -> config.getString(ConfigEntry.WORLD_RELATED_CHAT.path))); + metrics.addCustomChart(new Metrics.SimplePie("update-notify", () -> config.getString(ConfigEntry.UPDATE_CHECKER_ENABLED.path))); + metrics.addCustomChart(new Metrics.SimplePie("set-gamemode-on-join", () -> config.getString(ConfigEntry.GAMEMODE_SET_ON_JOIN.path))); + metrics.addCustomChart(new Metrics.SimplePie("tp-hub-on-join", () -> config.getString(ConfigEntry.TELEPORTATION_TP_HUB_ON_JOIN.path))); + metrics.addCustomChart(new Metrics.SimplePie("tp-hub-on-respawn", () -> config.getString(ConfigEntry.TELEPORTATION_TP_HUB_ON_RESPAWN.path))); + metrics.addCustomChart(new Metrics.SimplePie("multiverse-bypass", () -> config.getString(ConfigEntry.MULTIVERSE_BYPASS.path))); + metrics.addCustomChart(new Metrics.SimplePie("send-tp-message-on-join", () -> config.getString(ConfigEntry.TELEPORTATION_TP_MESSAGE_ON_JOIN.path))); + metrics.addCustomChart(new Metrics.SimplePie("fix-invisible-after-tp", () -> config.getString(ConfigEntry.INVISIBILITY_FIX.path))); - if (config.getBoolean(ConfigEntries.GAMEMODE_SET_ON_JOIN.path)) + if (config.getBoolean(ConfigEntry.GAMEMODE_SET_ON_JOIN.path)) { - metrics.addCustomChart(new Metrics.SimplePie("join-gamemode", () -> config.getString(ConfigEntries.GAMEMODE.path))); + metrics.addCustomChart(new Metrics.SimplePie("join-gamemode", () -> config.getString(ConfigEntry.GAMEMODE.path))); } } diff --git a/src/main/java/wtf/beatrice/hubthat/commands/HubCommand.java b/src/main/java/wtf/beatrice/hubthat/commands/HubCommand.java index 0b7e748..ea1cf42 100644 --- a/src/main/java/wtf/beatrice/hubthat/commands/HubCommand.java +++ b/src/main/java/wtf/beatrice/hubthat/commands/HubCommand.java @@ -90,7 +90,7 @@ public class HubCommand implements CommandExecutor // Put the player in the ArrayList of players waiting to be teleported. PluginCache.teleporting.add(username); // Load the teleportation delay. - int delay = FileUtils.FileType.CONFIG_YAML.yaml.getInt(ConfigEntries.HUB_DELAY.path); + int delay = FileUtils.FileType.CONFIG_YAML.yaml.getInt(ConfigEntry.HUB_DELAY.path); // Warn the player about the delay. diff --git a/src/main/java/wtf/beatrice/hubthat/commands/SpawnCommand.java b/src/main/java/wtf/beatrice/hubthat/commands/SpawnCommand.java index c57f300..f0f12a6 100644 --- a/src/main/java/wtf/beatrice/hubthat/commands/SpawnCommand.java +++ b/src/main/java/wtf/beatrice/hubthat/commands/SpawnCommand.java @@ -118,7 +118,7 @@ public class SpawnCommand implements CommandExecutor // Load the teleportation delay. - int delay = FileUtils.FileType.CONFIG_YAML.yaml.getInt(ConfigEntries.SPAWN_DELAY.path); + int delay = FileUtils.FileType.CONFIG_YAML.yaml.getInt(ConfigEntry.SPAWN_DELAY.path); // Warn the player about the delay. String delayMessage = MessageUtils.getLocalizedMessage(LocalizedMessage.INFO_TELEPORT_DELAY, false); diff --git a/src/main/java/wtf/beatrice/hubthat/listeners/PlayerChatListener.java b/src/main/java/wtf/beatrice/hubthat/listeners/PlayerChatListener.java index 8ca2365..ae1bddc 100644 --- a/src/main/java/wtf/beatrice/hubthat/listeners/PlayerChatListener.java +++ b/src/main/java/wtf/beatrice/hubthat/listeners/PlayerChatListener.java @@ -1,7 +1,7 @@ package wtf.beatrice.hubthat.listeners; import wtf.beatrice.hubthat.HubThat; -import wtf.beatrice.hubthat.utils.ConfigEntries; +import wtf.beatrice.hubthat.utils.ConfigEntry; import wtf.beatrice.hubthat.utils.Debugger; import wtf.beatrice.hubthat.utils.files.FileUtils; import org.bukkit.entity.Player; @@ -27,7 +27,7 @@ public class PlayerChatListener implements Listener Player messageSender = event.getPlayer(); // Check if the world-related chat is enabled. - if(FileUtils.FileType.CONFIG_YAML.yaml.getBoolean(ConfigEntries.WORLD_RELATED_CHAT.path)) + if(FileUtils.FileType.CONFIG_YAML.yaml.getBoolean(ConfigEntry.WORLD_RELATED_CHAT.path)) { // Store the sender's world spawn name in a string. Fallback to "__UNSET__". diff --git a/src/main/java/wtf/beatrice/hubthat/listeners/PlayerJoinListener.java b/src/main/java/wtf/beatrice/hubthat/listeners/PlayerJoinListener.java index f3a11a7..8485a23 100644 --- a/src/main/java/wtf/beatrice/hubthat/listeners/PlayerJoinListener.java +++ b/src/main/java/wtf/beatrice/hubthat/listeners/PlayerJoinListener.java @@ -2,7 +2,7 @@ package wtf.beatrice.hubthat.listeners; import wtf.beatrice.hubthat.HubThat; import wtf.beatrice.hubthat.commands.HubCommand; -import wtf.beatrice.hubthat.utils.ConfigEntries; +import wtf.beatrice.hubthat.utils.ConfigEntry; import wtf.beatrice.hubthat.utils.Debugger; import wtf.beatrice.hubthat.utils.MessageUtils; import wtf.beatrice.hubthat.utils.PluginCache; @@ -49,10 +49,10 @@ public class PlayerJoinListener implements Listener plugin.updateChecker.playerMessage(player); // Check if gamemode has to be set on join. - if(configYaml.getBoolean(ConfigEntries.GAMEMODE_SET_ON_JOIN.path)) + if(configYaml.getBoolean(ConfigEntry.GAMEMODE_SET_ON_JOIN.path)) { // Load the gamemode int from config. - int gamemodeInt = configYaml.getInt(ConfigEntries.GAMEMODE.path); + int gamemodeInt = configYaml.getInt(ConfigEntry.GAMEMODE.path); GameMode gamemode; // Set the gamemode accordingly. @@ -72,7 +72,7 @@ public class PlayerJoinListener implements Listener break; } - if(configYaml.getBoolean(ConfigEntries.MULTIVERSE_BYPASS.path)) + if(configYaml.getBoolean(ConfigEntry.MULTIVERSE_BYPASS.path)) { plugin.getServer().getScheduler().runTaskLater(plugin, ()-> player.setGameMode(gamemode), 10L); } @@ -83,10 +83,10 @@ public class PlayerJoinListener implements Listener } // Check if we have to teleport the player to the Hub on join. - if(configYaml.getBoolean(ConfigEntries.TELEPORTATION_TP_HUB_ON_JOIN.path)) + if(configYaml.getBoolean(ConfigEntry.TELEPORTATION_TP_HUB_ON_JOIN.path)) { - if(configYaml.getBoolean(ConfigEntries.MULTIVERSE_BYPASS.path)) + if(configYaml.getBoolean(ConfigEntry.MULTIVERSE_BYPASS.path)) { plugin.getServer().getScheduler().runTaskLater(plugin, ()-> HubCommand.teleportToHub(player, player, PluginCache.sendJoinTpMessage), 10L); } diff --git a/src/main/java/wtf/beatrice/hubthat/listeners/PlayerMoveListener.java b/src/main/java/wtf/beatrice/hubthat/listeners/PlayerMoveListener.java index 7b4b7f0..4f4a594 100644 --- a/src/main/java/wtf/beatrice/hubthat/listeners/PlayerMoveListener.java +++ b/src/main/java/wtf/beatrice/hubthat/listeners/PlayerMoveListener.java @@ -1,7 +1,7 @@ package wtf.beatrice.hubthat.listeners; import wtf.beatrice.hubthat.utils.PluginCache; -import wtf.beatrice.hubthat.utils.ConfigEntries; +import wtf.beatrice.hubthat.utils.ConfigEntry; import wtf.beatrice.hubthat.utils.LocalizedMessage; import wtf.beatrice.hubthat.utils.MessageUtils; import wtf.beatrice.hubthat.utils.files.FileUtils; @@ -17,7 +17,7 @@ public class PlayerMoveListener implements Listener { // Check if the movement detection is enabled. - if(FileUtils.FileType.CONFIG_YAML.yaml.getBoolean(ConfigEntries.MOVEMENT_DETECTION_ENABLED.path)) + if(FileUtils.FileType.CONFIG_YAML.yaml.getBoolean(ConfigEntry.MOVEMENT_DETECTION_ENABLED.path)) { // We are only going to allocate the playerName string and not the whole Player because we want efficiency. String playerName = event.getPlayer().getName(); diff --git a/src/main/java/wtf/beatrice/hubthat/listeners/PlayerRespawnListener.java b/src/main/java/wtf/beatrice/hubthat/listeners/PlayerRespawnListener.java index 2bf031e..eefba14 100644 --- a/src/main/java/wtf/beatrice/hubthat/listeners/PlayerRespawnListener.java +++ b/src/main/java/wtf/beatrice/hubthat/listeners/PlayerRespawnListener.java @@ -3,7 +3,7 @@ package wtf.beatrice.hubthat.listeners; import wtf.beatrice.hubthat.HubThat; import wtf.beatrice.hubthat.commands.HubCommand; import wtf.beatrice.hubthat.commands.SpawnCommand; -import wtf.beatrice.hubthat.utils.ConfigEntries; +import wtf.beatrice.hubthat.utils.ConfigEntry; import wtf.beatrice.hubthat.utils.files.FileUtils; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; @@ -31,7 +31,7 @@ public class PlayerRespawnListener implements Listener - if(configYaml.getBoolean(ConfigEntries.MULTIVERSE_BYPASS.path)) + if(configYaml.getBoolean(ConfigEntry.MULTIVERSE_BYPASS.path)) { plugin.getServer().getScheduler().runTaskLater(plugin, ()-> tpPlayer(event.getPlayer(), configYaml), 5L); @@ -48,11 +48,11 @@ public class PlayerRespawnListener implements Listener private void tpPlayer(Player player, YamlConfiguration configYaml) { // Check if the respawn handler is enabled in config. - if(configYaml.getBoolean(ConfigEntries.TELEPORTATION_RESPAWN_HANDLER.path)) + if(configYaml.getBoolean(ConfigEntry.TELEPORTATION_RESPAWN_HANDLER.path)) { // Check if the player has to be teleported to Hub on respawn. - if(configYaml.getBoolean(ConfigEntries.TELEPORTATION_TP_HUB_ON_RESPAWN.path)) + if(configYaml.getBoolean(ConfigEntry.TELEPORTATION_TP_HUB_ON_RESPAWN.path)) { HubCommand.teleportToHub(player, player); } diff --git a/src/main/java/wtf/beatrice/hubthat/utils/ConfigEntries.java b/src/main/java/wtf/beatrice/hubthat/utils/ConfigEntry.java similarity index 94% rename from src/main/java/wtf/beatrice/hubthat/utils/ConfigEntries.java rename to src/main/java/wtf/beatrice/hubthat/utils/ConfigEntry.java index ea52160..3369438 100644 --- a/src/main/java/wtf/beatrice/hubthat/utils/ConfigEntries.java +++ b/src/main/java/wtf/beatrice/hubthat/utils/ConfigEntry.java @@ -1,6 +1,6 @@ package wtf.beatrice.hubthat.utils; -public enum ConfigEntries +public enum ConfigEntry { HUB_DELAY("hub.delay"), @@ -33,7 +33,7 @@ public enum ConfigEntries public String path; - ConfigEntries(String path) + ConfigEntry(String path) { this.path = path; } diff --git a/src/main/java/wtf/beatrice/hubthat/utils/files/FileUtils.java b/src/main/java/wtf/beatrice/hubthat/utils/files/FileUtils.java index 203b32b..e63d98e 100644 --- a/src/main/java/wtf/beatrice/hubthat/utils/files/FileUtils.java +++ b/src/main/java/wtf/beatrice/hubthat/utils/files/FileUtils.java @@ -2,7 +2,7 @@ package wtf.beatrice.hubthat.utils.files; import wtf.beatrice.hubthat.HubThat; import wtf.beatrice.hubthat.utils.PluginCache; -import wtf.beatrice.hubthat.utils.ConfigEntries; +import wtf.beatrice.hubthat.utils.ConfigEntry; import wtf.beatrice.hubthat.utils.Debugger; import wtf.beatrice.hubthat.utils.metrics.UpdateChecker; import org.bukkit.configuration.file.YamlConfiguration; @@ -59,7 +59,7 @@ public class FileUtils YamlConfiguration config = FileType.CONFIG_YAML.yaml; - if(config.getBoolean(ConfigEntries.UPDATE_CHECKER_ENABLED.path)) + if(config.getBoolean(ConfigEntry.UPDATE_CHECKER_ENABLED.path)) { PluginCache.updateChecker = true; if(UpdateChecker.task != null) @@ -74,8 +74,8 @@ public class FileUtils PluginCache.updateChecker = false; } - PluginCache.invisibilityFix = config.getBoolean(ConfigEntries.INVISIBILITY_FIX.path); - PluginCache.sendJoinTpMessage = config.getBoolean(ConfigEntries.TELEPORTATION_TP_MESSAGE_ON_JOIN.path); + PluginCache.invisibilityFix = config.getBoolean(ConfigEntry.INVISIBILITY_FIX.path); + PluginCache.sendJoinTpMessage = config.getBoolean(ConfigEntry.TELEPORTATION_TP_MESSAGE_ON_JOIN.path); } // Only reload the needed File. diff --git a/src/main/java/wtf/beatrice/hubthat/utils/files/OldConfigConversion.java b/src/main/java/wtf/beatrice/hubthat/utils/files/OldConfigConversion.java index caf0d79..57da485 100644 --- a/src/main/java/wtf/beatrice/hubthat/utils/files/OldConfigConversion.java +++ b/src/main/java/wtf/beatrice/hubthat/utils/files/OldConfigConversion.java @@ -1,7 +1,7 @@ package wtf.beatrice.hubthat.utils.files; import wtf.beatrice.hubthat.HubThat; -import wtf.beatrice.hubthat.utils.ConfigEntries; +import wtf.beatrice.hubthat.utils.ConfigEntry; import wtf.beatrice.hubthat.utils.LocalizedMessage; import org.bukkit.configuration.file.YamlConfiguration; @@ -37,21 +37,21 @@ public class OldConfigConversion FileUtils.checkFiles(); // newPath, oldPath - HashMapnewAndOldConfigEntries = new HashMap<>(); + HashMapnewAndOldConfigEntries = new HashMap<>(); logger.warning("Loading config entries..."); - newAndOldConfigEntries.put(ConfigEntries.HUB_DELAY, "hub.delay"); - newAndOldConfigEntries.put(ConfigEntries.SPAWN_DELAY, "spawn.delay"); - newAndOldConfigEntries.put(ConfigEntries.WORLD_RELATED_CHAT, "global.world-related-chat"); - newAndOldConfigEntries.put(ConfigEntries.UPDATE_CHECKER_ENABLED, "updates.update-notify"); - newAndOldConfigEntries.put(ConfigEntries.MOVEMENT_DETECTION_ENABLED, "global.move-detect"); - newAndOldConfigEntries.put(ConfigEntries.GAMEMODE_SET_ON_JOIN, "global.set-gamemode-on-join"); - newAndOldConfigEntries.put(ConfigEntries.GAMEMODE, "global.gamemode"); - newAndOldConfigEntries.put(ConfigEntries.TELEPORTATION_TP_HUB_ON_JOIN, "global.tp-hub-on-join"); - newAndOldConfigEntries.put(ConfigEntries.TELEPORTATION_TP_HUB_ON_RESPAWN, "global.tp-hub-on-respawn"); - newAndOldConfigEntries.put(ConfigEntries.TELEPORTATION_RESPAWN_HANDLER, "global.respawn-handler"); + newAndOldConfigEntries.put(ConfigEntry.HUB_DELAY, "hub.delay"); + newAndOldConfigEntries.put(ConfigEntry.SPAWN_DELAY, "spawn.delay"); + newAndOldConfigEntries.put(ConfigEntry.WORLD_RELATED_CHAT, "global.world-related-chat"); + newAndOldConfigEntries.put(ConfigEntry.UPDATE_CHECKER_ENABLED, "updates.update-notify"); + newAndOldConfigEntries.put(ConfigEntry.MOVEMENT_DETECTION_ENABLED, "global.move-detect"); + newAndOldConfigEntries.put(ConfigEntry.GAMEMODE_SET_ON_JOIN, "global.set-gamemode-on-join"); + newAndOldConfigEntries.put(ConfigEntry.GAMEMODE, "global.gamemode"); + newAndOldConfigEntries.put(ConfigEntry.TELEPORTATION_TP_HUB_ON_JOIN, "global.tp-hub-on-join"); + newAndOldConfigEntries.put(ConfigEntry.TELEPORTATION_TP_HUB_ON_RESPAWN, "global.tp-hub-on-respawn"); + newAndOldConfigEntries.put(ConfigEntry.TELEPORTATION_RESPAWN_HANDLER, "global.respawn-handler"); logger.warning("Converting config entries..."); - for(ConfigEntries entry : newAndOldConfigEntries.keySet()) + for(ConfigEntry entry : newAndOldConfigEntries.keySet()) { logger.warning("Entry: " + entry.path); FileUtils.FileType.CONFIG_YAML.yaml.set(entry.path, oldConfig.get(newAndOldConfigEntries.get(entry)));