Runnables cleanup

This commit is contained in:
GJ 2012-04-01 00:11:57 -04:00
parent 18a2b686c1
commit b0fbaa71bf
8 changed files with 182 additions and 187 deletions

View File

@ -327,7 +327,7 @@ public class mcPlayerListener implements Listener {
String format = color + "(" + ChatColor.WHITE + name + color + ") " + event.getMessage(); 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)) if (partyChat && Party.getInstance().inSameParty(player, x))
x.sendMessage(format); x.sendMessage(format);
else if (adminChat && (x.isOp() || mcPermissions.getInstance().adminChat(x))) { else if (adminChat && (x.isOp() || mcPermissions.getInstance().adminChat(x))) {

View File

@ -9,67 +9,69 @@ import org.bukkit.ChatColor;
import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.config.LoadProperties;
public class mcLocale public class mcLocale {
{ private static final String BUNDLE_NAME = "com.gmail.nossr50.locale.locale";
private static final String BUNDLE_NAME = "com.gmail.nossr50.locale.locale"; //$NON-NLS-1$ 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) /**
{ * Gets the appropriate string from the Locale files.
return getString(key, null); *
} * @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) String output = RESOURCE_BUNDLE.getString(key);
{
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);
if (messageArguments != null) if (messageArguments != null) {
{ MessageFormat formatter = new MessageFormat("");
MessageFormat formatter = new MessageFormat(""); formatter.applyPattern(output);
formatter.applyPattern(output); output = formatter.format(messageArguments);
output = formatter.format(messageArguments); }
}
output = addColors(output);
output = addColors(output);
return output;
return output; }
} catch (MissingResourceException e) { catch (MissingResourceException e) {
return '!' + key + '!'; return '!' + key + '!';
} }
} }
private static String addColors(String input) { private static String addColors(String input) {
input = input.replaceAll("\\Q[[BLACK]]\\E", ChatColor.BLACK.toString()); 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_BLUE]]\\E", ChatColor.DARK_BLUE.toString());
input = input.replaceAll("\\Q[[DARK_GREEN]]\\E", ChatColor.DARK_GREEN.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_AQUA]]\\E", ChatColor.DARK_AQUA.toString());
input = input.replaceAll("\\Q[[DARK_RED]]\\E", ChatColor.DARK_RED.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[[DARK_PURPLE]]\\E", ChatColor.DARK_PURPLE.toString());
input = input.replaceAll("\\Q[[GOLD]]\\E", ChatColor.GOLD.toString()); input = input.replaceAll("\\Q[[GOLD]]\\E", ChatColor.GOLD.toString());
input = input.replaceAll("\\Q[[GRAY]]\\E", ChatColor.GRAY.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[[DARK_GRAY]]\\E", ChatColor.DARK_GRAY.toString());
input = input.replaceAll("\\Q[[BLUE]]\\E", ChatColor.BLUE.toString()); input = input.replaceAll("\\Q[[BLUE]]\\E", ChatColor.BLUE.toString());
input = input.replaceAll("\\Q[[GREEN]]\\E", ChatColor.GREEN.toString()); input = input.replaceAll("\\Q[[GREEN]]\\E", ChatColor.GREEN.toString());
input = input.replaceAll("\\Q[[AQUA]]\\E", ChatColor.AQUA.toString()); input = input.replaceAll("\\Q[[AQUA]]\\E", ChatColor.AQUA.toString());
input = input.replaceAll("\\Q[[RED]]\\E", ChatColor.RED.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[[LIGHT_PURPLE]]\\E", ChatColor.LIGHT_PURPLE.toString());
input = input.replaceAll("\\Q[[YELLOW]]\\E", ChatColor.YELLOW.toString()); input = input.replaceAll("\\Q[[YELLOW]]\\E", ChatColor.YELLOW.toString());
input = input.replaceAll("\\Q[[WHITE]]\\E", ChatColor.WHITE.toString()); input = input.replaceAll("\\Q[[WHITE]]\\E", ChatColor.WHITE.toString());
return input; return input;
} }
} }

View File

