Added some verbage around command center block.

Fixed async chat connection stuff.
This commit is contained in:
Jonathan Williams 2014-04-29 12:13:32 -07:00
parent 3ec1653532
commit cee2883786
4 changed files with 69 additions and 50 deletions

View File

@ -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)

View File

@ -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<ChatClient>
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<ChatClient>
_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 + "."));
}
}

View File

@ -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)

View File

@ -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);
}
}