diff --git a/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java index a00a0207e..6d978d6be 100644 --- a/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java @@ -327,7 +327,7 @@ public class mcPlayerListener implements Listener { String format = color + "(" + ChatColor.WHITE + name + color + ") " + event.getMessage(); - for (Player x : Bukkit.getServer().getOnlinePlayers()) { + for (Player x : plugin.getServer().getOnlinePlayers()) { if (partyChat && Party.getInstance().inSameParty(player, x)) x.sendMessage(format); else if (adminChat && (x.isOp() || mcPermissions.getInstance().adminChat(x))) { diff --git a/src/main/java/com/gmail/nossr50/locale/mcLocale.java b/src/main/java/com/gmail/nossr50/locale/mcLocale.java index 321b7806a..7e8472da8 100644 --- a/src/main/java/com/gmail/nossr50/locale/mcLocale.java +++ b/src/main/java/com/gmail/nossr50/locale/mcLocale.java @@ -9,67 +9,69 @@ import org.bukkit.ChatColor; import com.gmail.nossr50.config.LoadProperties; -public class mcLocale -{ - private static final String BUNDLE_NAME = "com.gmail.nossr50.locale.locale"; //$NON-NLS-1$ +public class mcLocale { + private static final String BUNDLE_NAME = "com.gmail.nossr50.locale.locale"; + private static ResourceBundle RESOURCE_BUNDLE = null; - private static ResourceBundle RESOURCE_BUNDLE = null; + public static String getString(String key) { + return getString(key, null); + } - public static String getString(String key) - { - return getString(key, null); - } + /** + * Gets the appropriate string from the Locale files. + * + * @param key The key to look up the string with + * @param messageArguments Any arguements to be added to the string + * @return The properly formatted locale string + */ + public static String getString(String key, Object[] messageArguments) { + try { + if (RESOURCE_BUNDLE == null) { + String myLocale = LoadProperties.locale.toLowerCase(); + try { + //attempt to get the locale denoted + RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME, new Locale(myLocale)); + } + catch (MissingResourceException e) { + RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME, new Locale("en_us")); + } + } - public static String getString(String key, Object[] messageArguments) - { - try { - if (RESOURCE_BUNDLE == null) - { - String myLocale = LoadProperties.locale.toLowerCase(); - try { - //attempt to get the locale denoted - RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME, new Locale(myLocale)); - } catch (MissingResourceException e) { - //System.out.println("Failed to load locale specified by mcmmo.properties '"+myLocale+"', defaulting to en_us"); - RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME, new Locale("en_us")); - } - } - - String output = RESOURCE_BUNDLE.getString(key); + String output = RESOURCE_BUNDLE.getString(key); - if (messageArguments != null) - { - MessageFormat formatter = new MessageFormat(""); - formatter.applyPattern(output); - output = formatter.format(messageArguments); - } - - output = addColors(output); - - return output; - } catch (MissingResourceException e) { - return '!' + key + '!'; - } - } - - private static String addColors(String input) { - input = input.replaceAll("\\Q[[BLACK]]\\E", ChatColor.BLACK.toString()); - input = input.replaceAll("\\Q[[DARK_BLUE]]\\E", ChatColor.DARK_BLUE.toString()); - input = input.replaceAll("\\Q[[DARK_GREEN]]\\E", ChatColor.DARK_GREEN.toString()); - input = input.replaceAll("\\Q[[DARK_AQUA]]\\E", ChatColor.DARK_AQUA.toString()); - input = input.replaceAll("\\Q[[DARK_RED]]\\E", ChatColor.DARK_RED.toString()); - input = input.replaceAll("\\Q[[DARK_PURPLE]]\\E", ChatColor.DARK_PURPLE.toString()); - input = input.replaceAll("\\Q[[GOLD]]\\E", ChatColor.GOLD.toString()); - input = input.replaceAll("\\Q[[GRAY]]\\E", ChatColor.GRAY.toString()); - input = input.replaceAll("\\Q[[DARK_GRAY]]\\E", ChatColor.DARK_GRAY.toString()); - input = input.replaceAll("\\Q[[BLUE]]\\E", ChatColor.BLUE.toString()); - input = input.replaceAll("\\Q[[GREEN]]\\E", ChatColor.GREEN.toString()); - input = input.replaceAll("\\Q[[AQUA]]\\E", ChatColor.AQUA.toString()); - input = input.replaceAll("\\Q[[RED]]\\E", ChatColor.RED.toString()); - input = input.replaceAll("\\Q[[LIGHT_PURPLE]]\\E", ChatColor.LIGHT_PURPLE.toString()); - input = input.replaceAll("\\Q[[YELLOW]]\\E", ChatColor.YELLOW.toString()); - input = input.replaceAll("\\Q[[WHITE]]\\E", ChatColor.WHITE.toString()); - - return input; - } + if (messageArguments != null) { + MessageFormat formatter = new MessageFormat(""); + formatter.applyPattern(output); + output = formatter.format(messageArguments); + } + + output = addColors(output); + + return output; + } + catch (MissingResourceException e) { + return '!' + key + '!'; + } + } + + private static String addColors(String input) { + input = input.replaceAll("\\Q[[BLACK]]\\E", ChatColor.BLACK.toString()); + input = input.replaceAll("\\Q[[DARK_BLUE]]\\E", ChatColor.DARK_BLUE.toString()); + input = input.replaceAll("\\Q[[DARK_GREEN]]\\E", ChatColor.DARK_GREEN.toString()); + input = input.replaceAll("\\Q[[DARK_AQUA]]\\E", ChatColor.DARK_AQUA.toString()); + input = input.replaceAll("\\Q[[DARK_RED]]\\E", ChatColor.DARK_RED.toString()); + input = input.replaceAll("\\Q[[DARK_PURPLE]]\\E", ChatColor.DARK_PURPLE.toString()); + input = input.replaceAll("\\Q[[GOLD]]\\E", ChatColor.GOLD.toString()); + input = input.replaceAll("\\Q[[GRAY]]\\E", ChatColor.GRAY.toString()); + input = input.replaceAll("\\Q[[DARK_GRAY]]\\E", ChatColor.DARK_GRAY.toString()); + input = input.replaceAll("\\Q[[BLUE]]\\E", ChatColor.BLUE.toString()); + input = input.replaceAll("\\Q[[GREEN]]\\E", ChatColor.GREEN.toString()); + input = input.replaceAll("\\Q[[AQUA]]\\E", ChatColor.AQUA.toString()); + input = input.replaceAll("\\Q[[RED]]\\E", ChatColor.RED.toString()); + input = input.replaceAll("\\Q[[LIGHT_PURPLE]]\\E", ChatColor.LIGHT_PURPLE.toString()); + input = input.replaceAll("\\Q[[YELLOW]]\\E", ChatColor.YELLOW.toString()); + input = input.replaceAll("\\Q[[WHITE]]\\E", ChatColor.WHITE.toString()); + + return input; + } } diff --git a/src/main/java/com/gmail/nossr50/runnables/RemoveProfileFromMemoryTask.java b/src/main/java/com/gmail/nossr50/runnables/RemoveProfileFromMemoryTask.java index feb7065de..3396a9da0 100644 --- a/src/main/java/com/gmail/nossr50/runnables/RemoveProfileFromMemoryTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/RemoveProfileFromMemoryTask.java @@ -5,18 +5,19 @@ import org.bukkit.entity.Player; import com.gmail.nossr50.Users; public class RemoveProfileFromMemoryTask implements Runnable { - private Player player; + private Player player; - public RemoveProfileFromMemoryTask(Player player) { - this.player = player; - } + public RemoveProfileFromMemoryTask(Player player) { + this.player = player; + } - @Override - public void run() { - //Check if the profile still exists (stuff like MySQL reconnection removes profiles) - if(Users.players.containsKey(player.getName().toLowerCase())) { - Users.getProfile(player.getName()).save(); //We save here so players don't quit/reconnect to cause lag - Users.removeUserByName(player.getName()); - } - } + @Override + public void run() { + String playerName = player.getName(); + //Check if the profile still exists (stuff like MySQL reconnection removes profiles) + if (Users.players.containsKey(playerName.toLowerCase())) { + Users.getProfile(playerName).save(); //We save here so players don't quit/reconnect to cause lag + Users.removeUserByName(playerName); + } + } } diff --git a/src/main/java/com/gmail/nossr50/runnables/SQLConversionTask.java b/src/main/java/com/gmail/nossr50/runnables/SQLConversionTask.java index 500acddee..34efbda9d 100644 --- a/src/main/java/com/gmail/nossr50/runnables/SQLConversionTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/SQLConversionTask.java @@ -10,7 +10,6 @@ import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.LoadProperties; public class SQLConversionTask implements Runnable { - public SQLConversionTask() {} @Override public void run() { @@ -175,40 +174,36 @@ public class SQLConversionTask implements Runnable { + " WHERE id = " + id); mcMMO.database.write("UPDATE " + LoadProperties.MySQLtablePrefix - + "skills SET " + " taming = taming+" - + m.getInt(taming) + ", mining = mining+" - + m.getInt(mining) + ", repair = repair+" - + m.getInt(repair) - + ", woodcutting = woodcutting+" - + m.getInt(woodcutting) + + "skills SET " + + " taming = taming+" + m.getInt(taming) + + ", mining = mining+" + m.getInt(mining) + + ", repair = repair+" + m.getInt(repair) + + ", woodcutting = woodcutting+" + m.getInt(woodcutting) + ", unarmed = unarmed+" + m.getInt(unarmed) - + ", herbalism = herbalism+" - + m.getInt(herbalism) - + ", excavation = excavation+" - + m.getInt(excavation) + + ", herbalism = herbalism+" + m.getInt(herbalism) + + ", excavation = excavation+" + m.getInt(excavation) + ", archery = archery+" + m.getInt(archery) + ", swords = swords+" + m.getInt(swords) + ", axes = axes+" + m.getInt(axes) - + ", acrobatics = acrobatics+" - + m.getInt(acrobatics) + + ", acrobatics = acrobatics+" + m.getInt(acrobatics) + ", fishing = fishing+" + m.getInt(fishing) + " WHERE user_id = " + id); mcMMO.database.write("UPDATE " + LoadProperties.MySQLtablePrefix - + "experience SET " + " taming = " - + m.getInt(tamingXP) + ", mining = " - + m.getInt(miningXP) + ", repair = " - + m.getInt(repairXP) + ", woodcutting = " - + m.getInt(woodCuttingXP) + ", unarmed = " - + m.getInt(unarmedXP) + ", herbalism = " - + m.getInt(herbalismXP) + ", excavation = " - + m.getInt(excavationXP) + ", archery = " - + m.getInt(archeryXP) + ", swords = " - + m.getInt(swordsXP) + ", axes = " - + m.getInt(axesXP) + ", acrobatics = " - + m.getInt(acrobaticsXP) + ", fishing = " - + m.getInt(fishingXP) + " WHERE user_id = " - + id); + + "experience SET " + + " taming = " + m.getInt(tamingXP) + + ", mining = " + m.getInt(miningXP) + + ", repair = " + m.getInt(repairXP) + + ", woodcutting = " + m.getInt(woodCuttingXP) + + ", unarmed = " + m.getInt(unarmedXP) + + ", herbalism = " + m.getInt(herbalismXP) + + ", excavation = " + m.getInt(excavationXP) + + ", archery = " + m.getInt(archeryXP) + + ", swords = " + m.getInt(swordsXP) + + ", axes = " + m.getInt(axesXP) + + ", acrobatics = " + m.getInt(acrobaticsXP) + + ", fishing = " + m.getInt(fishingXP) + + " WHERE user_id = " + id); } else { theCount++; @@ -241,40 +236,40 @@ public class SQLConversionTask implements Runnable { + "' WHERE id = " + id); mcMMO.database.write("UPDATE " + LoadProperties.MySQLtablePrefix - + "skills SET " + " taming = " - + m.getInt(taming) + ", mining = " - + m.getInt(mining) + ", repair = " - + m.getInt(repair) + ", woodcutting = " - + m.getInt(woodcutting) + ", unarmed = " - + m.getInt(unarmed) + ", herbalism = " - + m.getInt(herbalism) + ", excavation = " - + m.getInt(excavation) + ", archery = " - + m.getInt(archery) + ", swords = " - + m.getInt(swords) + ", axes = " - + m.getInt(axes) + ", acrobatics = " - + m.getInt(acrobatics) + ", fishing = " - + m.getInt(fishing) + " WHERE user_id = " - + id); + + "skills SET " + + " taming = taming+" + m.getInt(taming) + + ", mining = mining+" + m.getInt(mining) + + ", repair = repair+" + m.getInt(repair) + + ", woodcutting = woodcutting+" + m.getInt(woodcutting) + + ", unarmed = unarmed+" + m.getInt(unarmed) + + ", herbalism = herbalism+" + m.getInt(herbalism) + + ", excavation = excavation+" + m.getInt(excavation) + + ", archery = archery+" + m.getInt(archery) + + ", swords = swords+" + m.getInt(swords) + + ", axes = axes+" + m.getInt(axes) + + ", acrobatics = acrobatics+" + m.getInt(acrobatics) + + ", fishing = fishing+" + m.getInt(fishing) + + " WHERE user_id = " + id); mcMMO.database.write("UPDATE " + LoadProperties.MySQLtablePrefix - + "experience SET " + " taming = " - + m.getInt(tamingXP) + ", mining = " - + m.getInt(miningXP) + ", repair = " - + m.getInt(repairXP) + ", woodcutting = " - + m.getInt(woodCuttingXP) + ", unarmed = " - + m.getInt(unarmedXP) + ", herbalism = " - + m.getInt(herbalismXP) + ", excavation = " - + m.getInt(excavationXP) + ", archery = " - + m.getInt(archeryXP) + ", swords = " - + m.getInt(swordsXP) + ", axes = " - + m.getInt(axesXP) + ", acrobatics = " - + m.getInt(acrobaticsXP) + ", fishing = " - + m.getInt(fishingXP) + " WHERE user_id = " - + id); + + "experience SET " + + " taming = " + m.getInt(tamingXP) + + ", mining = " + m.getInt(miningXP) + + ", repair = " + m.getInt(repairXP) + + ", woodcutting = " + m.getInt(woodCuttingXP) + + ", unarmed = " + m.getInt(unarmedXP) + + ", herbalism = " + m.getInt(herbalismXP) + + ", excavation = " + m.getInt(excavationXP) + + ", archery = " + m.getInt(archeryXP) + + ", swords = " + m.getInt(swordsXP) + + ", axes = " + m.getInt(axesXP) + + ", acrobatics = " + m.getInt(acrobaticsXP) + + ", fishing = " + m.getInt(fishingXP) + + " WHERE user_id = " + id); } } - System.out.println("[mcMMO] MySQL Updated from users file, " + theCount + " items added/updated to MySQL DB"); + System.out.println("[mcMMO] MySQL Updated from users file, " + theCount + " items added/updated to MySQL DB"); //TODO: Locale in.close(); } catch (Exception e) { diff --git a/src/main/java/com/gmail/nossr50/runnables/SpoutStart.java b/src/main/java/com/gmail/nossr50/runnables/SpoutStart.java index f90561179..574fb28d8 100644 --- a/src/main/java/com/gmail/nossr50/runnables/SpoutStart.java +++ b/src/main/java/com/gmail/nossr50/runnables/SpoutStart.java @@ -9,13 +9,12 @@ import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.spout.SpoutStuff; public class SpoutStart implements Runnable{ - - mcMMO plugin; - + private final mcMMO plugin; + public SpoutStart(mcMMO m) { - plugin = m; + this.plugin = m; } - + @Override public void run() { if (Bukkit.getPluginManager().getPlugin("Spout") != null) { @@ -24,7 +23,7 @@ public class SpoutStart implements Runnable{ else { LoadProperties.spoutEnabled = false; } - + //Spout Stuff if (LoadProperties.spoutEnabled) { SpoutStuff.setupSpoutConfigs(); diff --git a/src/main/java/com/gmail/nossr50/runnables/mcBleedTimer.java b/src/main/java/com/gmail/nossr50/runnables/mcBleedTimer.java index 05a1379cd..4b671139b 100644 --- a/src/main/java/com/gmail/nossr50/runnables/mcBleedTimer.java +++ b/src/main/java/com/gmail/nossr50/runnables/mcBleedTimer.java @@ -52,7 +52,7 @@ public class mcBleedTimer implements Runnable { } PP.decreaseBleedTicks(); - + if (PP.getBleedTicks() == 0) { player.sendMessage(mcLocale.getString("Swords.StoppedBleeding")); } diff --git a/src/main/java/com/gmail/nossr50/runnables/mcSaveTimer.java b/src/main/java/com/gmail/nossr50/runnables/mcSaveTimer.java index 9e3971baf..4843168ba 100644 --- a/src/main/java/com/gmail/nossr50/runnables/mcSaveTimer.java +++ b/src/main/java/com/gmail/nossr50/runnables/mcSaveTimer.java @@ -7,19 +7,16 @@ import com.gmail.nossr50.mcMMO; public class mcSaveTimer implements Runnable { private final mcMMO plugin; - - public mcSaveTimer(final mcMMO plugin) - { + + public mcSaveTimer(final mcMMO plugin) { this.plugin = plugin; } - + @Override - public void run() - { + public void run() { //All player data will be saved periodically through this - for(Player player : plugin.getServer().getOnlinePlayers()) - { + for (Player player : plugin.getServer().getOnlinePlayers()) { Users.getProfile(player).save(); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/gmail/nossr50/runnables/mcTimer.java b/src/main/java/com/gmail/nossr50/runnables/mcTimer.java index ea7cb714a..977fa23f3 100644 --- a/src/main/java/com/gmail/nossr50/runnables/mcTimer.java +++ b/src/main/java/com/gmail/nossr50/runnables/mcTimer.java @@ -1,6 +1,6 @@ package com.gmail.nossr50.runnables; -import org.bukkit.entity.*; +import org.bukkit.entity.Player; import com.gmail.nossr50.Users; import com.gmail.nossr50.mcMMO; @@ -9,49 +9,50 @@ import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.skills.Skills; -public class mcTimer implements Runnable -{ - private final mcMMO plugin; +public class mcTimer implements Runnable { + private final mcMMO plugin; - public mcTimer(final mcMMO plugin) - { + public mcTimer(final mcMMO plugin) { this.plugin = plugin; } - - public void run() - { - long curTime = System.currentTimeMillis(); - for(Player player : plugin.getServer().getOnlinePlayers()) - { - if(player == null) - continue; - PlayerProfile PP = Users.getProfile(player); - - if(PP == null) - continue; - - /* - * MONITOR SKILLS - */ - Skills.monitorSkill(player, PP, curTime, SkillType.AXES); - Skills.monitorSkill(player, PP, curTime, SkillType.EXCAVATION); - Skills.monitorSkill(player, PP, curTime, SkillType.HERBALISM); - Skills.monitorSkill(player, PP, curTime, SkillType.MINING); - Skills.monitorSkill(player, PP, curTime, SkillType.SWORDS); - Skills.monitorSkill(player, PP, curTime, SkillType.UNARMED); - Skills.monitorSkill(player, PP, curTime, SkillType.WOODCUTTING); - - /* - * COOLDOWN MONITORING - */ - Skills.watchCooldown(player, PP, curTime, AbilityType.SKULL_SPLIITER); - Skills.watchCooldown(player, PP, curTime, AbilityType.GIGA_DRILL_BREAKER); - Skills.watchCooldown(player, PP, curTime, AbilityType.GREEN_TERRA); - Skills.watchCooldown(player, PP, curTime, AbilityType.SUPER_BREAKER); - Skills.watchCooldown(player, PP, curTime, AbilityType.SERRATED_STRIKES); - Skills.watchCooldown(player, PP, curTime, AbilityType.BERSERK); - Skills.watchCooldown(player, PP, curTime, AbilityType.TREE_FELLER); - Skills.watchCooldown(player, PP, curTime, AbilityType.BLAST_MINING); - } - } + + @Override + public void run() { + long curTime = System.currentTimeMillis(); + + for (Player player : plugin.getServer().getOnlinePlayers()) { + if (player == null) { //Is this even possible? + continue; + } + + PlayerProfile PP = Users.getProfile(player); + + if (PP == null) { //Is this even possible? + continue; + } + + /* + * MONITOR SKILLS + */ + Skills.monitorSkill(player, PP, curTime, SkillType.AXES); + Skills.monitorSkill(player, PP, curTime, SkillType.EXCAVATION); + Skills.monitorSkill(player, PP, curTime, SkillType.HERBALISM); + Skills.monitorSkill(player, PP, curTime, SkillType.MINING); + Skills.monitorSkill(player, PP, curTime, SkillType.SWORDS); + Skills.monitorSkill(player, PP, curTime, SkillType.UNARMED); + Skills.monitorSkill(player, PP, curTime, SkillType.WOODCUTTING); + + /* + * COOLDOWN MONITORING + */ + Skills.watchCooldown(player, PP, curTime, AbilityType.SKULL_SPLIITER); + Skills.watchCooldown(player, PP, curTime, AbilityType.GIGA_DRILL_BREAKER); + Skills.watchCooldown(player, PP, curTime, AbilityType.GREEN_TERRA); + Skills.watchCooldown(player, PP, curTime, AbilityType.SUPER_BREAKER); + Skills.watchCooldown(player, PP, curTime, AbilityType.SERRATED_STRIKES); + Skills.watchCooldown(player, PP, curTime, AbilityType.BERSERK); + Skills.watchCooldown(player, PP, curTime, AbilityType.TREE_FELLER); + Skills.watchCooldown(player, PP, curTime, AbilityType.BLAST_MINING); + } + } }