From de94e6a7572f6b4ceb34d9b7342a28840fe7e8c3 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Mon, 29 Sep 2014 16:32:47 +1300 Subject: [PATCH] Move updatemessage and permission to disguiseconfig --- .../disguise/DisguiseConfig.java | 22 +++++++++++++++++++ .../disguise/DisguiseListener.java | 14 +++++------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/me/libraryaddict/disguise/DisguiseConfig.java b/src/me/libraryaddict/disguise/DisguiseConfig.java index 9aaf4011..7a2e56bb 100644 --- a/src/me/libraryaddict/disguise/DisguiseConfig.java +++ b/src/me/libraryaddict/disguise/DisguiseConfig.java @@ -1,6 +1,7 @@ package me.libraryaddict.disguise; import me.libraryaddict.disguise.utilities.PacketsManager; + import org.bukkit.ChatColor; import org.bukkit.configuration.ConfigurationSection; @@ -34,6 +35,10 @@ public class DisguiseConfig { private static boolean showNameAboveHeadAlwaysVisible; private static boolean targetDisguises; private static boolean undisguiseSwitchWorlds; + private static String updateMessage = ChatColor.RED + "[LibsDisguises] " + ChatColor.DARK_RED + + "There is a update ready to be downloaded! You are using " + ChatColor.RED + "v%s" + ChatColor.DARK_RED + + ", the new version is " + ChatColor.RED + "%s" + ChatColor.DARK_RED + "!"; + private static String updateNotificationPermission; private static boolean witherSkullEnabled; public static String getDisguiseBlownMessage() { @@ -52,6 +57,14 @@ public class DisguiseConfig { return maxClonedDisguises; } + public static String getUpdateMessage() { + return updateMessage; + } + + public static String getUpdateNotificationPermission() { + return updateNotificationPermission; + } + public static void initConfig(ConfigurationSection config) { setSoundsEnabled(config.getBoolean("DisguiseSounds")); setVelocitySent(config.getBoolean("SendVelocity")); @@ -85,6 +98,7 @@ public class DisguiseConfig { setSheepDyeable(config.getBoolean("DyeableSheep")); setWolfDyeable(config.getBoolean("DyeableWolf")); setUndisguiseOnWorldChange(config.getBoolean("UndisguiseOnWorldChange")); + setUpdateNotificationPermission(config.getString("Permission")); } public static boolean isAnimationPacketsEnabled() { @@ -380,6 +394,14 @@ public class DisguiseConfig { undisguiseSwitchWorlds = isUndisguise; } + public static void setUpdateMessage(String newMessage) { + updateMessage = newMessage; + } + + public static void setUpdateNotificationPermission(String newPermission) { + updateNotificationPermission = newPermission; + } + /** * Disable velocity packets being sent for w/e reason. Maybe you want every ounce of performance you can get? */ diff --git a/src/me/libraryaddict/disguise/DisguiseListener.java b/src/me/libraryaddict/disguise/DisguiseListener.java index 3c0bd14d..9c2b6a7b 100644 --- a/src/me/libraryaddict/disguise/DisguiseListener.java +++ b/src/me/libraryaddict/disguise/DisguiseListener.java @@ -47,14 +47,9 @@ public class DisguiseListener implements Listener { private HashMap disguiseRunnable = new HashMap(); private String latestVersion; private LibsDisguises plugin; - private String updateMessage = ChatColor.RED + "[LibsDisguises] " + ChatColor.DARK_RED - + "There is a update ready to be downloaded! You are using " + ChatColor.RED + "v%s" + ChatColor.DARK_RED - + ", the new version is " + ChatColor.RED + "%s" + ChatColor.DARK_RED + "!"; - private String updateNotifyPermission; public DisguiseListener(LibsDisguises libsDisguises) { plugin = libsDisguises; - updateNotifyPermission = plugin.getConfig().getString("Permission"); if (plugin.getConfig().getBoolean("NotifyUpdate")) { currentVersion = plugin.getDescription().getVersion(); Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() { @@ -68,8 +63,9 @@ public class DisguiseListener implements Listener { Bukkit.getScheduler().runTask(plugin, new Runnable() { public void run() { for (Player p : Bukkit.getOnlinePlayers()) - if (p.hasPermission(updateNotifyPermission)) - p.sendMessage(String.format(updateMessage, currentVersion, latestVersion)); + if (p.hasPermission(DisguiseConfig.getUpdateNotificationPermission())) + p.sendMessage(String.format(DisguiseConfig.getUpdateMessage(), currentVersion, + latestVersion)); } }); } @@ -138,8 +134,8 @@ public class DisguiseListener implements Listener { @EventHandler public void onJoin(PlayerJoinEvent event) { Player p = event.getPlayer(); - if (latestVersion != null && p.hasPermission(updateNotifyPermission)) { - p.sendMessage(String.format(updateMessage, currentVersion, latestVersion)); + if (latestVersion != null && p.hasPermission(DisguiseConfig.getUpdateNotificationPermission())) { + p.sendMessage(String.format(DisguiseConfig.getUpdateMessage(), currentVersion, latestVersion)); } if (DisguiseConfig.isBedPacketsEnabled()) { chunkMove(p, p.getLocation(), null);