Finished up the Unban feature...

This commit is contained in:
Morten 2015-12-22 21:31:57 +01:00
parent 1726aa2530
commit 9336eb19fa
2 changed files with 59 additions and 13 deletions

View File

@ -1,8 +1,12 @@
package mineplex.core.stats.command; package mineplex.core.stats.command;
import java.util.Iterator;
import java.util.List;
import mineplex.core.account.CoreClient; import mineplex.core.account.CoreClient;
import mineplex.core.command.CommandBase; import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank; import mineplex.core.common.Rank;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.stats.StatsManager; import mineplex.core.stats.StatsManager;
@ -28,29 +32,71 @@ public class MasterBuilderUnban extends CommandBase<StatsManager>
try try
{ {
Plugin.getClientManager().loadClientByName(args[0], new Runnable() Plugin.getClientManager().getRepository().matchPlayerName(new Callback<List<String>>()
{ {
@Override
public void run(List<String> matches)
{
boolean matchedExact = false;
for (String match : matches)
{
if (match.equalsIgnoreCase(args[0]))
{
matchedExact = true;
}
}
if (matchedExact)
{
for (Iterator<String> matchIterator = matches.iterator(); matchIterator.hasNext();)
{
if (!matchIterator.next().equalsIgnoreCase(args[0]))
{
matchIterator.remove();
}
}
}
UtilPlayer.searchOffline(matches, new Callback<String>()
{
@Override
public void run(String target)
{
if(target == null)
{
caller.sendMessage(F.main("MasterBuilder Unban", "Couldn't find " + args[0] + "'s account!"));
return;
}
Plugin.getClientManager().loadClientByName(target, new Runnable()
{
@Override @Override
public void run() public void run()
{ {
CoreClient theClient = Plugin.getClientManager().Get(args[0]); CoreClient theClient = Plugin.getClientManager().Get(target);
if(theClient != null) if(theClient != null)
{ {
Plugin.incrementStat(theClient.getAccountId(), "Global.Build Draw Abuse", 0, true); Plugin.incrementStat(theClient.getAccountId(), "Global.Build Draw Abuse", 0, true); // True = Resets the stat
caller.sendMessage(F.main("MasterBuilder Unban", "The user " + args[0] + " has been unbanned for Master Builders")); caller.sendMessage(F.main("MasterBuilder Unban", "The user " + target + " has been unbanned from Master Builders"));
} }
else else
{ {
caller.sendMessage(F.main("MasterBuilder Unban", "Couldn't find " + args[0] + "'s account!")); caller.sendMessage(F.main("MasterBuilder Unban", "Couldn't find " + target + "'s client!"));
return; return;
} }
} }
}); });
} }
}, caller, args[0], false);
}
}, args[0]);
}
catch(Exception e) catch(Exception e)
{ {
e.printStackTrace();
caller.sendMessage(F.main("MasterBuilder Unban", "Exception caught! Please contact Morten and explain what happened.")); caller.sendMessage(F.main("MasterBuilder Unban", "Exception caught! Please contact Morten and explain what happened."));
} }
} }

View File

@ -24,7 +24,7 @@ public class PasswordRepository extends RepositoryBase
public PasswordRepository(JavaPlugin plugin, String serverName) public PasswordRepository(JavaPlugin plugin, String serverName)
{ {
super(plugin, DBPool.ACCOUNT); super(plugin, DBPool.getAccount());
_serverName = serverName; _serverName = serverName;
} }