From c784fc7f2e126769ea174088053ae5546d4b8dff Mon Sep 17 00:00:00 2001 From: ljacqu Date: Wed, 29 Nov 2017 19:43:35 +0100 Subject: [PATCH] #1423 Fix ignored review remarks --- .../xephi/authme/listener/ServerListener.java | 4 +-- .../fr/xephi/authme/settings/SpawnLoader.java | 28 +++++++++---------- .../authme/listener/ServerListenerTest.java | 4 +-- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/main/java/fr/xephi/authme/listener/ServerListener.java b/src/main/java/fr/xephi/authme/listener/ServerListener.java index 83898bdc..4aceaf6f 100644 --- a/src/main/java/fr/xephi/authme/listener/ServerListener.java +++ b/src/main/java/fr/xephi/authme/listener/ServerListener.java @@ -42,7 +42,7 @@ public class ServerListener implements Listener { ConsoleLogger.info("Essentials has been disabled: unhooking"); } else if ("CMI".equalsIgnoreCase(pluginName)) { pluginHookService.unhookCmi(); - spawnLoader.unloadCMISpawn(); + spawnLoader.unloadCmiSpawn(); ConsoleLogger.info("CMI has been disabled: unhooking"); } else if ("Multiverse-Core".equalsIgnoreCase(pluginName)) { pluginHookService.unhookMultiverse(); @@ -76,7 +76,7 @@ public class ServerListener implements Listener { spawnLoader.loadEssentialsSpawn(); } else if ("CMI".equalsIgnoreCase(pluginName)) { pluginHookService.tryHookToCmi(); - spawnLoader.loadCMISpawn(); + spawnLoader.loadCmiSpawn(); } else if ("ProtocolLib".equalsIgnoreCase(pluginName)) { protocolLibService.setup(); } diff --git a/src/main/java/fr/xephi/authme/settings/SpawnLoader.java b/src/main/java/fr/xephi/authme/settings/SpawnLoader.java index 93d1f57f..ea235b3c 100644 --- a/src/main/java/fr/xephi/authme/settings/SpawnLoader.java +++ b/src/main/java/fr/xephi/authme/settings/SpawnLoader.java @@ -134,7 +134,7 @@ public class SpawnLoader implements Reloadable { /** * Load the spawn point defined in CMI. */ - public void loadCMISpawn() { + public void loadCmiSpawn() { File cmiFolder = pluginHookService.getCmiDataFolder(); if (cmiFolder == null) { return; @@ -142,8 +142,7 @@ public class SpawnLoader implements Reloadable { File cmiConfig = new File(cmiFolder, "config.yml"); if (cmiConfig.exists()) { - cmiSpawn = getLocationFromConfigurationUpper( - YamlConfiguration.loadConfiguration(cmiConfig), "Spawn.Main"); + cmiSpawn = getLocationFromCmiConfiguration(YamlConfiguration.loadConfiguration(cmiConfig)); } else { cmiSpawn = null; ConsoleLogger.info("CMI config file not found: '" + cmiConfig.getAbsolutePath() + "'"); @@ -153,7 +152,7 @@ public class SpawnLoader implements Reloadable { /** * Unset the spawn point defined in CMI. */ - public void unloadCMISpawn() { + public void unloadCmiSpawn() { cmiSpawn = null; } @@ -273,15 +272,15 @@ public class SpawnLoader implements Reloadable { } /** - * Build a {@link Location} object from the given path in the file configuration. + * Build a {@link Location} object based on the CMI configuration. * - * @param configuration The file configuration to read from - * @param pathPrefix The path to get the spawn point from + * @param configuration The CMI file configuration to read from * * @return Location corresponding to the values in the path */ - private static Location getLocationFromConfigurationUpper(FileConfiguration configuration, String pathPrefix) { - if (containsAllSpawnFieldsUpper(configuration, pathPrefix)) { + private static Location getLocationFromCmiConfiguration(FileConfiguration configuration) { + final String pathPrefix = "Spawn.Main"; + if (isLocationCompleteInCmiConfig(configuration, pathPrefix)) { String prefix = pathPrefix + "."; String worldName = configuration.getString(prefix + "World"); World world = Bukkit.getWorld(worldName); @@ -314,18 +313,17 @@ public class SpawnLoader implements Reloadable { } /** - * Return whether the file configuration contains all fields necessary to define a spawn - * under the given path. + * Return whether the CMI file configuration contains all spawn fields under the given path. * - * @param configuration The file configuration to use - * @param pathPrefix The path to verify + * @param cmiConfiguration The file configuration from CMI + * @param pathPrefix The path to verify * * @return True if all spawn fields are present, false otherwise */ - private static boolean containsAllSpawnFieldsUpper(FileConfiguration configuration, String pathPrefix) { + private static boolean isLocationCompleteInCmiConfig(FileConfiguration cmiConfiguration, String pathPrefix) { String[] fields = {"World", "X", "Y", "Z", "Yaw", "Pitch"}; for (String field : fields) { - if (!configuration.contains(pathPrefix + "." + field)) { + if (!cmiConfiguration.contains(pathPrefix + "." + field)) { return false; } } diff --git a/src/test/java/fr/xephi/authme/listener/ServerListenerTest.java b/src/test/java/fr/xephi/authme/listener/ServerListenerTest.java index 8cfdf03e..b015c2eb 100644 --- a/src/test/java/fr/xephi/authme/listener/ServerListenerTest.java +++ b/src/test/java/fr/xephi/authme/listener/ServerListenerTest.java @@ -61,7 +61,7 @@ public class ServerListenerTest { checkEnableHandling(ESSENTIALS_SPAWN, () -> verify(spawnLoader).loadEssentialsSpawn()); checkEnableHandling(CMI, () -> { verify(pluginHookService).tryHookToCmi(); - verify(spawnLoader).loadCMISpawn(); + verify(spawnLoader).loadCmiSpawn(); }); checkEnableHandling(MULTIVERSE, () -> verify(pluginHookService).tryHookToMultiverse()); checkEnableHandling(PROTOCOL_LIB, () -> verify(protocolLibService).setup()); @@ -74,7 +74,7 @@ public class ServerListenerTest { checkDisableHandling(ESSENTIALS_SPAWN, () -> verify(spawnLoader).unloadEssentialsSpawn()); checkDisableHandling(CMI, () -> { verify(pluginHookService).unhookCmi(); - verify(spawnLoader).unloadCMISpawn(); + verify(spawnLoader).unloadCmiSpawn(); }); checkDisableHandling(MULTIVERSE, () -> verify(pluginHookService).unhookMultiverse()); checkDisableHandling(PROTOCOL_LIB, () -> verify(protocolLibService).disable());