From b8e926948821f15f049f147701a12e9a88686180 Mon Sep 17 00:00:00 2001 From: bm01 Date: Mon, 25 Jun 2012 14:30:55 +0200 Subject: [PATCH] Made things cleaner --- .../commands/general/MmoupdateCommand.java | 2 +- .../nossr50/commands/mc/McremoveCommand.java | 2 +- src/main/java/com/gmail/nossr50/mcMMO.java | 15 +++----------- .../gmail/nossr50/runnables/SQLReconnect.java | 7 ++----- .../java/com/gmail/nossr50/util/Users.java | 20 ++++++++++++++++++- 5 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/commands/general/MmoupdateCommand.java b/src/main/java/com/gmail/nossr50/commands/general/MmoupdateCommand.java index 2f6b4a2b0..737dacd58 100644 --- a/src/main/java/com/gmail/nossr50/commands/general/MmoupdateCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/general/MmoupdateCommand.java @@ -26,7 +26,7 @@ public class MmoupdateCommand implements CommandExecutor { } sender.sendMessage(ChatColor.GRAY + "Starting conversion..."); //TODO: Needs more locale. - Users.clearUsers(); + Users.clearAll(); convertToMySQL(); for (Player x : plugin.getServer().getOnlinePlayers()) { diff --git a/src/main/java/com/gmail/nossr50/commands/mc/McremoveCommand.java b/src/main/java/com/gmail/nossr50/commands/mc/McremoveCommand.java index c5739abe0..66a3900ea 100644 --- a/src/main/java/com/gmail/nossr50/commands/mc/McremoveCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/mc/McremoveCommand.java @@ -102,7 +102,7 @@ public class McremoveCommand implements CommandExecutor { PlayerProfile playerProfile = Users.getProfile(player); if (playerProfile != null) { - Users.getProfiles().remove(playerProfile); + Users.remove(player.getName()); if (player.isOnline()) { Users.addUser((Player) player); diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index 7c7951ec6..c74995435 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -284,20 +284,11 @@ public class mcMMO extends JavaPlugin { */ @Override public void onDisable() { - //Make sure to save player information if the server shuts down - for (PlayerProfile playerProfile : Users.getProfiles().values()) { - playerProfile.save(); - } - + Users.saveAll(); //Make sure to save player information if the server shuts down PartyManager.getInstance().saveParties(); - getServer().getScheduler().cancelTasks(this); //This removes our tasks - - //Save our metadata - placeStore.saveAll(); - - //Cleanup empty metadata stores - placeStore.cleanUp(); + placeStore.saveAll(); //Save our metadata + placeStore.cleanUp(); //Cleanup empty metadata stores //Remove other tasks BEFORE starting the Backup, or we just cancel it straight away. try { diff --git a/src/main/java/com/gmail/nossr50/runnables/SQLReconnect.java b/src/main/java/com/gmail/nossr50/runnables/SQLReconnect.java index fd8f76b5b..83cbc870b 100644 --- a/src/main/java/com/gmail/nossr50/runnables/SQLReconnect.java +++ b/src/main/java/com/gmail/nossr50/runnables/SQLReconnect.java @@ -3,7 +3,6 @@ package com.gmail.nossr50.runnables; import org.bukkit.entity.Player; import com.gmail.nossr50.mcMMO; -import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.util.Database; import com.gmail.nossr50.util.Users; @@ -19,11 +18,9 @@ public class SQLReconnect implements Runnable { if (!Database.isConnected()) { Database.connect(); if (Database.isConnected()) { - for (PlayerProfile playerProfile : Users.getProfiles().values()) { - playerProfile.save(); //Save all profiles - } + Users.saveAll(); //Save all profiles + Users.clearAll(); //Clear the profiles - Users.clearUsers(); //Clear the profiles for (Player player : plugin.getServer().getOnlinePlayers()) { Users.addUser(player); //Add in new profiles, forcing them to 'load' again from MySQL } diff --git a/src/main/java/com/gmail/nossr50/util/Users.java b/src/main/java/com/gmail/nossr50/util/Users.java index 8974f4066..b02c53620 100644 --- a/src/main/java/com/gmail/nossr50/util/Users.java +++ b/src/main/java/com/gmail/nossr50/util/Users.java @@ -58,13 +58,31 @@ public class Users { return playerProfile; } + /* + * Remove a user. + * + * @param playerName The name of the player to remove + */ + public static void remove(String playerName) { + profiles.remove(playerName); + } + /** * Clear all users. */ - public static void clearUsers() { + public static void clearAll() { profiles.clear(); } + /* + * Save all users. + */ + public static void saveAll() { + for (PlayerProfile playerProfile : profiles.values()) { + playerProfile.save(); + } + } + /** * Get all PlayerProfiles. *