Skip to content

Commit

Permalink
Runnables cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
gmcferrin committed Apr 1, 2012
1 parent 18a2b68 commit b0fbaa7
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 187 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ else if (adminChat) {

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))) {
Expand Down
120 changes: 61 additions & 59 deletions src/main/java/com/gmail/nossr50/locale/mcLocale.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,67 +9,69 @@

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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
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);
}
}
}
107 changes: 51 additions & 56 deletions src/main/java/com/gmail/nossr50/runnables/SQLConversionTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.gmail.nossr50.config.LoadProperties;

public class SQLConversionTask implements Runnable {
public SQLConversionTask() {}

@Override
public void run() {
Expand Down Expand Up @@ -175,40 +174,36 @@ public void run() {
+ " 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++;
Expand Down Expand Up @@ -241,40 +236,40 @@ public void run() {
+ "' 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) {
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/com/gmail/nossr50/runnables/SpoutStart.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
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) {
Expand All @@ -24,7 +23,7 @@ public void run() {
else {
LoadProperties.spoutEnabled = false;
}

//Spout Stuff
if (LoadProperties.spoutEnabled) {
SpoutStuff.setupSpoutConfigs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void run() {
}

PP.decreaseBleedTicks();

if (PP.getBleedTicks() == 0) {
player.sendMessage(mcLocale.getString("Swords.StoppedBleeding"));
}
Expand Down
15 changes: 6 additions & 9 deletions src/main/java/com/gmail/nossr50/runnables/mcSaveTimer.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@

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();
}
}
}
}
Loading

0 comments on commit b0fbaa7

Please sign in to comment.