@ -5,18 +5,19 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.Users; import com.gmail.nossr50.Users;
public class RemoveProfileFromMemoryTask implements Runnable { public class RemoveProfileFromMemoryTask implements Runnable {
private Player player; private Player player;
public RemoveProfileFromMemoryTask(Player player) { public RemoveProfileFromMemoryTask(Player player) {
this.player = player; this.player = player;
} }
@Override @Override
public void run() { public void run() {
//Check if the profile still exists (stuff like MySQL reconnection removes profiles) String playerName = player.getName();
if(Users.players.containsKey(player.getName().toLowerCase())) { //Check if the profile still exists (stuff like MySQL reconnection removes profiles)
Users.getProfile(player.getName()).save(); //We save here so players don't quit/reconnect to cause lag if (Users.players.containsKey(playerName.toLowerCase())) {
Users.removeUserByName(player.getName()); Users.getProfile(playerName).save(); //We save here so players don't quit/reconnect to cause lag
} Users.removeUserByName(playerName);
} }
}
} }

View File

@ -10,7 +10,6 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.config.LoadProperties;
public class SQLConversionTask implements Runnable { public class SQLConversionTask implements Runnable {
public SQLConversionTask() {}
@Override @Override
public void run() { public void run() {
@ -175,40 +174,36 @@ public class SQLConversionTask implements Runnable {
+ " WHERE id = " + id); + " WHERE id = " + id);
mcMMO.database.write("UPDATE " mcMMO.database.write("UPDATE "
+ LoadProperties.MySQLtablePrefix + LoadProperties.MySQLtablePrefix
+ "skills SET " + " taming = taming+" + "skills SET "
+ m.getInt(taming) + ", mining = mining+" + " taming = taming+" + m.getInt(taming)
+ m.getInt(mining) + ", repair = repair+" + ", mining = mining+" + m.getInt(mining)
+ m.getInt(repair) + ", repair = repair+" + m.getInt(repair)
+ ", woodcutting = woodcutting+" + ", woodcutting = woodcutting+" + m.getInt(woodcutting)
+ m.getInt(woodcutting)
+ ", unarmed = unarmed+" + m.getInt(unarmed) + ", unarmed = unarmed+" + m.getInt(unarmed)
+ ", herbalism = herbalism+" + ", herbalism = herbalism+" + m.getInt(herbalism)
+ m.getInt(herbalism) + ", excavation = excavation+" + m.getInt(excavation)
+ ", excavation = excavation+"
+ m.getInt(excavation)
+ ", archery = archery+" + m.getInt(archery) + ", archery = archery+" + m.getInt(archery)
+ ", swords = swords+" + m.getInt(swords) + ", swords = swords+" + m.getInt(swords)
+ ", axes = axes+" + m.getInt(axes) + ", axes = axes+" + m.getInt(axes)
+ ", acrobatics = acrobatics+" + ", acrobatics = acrobatics+" + m.getInt(acrobatics)
+ m.getInt(acrobatics)
+ ", fishing = fishing+" + m.getInt(fishing) + ", fishing = fishing+" + m.getInt(fishing)
+ " WHERE user_id = " + id); + " WHERE user_id = " + id);
mcMMO.database.write("UPDATE " mcMMO.database.write("UPDATE "
+ LoadProperties.MySQLtablePrefix + LoadProperties.MySQLtablePrefix
+ "experience SET " + " taming = " + "experience SET "
+ m.getInt(tamingXP) + ", mining = " + " taming = " + m.getInt(tamingXP)
+ m.getInt(miningXP) + ", repair = " + ", mining = " + m.getInt(miningXP)
+ m.getInt(repairXP) + ", woodcutting = " + ", repair = " + m.getInt(repairXP)
+ m.getInt(woodCuttingXP) + ", unarmed = " + ", woodcutting = " + m.getInt(woodCuttingXP)
+ m.getInt(unarmedXP) + ", herbalism = " + ", unarmed = " + m.getInt(unarmedXP)
+ m.getInt(herbalismXP) + ", excavation = " + ", herbalism = " + m.getInt(herbalismXP)
+ m.getInt(excavationXP) + ", archery = " + ", excavation = " + m.getInt(excavationXP)
+ m.getInt(archeryXP) + ", swords = " + ", archery = " + m.getInt(archeryXP)
+ m.getInt(swordsXP) + ", axes = " + ", swords = " + m.getInt(swordsXP)
+ m.getInt(axesXP) + ", acrobatics = " + ", axes = " + m.getInt(axesXP)
+ m.getInt(acrobaticsXP) + ", fishing = " + ", acrobatics = " + m.getInt(acrobaticsXP)
+ m.getInt(fishingXP) + " WHERE user_id = " + ", fishing = " + m.getInt(fishingXP)
+ id); + " WHERE user_id = " + id);
} }
else { else {
theCount++; theCount++;
@ -241,40 +236,40 @@ public class SQLConversionTask implements Runnable {
+ "' WHERE id = " + id); + "' WHERE id = " + id);
mcMMO.database.write("UPDATE " mcMMO.database.write("UPDATE "
+ LoadProperties.MySQLtablePrefix + LoadProperties.MySQLtablePrefix
+ "skills SET " + " taming = " + "skills SET "
+ m.getInt(taming) + ", mining = " + " taming = taming+" + m.getInt(taming)
+ m.getInt(mining) + ", repair = " + ", mining = mining+" + m.getInt(mining)
+ m.getInt(repair) + ", woodcutting = " + ", repair = repair+" + m.getInt(repair)
+ m.getInt(woodcutting) + ", unarmed = " + ", woodcutting = woodcutting+" + m.getInt(woodcutting)
+ m.getInt(unarmed) + ", herbalism = " + ", unarmed = unarmed+" + m.getInt(unarmed)
+ m.getInt(herbalism) + ", excavation = " + ", herbalism = herbalism+" + m.getInt(herbalism)
+ m.getInt(excavation) + ", archery = " + ", excavation = excavation+" + m.getInt(excavation)
+ m.getInt(archery) + ", swords = " + ", archery = archery+" + m.getInt(archery)
+ m.getInt(swords) + ", axes = " + ", swords = swords+" + m.getInt(swords)
+ m.getInt(axes) + ", acrobatics = " + ", axes = axes+" + m.getInt(axes)
+ m.getInt(acrobatics) + ", fishing = " + ", acrobatics = acrobatics+" + m.getInt(acrobatics)
+ m.getInt(fishing) + " WHERE user_id = " + ", fishing = fishing+" + m.getInt(fishing)
+ id); + " WHERE user_id = " + id);
mcMMO.database.write("UPDATE " mcMMO.database.write("UPDATE "
+ LoadProperties.MySQLtablePrefix + LoadProperties.MySQLtablePrefix
+ "experience SET " + " taming = " + "experience SET "
+ m.getInt(tamingXP) + ", mining = " + " taming = " + m.getInt(tamingXP)
+ m.getInt(miningXP) + ", repair = " + ", mining = " + m.getInt(miningXP)
+ m.getInt(repairXP) + ", woodcutting = " + ", repair = " + m.getInt(repairXP)
+ m.getInt(woodCuttingXP) + ", unarmed = " + ", woodcutting = " + m.getInt(woodCuttingXP)
+ m.getInt(unarmedXP) + ", herbalism = " + ", unarmed = " + m.getInt(unarmedXP)
+ m.getInt(herbalismXP) + ", excavation = " + ", herbalism = " + m.getInt(herbalismXP)
+ m.getInt(excavationXP) + ", archery = " + ", excavation = " + m.getInt(excavationXP)
+ m.getInt(archeryXP) + ", swords = " + ", archery = " + m.getInt(archeryXP)
+ m.getInt(swordsXP) + ", axes = " + ", swords = " + m.getInt(swordsXP)
+ m.getInt(axesXP) + ", acrobatics = " + ", axes = " + m.getInt(axesXP)
+ m.getInt(acrobaticsXP) + ", fishing = " + ", acrobatics = " + m.getInt(acrobaticsXP)
+ m.getInt(fishingXP) + " WHERE user_id = " + ", fishing = " + m.getInt(fishingXP)
+ id); + " 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(); in.close();
} }
catch (Exception e) { catch (Exception e) {

View File

@ -9,13 +9,12 @@ import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.spout.SpoutStuff; import com.gmail.nossr50.spout.SpoutStuff;
public class SpoutStart implements Runnable{ public class SpoutStart implements Runnable{
private final mcMMO plugin;
mcMMO plugin;
public SpoutStart(mcMMO m) { public SpoutStart(mcMMO m) {
plugin = m; this.plugin = m;
} }
@Override @Override
public void run() { public void run() {
if (Bukkit.getPluginManager().getPlugin("Spout") != null) { if (Bukkit.getPluginManager().getPlugin("Spout") != null) {
@ -24,7 +23,7 @@ public class SpoutStart implements Runnable{
else { else {
LoadProperties.spoutEnabled = false; LoadProperties.spoutEnabled = false;
} }
//Spout Stuff //Spout Stuff
if (LoadProperties.spoutEnabled) { if (LoadProperties.spoutEnabled) {
SpoutStuff.setupSpoutConfigs(); SpoutStuff.setupSpoutConfigs();

View File

@ -52,7 +52,7 @@ public class mcBleedTimer implements Runnable {
} }
PP.decreaseBleedTicks(); PP.decreaseBleedTicks();
if (PP.getBleedTicks() == 0) { if (PP.getBleedTicks() == 0) {
player.sendMessage(mcLocale.getString("Swords.StoppedBleeding")); player.sendMessage(mcLocale.getString("Swords.StoppedBleeding"));
} }

View File

@ -7,19 +7,16 @@ import com.gmail.nossr50.mcMMO;
public class mcSaveTimer implements Runnable { public class mcSaveTimer implements Runnable {
private final mcMMO plugin; private final mcMMO plugin;
public mcSaveTimer(final mcMMO plugin) public mcSaveTimer(final mcMMO plugin) {
{
this.plugin = plugin; this.plugin = plugin;
} }
@Override @Override
public void run() public void run() {
{
//All player data will be saved periodically through this //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(); Users.getProfile(player).save();
} }
} }
} }

View File

@ -1,6 +1,6 @@
package com.gmail.nossr50.runnables; package com.gmail.nossr50.runnables;
import org.bukkit.entity.*; import org.bukkit.entity.Player;
import com.gmail.nossr50.Users; import com.gmail.nossr50.Users;
import com.gmail.nossr50.mcMMO; 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.datatypes.SkillType;
import com.gmail.nossr50.skills.Skills; import com.gmail.nossr50.skills.Skills;
public class mcTimer implements Runnable public class mcTimer implements Runnable {
{ private final mcMMO plugin;
private final mcMMO plugin;
public mcTimer(final mcMMO plugin) public mcTimer(final mcMMO plugin) {
{
this.plugin = plugin; this.plugin = plugin;
} }
public void run() @Override
{ public void run() {
long curTime = System.currentTimeMillis(); long curTime = System.currentTimeMillis();
for(Player player : plugin.getServer().getOnlinePlayers())
{ for (Player player : plugin.getServer().getOnlinePlayers()) {
if(player == null) if (player == null) { //Is this even possible?
continue; continue;
PlayerProfile PP = Users.getProfile(player); }
if(PP == null) PlayerProfile PP = Users.getProfile(player);
continue;
if (PP == null) { //Is this even possible?
/* continue;
* MONITOR SKILLS }
*/
Skills.monitorSkill(player, PP, curTime, SkillType.AXES); /*
Skills.monitorSkill(player, PP, curTime, SkillType.EXCAVATION); * MONITOR SKILLS
Skills.monitorSkill(player, PP, curTime, SkillType.HERBALISM); */
Skills.monitorSkill(player, PP, curTime, SkillType.MINING); Skills.monitorSkill(player, PP, curTime, SkillType.AXES);
Skills.monitorSkill(player, PP, curTime, SkillType.SWORDS); Skills.monitorSkill(player, PP, curTime, SkillType.EXCAVATION);
Skills.monitorSkill(player, PP, curTime, SkillType.UNARMED); Skills.monitorSkill(player, PP, curTime, SkillType.HERBALISM);
Skills.monitorSkill(player, PP, curTime, SkillType.WOODCUTTING); Skills.monitorSkill(player, PP, curTime, SkillType.MINING);
Skills.monitorSkill(player, PP, curTime, SkillType.SWORDS);
/* Skills.monitorSkill(player, PP, curTime, SkillType.UNARMED);
* COOLDOWN MONITORING Skills.monitorSkill(player, PP, curTime, SkillType.WOODCUTTING);
*/
Skills.watchCooldown(player, PP, curTime, AbilityType.SKULL_SPLIITER); /*
Skills.watchCooldown(player, PP, curTime, AbilityType.GIGA_DRILL_BREAKER); * COOLDOWN MONITORING
Skills.watchCooldown(player, PP, curTime, AbilityType.GREEN_TERRA); */
Skills.watchCooldown(player, PP, curTime, AbilityType.SUPER_BREAKER); Skills.watchCooldown(player, PP, curTime, AbilityType.SKULL_SPLIITER);
Skills.watchCooldown(player, PP, curTime, AbilityType.SERRATED_STRIKES); Skills.watchCooldown(player, PP, curTime, AbilityType.GIGA_DRILL_BREAKER);
Skills.watchCooldown(player, PP, curTime, AbilityType.BERSERK); Skills.watchCooldown(player, PP, curTime, AbilityType.GREEN_TERRA);
Skills.watchCooldown(player, PP, curTime, AbilityType.TREE_FELLER); Skills.watchCooldown(player, PP, curTime, AbilityType.SUPER_BREAKER);
Skills.watchCooldown(player, PP, curTime, AbilityType.BLAST_MINING); 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);
}
}
} }