From cee288378632d1b39813741b6a05c9d70998e3fa Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Tue, 29 Apr 2014 12:13:32 -0700 Subject: [PATCH] Added some verbage around command center block. Fixed async chat connection stuff. --- .../core/account/CoreClientManager.java | 11 ++- .../src/mineplex/core/chat/Chat.java | 17 ++--- .../core/chat/repository/ChatRepository.java | 74 ++++++++++--------- .../mineplex/core/command/CommandCenter.java | 17 ++++- 4 files changed, 69 insertions(+), 50 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java index d65276c08..1c6c4bebf 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java @@ -164,8 +164,15 @@ public class CoreClientManager implements Listener // Load client in miniplugins Bukkit.getServer().getPluginManager().callEvent(new AsyncClientLoadEvent(token, client)); - // Mysql - Bukkit.getServer().getPluginManager().callEvent(new RetrieveClientInformationEvent(client.GetPlayerName(), uuid)); + try + { + // Mysql + Bukkit.getServer().getPluginManager().callEvent(new RetrieveClientInformationEvent(client.GetPlayerName(), uuid)); + } + catch (Exception exception) + { + System.out.println("Error running RetrieveClientInformationEvent" + exception.getMessage()); + } } @EventHandler(priority = EventPriority.LOWEST) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/chat/Chat.java b/Plugins/Mineplex.Core/src/mineplex/core/chat/Chat.java index 934d5e719..17600c763 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/chat/Chat.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/chat/Chat.java @@ -16,8 +16,6 @@ import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; import mineplex.core.MiniClientPlugin; -import mineplex.core.packethandler.IPacketRunnable; -import mineplex.core.packethandler.PacketHandler; import mineplex.core.recharge.Recharge; import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.UpdateType; @@ -304,14 +302,6 @@ public class Chat extends MiniClientPlugin return hasharray; } - private String parseResponse(String response) - { - JSONObject checkresponse = (JSONObject) JSONValue.parse(response); - String display = checkresponse.get("response").toString(); - - return display; - } - private JSONObject buildJsonChatObject(String filtertype, String name, String player, String msg, int rule) { JSONObject message = new JSONObject(); @@ -489,6 +479,11 @@ public class Chat extends MiniClientPlugin _repository.saveFilterChat(caller.getUniqueId().toString(), !Get(caller).GetFilterChat()); Get(caller).SetFilterChat(!Get(caller).GetFilterChat()); - caller.sendMessage(F.main("Chat", "You have turned chat filtering " + (Get(caller).GetFilterChat() ? "on" : "off") + ".")); + if (Get(caller).GetFilterChat()) + caller.playSound(caller.getLocation(), Sound.NOTE_PIANO, 2f, 2f); + else + caller.playSound(caller.getLocation(), Sound.NOTE_PIANO, 1f, 1f); + + caller.sendMessage(F.main("Chat", "You have turned chat filtering " + ChatColor.YELLOW + (Get(caller).GetFilterChat() ? "ON" : "OFF") + ChatColor.GRAY + ".")); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/chat/repository/ChatRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/chat/repository/ChatRepository.java index 00e2c2d3f..02d993ee9 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/chat/repository/ChatRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/chat/repository/ChatRepository.java @@ -9,6 +9,8 @@ import java.util.UUID; public class ChatRepository { + private static Object _connectionLock = new Object(); + private String _connectionString; private String _userName = "root"; private String _password = "tAbechAk3wR7tuTh"; @@ -75,21 +77,24 @@ public class ChatRepository try { - if (_connection.isClosed()) + synchronized (_connectionLock) { - _connection = DriverManager.getConnection(_connectionString, _userName, _password); - } - - preparedStatement = _connection.prepareStatement(SAVE_FILTER_VALUE); - - preparedStatement.setBoolean(1, filterChat); - preparedStatement.setString(2, uuid); - - affectedRows = preparedStatement.executeUpdate(); - - if (affectedRows == 0) - { - System.out.println("Error saving FilterChat option."); + if (_connection.isClosed()) + { + _connection = DriverManager.getConnection(_connectionString, _userName, _password); + } + + preparedStatement = _connection.prepareStatement(SAVE_FILTER_VALUE); + + preparedStatement.setBoolean(1, filterChat); + preparedStatement.setString(2, uuid); + + affectedRows = preparedStatement.executeUpdate(); + + if (affectedRows == 0) + { + System.out.println("Error saving FilterChat option."); + } } } catch (Exception exception) @@ -119,30 +124,33 @@ public class ChatRepository try { - if (_connection.isClosed()) + synchronized (_connectionLock) { - _connection = DriverManager.getConnection(_connectionString, _userName, _password); - } + if (_connection.isClosed()) + { + _connection = DriverManager.getConnection(_connectionString, _userName, _password); + } - preparedStatement = _connection.prepareStatement(RETRIEVE_FILTER_VALUE); - preparedStatement.setString(1, uuid.toString()); - - resultSet = preparedStatement.executeQuery(); - - if (!resultSet.next()) - { - preparedStatement.close(); - preparedStatement = _connection.prepareStatement(INSERT_ACCOUNT); + preparedStatement = _connection.prepareStatement(RETRIEVE_FILTER_VALUE); preparedStatement.setString(1, uuid.toString()); - preparedStatement.execute(); + resultSet = preparedStatement.executeQuery(); + + if (!resultSet.next()) + { + preparedStatement.close(); + preparedStatement = _connection.prepareStatement(INSERT_ACCOUNT); + preparedStatement.setString(1, uuid.toString()); + + preparedStatement.execute(); + + return true; + } - return true; - } - - while (resultSet.next()) - { - return resultSet.getBoolean(1); + while (resultSet.next()) + { + return resultSet.getBoolean(1); + } } } catch (Exception exception) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/command/CommandCenter.java b/Plugins/Mineplex.Core/src/mineplex/core/command/CommandCenter.java index b225080a0..566644146 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/command/CommandCenter.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/command/CommandCenter.java @@ -1,7 +1,9 @@ package mineplex.core.command; import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.F; import mineplex.core.common.util.NautHashMap; +import mineplex.core.recharge.Recharge; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -47,11 +49,18 @@ public class CommandCenter implements Listener args = event.getMessage().substring(event.getMessage().indexOf(' ') + 1).split(" "); } - ICommand command = Commands.get(commandName); + ICommand command = Commands.get(commandName.toLowerCase()); if (command != null && ClientManager.Get(event.getPlayer()).GetRank().Has(event.getPlayer(), command.GetRequiredRank(), true)) { - command.SetAliasUsed(commandName); + if (!Recharge.Instance.use(event.getPlayer(), "Command", 500, false, false)) + { + event.getPlayer().sendMessage(F.main("Command Center", "You can't spam commands that fast.")); + event.setCancelled(true); + return; + } + + command.SetAliasUsed(commandName.toLowerCase()); command.Execute(event.getPlayer(), args); event.setCancelled(true); @@ -62,7 +71,7 @@ public class CommandCenter implements Listener { for (String commandRoot : command.Aliases()) { - Commands.put(commandRoot, command); + Commands.put(commandRoot.toLowerCase(), command); command.SetCommandCenter(this); } } @@ -71,7 +80,7 @@ public class CommandCenter implements Listener { for (String commandRoot : command.Aliases()) { - Commands.remove(commandRoot); + Commands.remove(commandRoot.toLowerCase()); command.SetCommandCenter(null); } }