Rename config entries class
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Bea 2023-02-11 20:57:29 +01:00
parent 7f792b5ca8
commit 122b4b064c
10 changed files with 47 additions and 47 deletions

View File

@ -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)));
}
}

View File

@ -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.

View File

@ -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);

View File

@ -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__".

View File

@ -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);
}

View File

@ -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();

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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.

View File

@ -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
HashMap<ConfigEntries, String>newAndOldConfigEntries = new HashMap<>();
HashMap<ConfigEntry, String>newAndOldConfigEntries = 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)));