From 3b137b1dad6df641b08f41eaccea891ecacba8e8 Mon Sep 17 00:00:00 2001 From: Mykyta Date: Wed, 6 May 2020 07:00:52 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8C=20Refactor=20the=20config=20Includ?= =?UTF-8?q?e=20a=20getConfig()=20method=20to=20simplify=20things=20a=20tad?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/xyz/nkomarn/Harbor/task/Checker.java | 4 +-- .../java/xyz/nkomarn/Harbor/util/Config.java | 34 +++++++++---------- .../xyz/nkomarn/Harbor/util/Messages.java | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/main/java/xyz/nkomarn/Harbor/task/Checker.java b/src/main/java/xyz/nkomarn/Harbor/task/Checker.java index df73158..b3d16d9 100644 --- a/src/main/java/xyz/nkomarn/Harbor/task/Checker.java +++ b/src/main/java/xyz/nkomarn/Harbor/task/Checker.java @@ -62,9 +62,9 @@ public class Checker implements Runnable { private boolean isBlacklisted(final World world) { if (Config.getBoolean("whitelist-mode")) { - return !Config.getList("blacklisted-worlds").contains(world.getName()); + return !Config.getConfig().getStringList("blacklisted-worlds").contains(world.getName()); } - return Config.getList("blacklisted-worlds").contains(world.getName()); + return Config.getConfig().getStringList("blacklisted-worlds").contains(world.getName()); } private boolean isNight(final World world) { diff --git a/src/main/java/xyz/nkomarn/Harbor/util/Config.java b/src/main/java/xyz/nkomarn/Harbor/util/Config.java index 2757698..8c39e3e 100644 --- a/src/main/java/xyz/nkomarn/Harbor/util/Config.java +++ b/src/main/java/xyz/nkomarn/Harbor/util/Config.java @@ -1,18 +1,27 @@ package xyz.nkomarn.Harbor.util; +import org.bukkit.configuration.file.FileConfiguration; import xyz.nkomarn.Harbor.Harbor; import java.util.ArrayList; import java.util.List; public class Config { + /** + * Fetches an instance of the FileConfiguration. + * @return The configuration for this server. + */ + public static FileConfiguration getConfig() { + return Harbor.getHarbor().getConfig(); + } + /** * Fetches a boolean from the configuration * if location is not found, false is returned * @param location Configuration location of the boolean */ - public static boolean getBoolean(final String location) { - return Harbor.getHarbor().getConfig().getBoolean(location, false); + public static boolean getBoolean(String location) { + return getConfig().getBoolean(location, false); } /** @@ -20,8 +29,8 @@ public class Config { * if location is not found, empty string is returned * @param location Configuration location of the string */ - public static String getString(final String location) { - return Harbor.getHarbor().getConfig().getString(location, ""); + public static String getString(String location) { + return getConfig().getString(location, ""); } /** @@ -29,8 +38,8 @@ public class Config { * if location is not found, 0 is returned * @param location Configuration location of the integer */ - public static int getInteger(final String location) { - return Harbor.getHarbor().getConfig().getInt(location, 0); + public static int getInteger(String location) { + return getConfig().getInt(location, 0); } /** @@ -38,16 +47,7 @@ public class Config { * if location is not found, 0.0 is returned * @param location Configuration location of the double */ - public static double getDouble(final String location) { - return Harbor.getHarbor().getConfig().getDouble(location, 0.0); - } - - /** - * Fetches a list from the configuration - * if location is not found, empty list is returned - * @param location Configuration location of the list - */ - public static List getList(final String location) { - return (List) Harbor.getHarbor().getConfig().getList(location, new ArrayList<>()); + public static double getDouble(String location) { + return getConfig().getDouble(location, 0.0); } } diff --git a/src/main/java/xyz/nkomarn/Harbor/util/Messages.java b/src/main/java/xyz/nkomarn/Harbor/util/Messages.java index 0f82e0f..70a6884 100644 --- a/src/main/java/xyz/nkomarn/Harbor/util/Messages.java +++ b/src/main/java/xyz/nkomarn/Harbor/util/Messages.java @@ -16,7 +16,7 @@ import java.util.Random; public class Messages { public static void sendRandomChatMessage(final World world, final String messageList) { - final List messages = Config.getList(messageList); + final List messages = Config.getConfig().getStringList(messageList); if (messages.size() < 1) return; final int index = new Random().nextInt(Math.max(0, messages.size())); sendWorldChatMessage(world, messages.get(index));