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,36 +9,37 @@ 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) public static String getString(String key) {
{
return getString(key, null); return getString(key, null);
} }
public static String getString(String key, Object[] messageArguments) /**
{ * 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 { try {
if (RESOURCE_BUNDLE == null) if (RESOURCE_BUNDLE == null) {
{
String myLocale = LoadProperties.locale.toLowerCase(); String myLocale = LoadProperties.locale.toLowerCase();
try { try {
//attempt to get the locale denoted //attempt to get the locale denoted
RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME, new Locale(myLocale)); 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"); catch (MissingResourceException e) {
RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME, new Locale("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) 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);
@ -47,7 +48,8 @@ public class mcLocale
output = addColors(output); output = addColors(output);
return output; return output;
} catch (MissingResourceException e) { }
catch (MissingResourceException e) {
return '!' + key + '!'; return '!' + key + '!';
} }
} }

View File

@ -13,10 +13,11 @@ public class RemoveProfileFromMemoryTask implements Runnable {
@Override @Override
public void run() { public void run() {
String playerName = player.getName();
//Check if the profile still exists (stuff like MySQL reconnection removes profiles) //Check if the profile still exists (stuff like MySQL reconnection removes profiles)
if(Users.players.containsKey(player.getName().toLowerCase())) { if (Users.players.containsKey(playerName.toLowerCase())) {
Users.getProfile(player.getName()).save(); //We save here so players don't quit/reconnect to cause lag Users.getProfile(playerName).save(); //We save here so players don't quit/reconnect to cause lag
Users.removeUserByName(player.getName()); 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,11 +9,10 @@ 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

View File

@ -8,17 +8,14 @@ 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,26 +9,27 @@ 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); PlayerProfile PP = Users.getProfile(player);
if(PP == null) if (PP == null) { //Is this even possible?
continue; continue;
}
/* /*
* MONITOR SKILLS * MONITOR SKILLS