i think clans ban is broken in this commit, and i removed some unnecessary spammy debug messages.

This commit is contained in:
Ben 2016-03-24 08:58:48 +00:00
parent 2e41f906d0
commit 2eb4d89875
3 changed files with 66 additions and 11 deletions

View File

@ -245,7 +245,7 @@ public class ClansAdmin
{ {
public void run() public void run()
{ {
if (nameExists) if (nameExists.booleanValue())
UtilPlayer.message(caller, F.main("Clans Admin", "Clan name cannot be a Player name.")); UtilPlayer.message(caller, F.main("Clans Admin", "Clan name cannot be a Player name."));
else else
{ {

View File

@ -1,5 +1,7 @@
package mineplex.game.clans.clans.ban; package mineplex.game.clans.clans.ban;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -20,6 +22,7 @@ import com.google.common.collect.Lists;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.account.ILoginProcessor;
import mineplex.core.common.Pair; import mineplex.core.common.Pair;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback; import mineplex.core.common.util.Callback;
@ -31,7 +34,7 @@ import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ban.commands.ClansBanCommand; import mineplex.game.clans.clans.ban.commands.ClansBanCommand;
import mineplex.game.clans.clans.ban.ui.ClansBanShop; import mineplex.game.clans.clans.ban.ui.ClansBanShop;
public class ClansBanManager extends MiniPlugin public class ClansBanManager extends MiniPlugin implements ILoginProcessor
{ {
private CoreClientManager _clientManager; private CoreClientManager _clientManager;
private ClansBanRepository _repository; private ClansBanRepository _repository;
@ -39,6 +42,8 @@ public class ClansBanManager extends MiniPlugin
private Map<String, Pair<String, String>> _cache; private Map<String, Pair<String, String>> _cache;
private ClansBanShop _shop; private ClansBanShop _shop;
private Map<String, String> _toKick = new HashMap<>();
private Object _lock = new Object(); private Object _lock = new Object();
public ClansBanManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager) public ClansBanManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager)
@ -53,6 +58,8 @@ public class ClansBanManager extends MiniPlugin
_cache = new HashMap<>(); _cache = new HashMap<>();
_shop = new ClansBanShop(this, clientManager, donationManager); _shop = new ClansBanShop(this, clientManager, donationManager);
clientManager.addStoredProcedureLoginProcessor(this);
} }
@Override @Override
@ -229,4 +236,27 @@ public class ClansBanManager extends MiniPlugin
LoadClient(name, callback); LoadClient(name, callback);
} }
public void processLoginResultSet(String playerName, int accountId, ResultSet resultSet) throws SQLException
{
_repository.loadBans(playerName, client -> {
if (client.isBanned())
{
String time = UtilTime.convertString(client.getLongestBan().getTimeLeft(), 0, TimeUnit.FIT);
if (client.getLongestBan().isPermanent())
time = "Permanent";
String reason = C.cRedB + "You are banned from Clans for " + time +
"\n" + C.cWhite + client.getLongestBan().getReason();
_toKick.put(playerName, reason);
}
});
}
public String getQuery(int accountId, String uuid, String name)
{
return "SELECT * FROM clanBans WHERE uuid = '" + uuid + "';";
}
} }

View File

@ -1,5 +1,6 @@
package mineplex.game.clans.clans.ban; package mineplex.game.clans.clans.ban;
import java.sql.ResultSet;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -47,15 +48,36 @@ public class ClansBanRepository extends MinecraftRepository
public void loadBans(final String name, final Callback<ClansBanClient> callback) public void loadBans(final String name, final Callback<ClansBanClient> callback)
{ {
System.out.println(">> Attempting to load Clans Bans for \"" + name + "\"");
loadClientByName(name, client -> { loadClientByName(name, client -> {
System.out.println("> Successfully loaded CoreClient");
String uuid = UUIDFetcher.getUUIDOf(client.GetPlayerName()).toString(); String uuid = UUIDFetcher.getUUIDOf(client.GetPlayerName()).toString();
executeQuery(GET_ALL_BANS, resultSet -> { executeQuery(GET_ALL_BANS, resultSet -> {
System.out.println("> Successfully executed query, result set object: " + resultSet); final List<ClansBan> list = new ArrayList<ClansBan>();
while (resultSet.next())
{
int id = resultSet.getInt(1);
String ruuid = resultSet.getString(2);
String admin = resultSet.getString(3);
String reason = resultSet.getString(4);
Timestamp banTime = resultSet.getTimestamp(5);
Timestamp unbanTime = resultSet.getTimestamp(6);
boolean permanent = resultSet.getBoolean(7);
boolean removed = resultSet.getBoolean(8);
list.add(new ClansBan(id, UUID.fromString(ruuid), admin, reason, banTime, unbanTime, permanent, removed));
}
callback.run(new ClansBanClient(uuid, list));
}, new ColumnVarChar("uuid", 36, uuid));
});
}
public void loadBans(final String name, final String uuid, final ResultSet resultSet, final Callback<ClansBanClient> callback)
{
try
{
final List<ClansBan> list = new ArrayList<ClansBan>(); final List<ClansBan> list = new ArrayList<ClansBan>();
while (resultSet.next()) while (resultSet.next())
@ -78,8 +100,11 @@ public class ClansBanRepository extends MinecraftRepository
System.out.println("> Successfully handled result"); System.out.println("> Successfully handled result");
System.out.println(">> FINISH"); System.out.println(">> FINISH");
}, new ColumnVarChar("uuid", 36, uuid)); }
}); catch (Exception exception)
{
exception.printStackTrace();
}
} }
private void loadClientByName(String name, Callback<CoreClient> client) private void loadClientByName(String name, Callback<CoreClient> client)