Remove adminworld guests properly. Fixes #202

This commit is contained in:
unknown 2014-06-22 17:53:50 +02:00
parent 28459e4702
commit 499472a126
3 changed files with 22 additions and 16 deletions

View File

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit!
#Sun Jun 22 17:11:19 CEST 2014
build.number=865
#Sun Jun 22 17:51:33 CEST 2014
build.number=871

View File

@ -15,7 +15,7 @@ public class Command_adminworld extends TFM_Command
{
private enum CommandMode
{
TELEPORT, GUEST, TIME, WEATHER
TELEPORT, GUEST, TIME, WEATHER;
}
@Override
@ -222,7 +222,9 @@ public class Command_adminworld extends TFM_Command
private class PermissionDeniedException extends Exception
{
public PermissionDeniedException(String string)
private static final long serialVersionUID = 1L;
private PermissionDeniedException(String string)
{
super(string);
}

View File

@ -8,6 +8,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
import me.StevenLawson.TotalFreedomMod.TFM_GameRuleHandler;
import me.StevenLawson.TotalFreedomMod.TFM_Log;
@ -32,7 +33,7 @@ public final class TFM_AdminWorld extends TFM_CustomWorld
private final Map<CommandSender, Boolean> accessCache = new HashMap<CommandSender, Boolean>();
//
private Long cacheLastCleared = null;
private Map<Player, Player> guestList = new HashMap<Player, Player>();
private Map<Player, Player> guestList = new HashMap<Player, Player>(); // Guest, Supervisor
private WeatherMode weatherMode = WeatherMode.OFF;
private TimeOfDay timeOfDay = TimeOfDay.INHERIT;
@ -102,35 +103,38 @@ public final class TFM_AdminWorld extends TFM_CustomWorld
public Player removeGuest(Player guest)
{
Player player = guestList.remove(guest);
final Player player = guestList.remove(guest);
wipeAccessCache();
return player;
}
public Player removeGuest(String partialName)
{
partialName = partialName.toLowerCase().trim();
Iterator<Player> it = guestList.values().iterator();
partialName = partialName.toLowerCase();
final Iterator<Player> it = guestList.keySet().iterator();
while (it.hasNext())
{
Player player = it.next();
if (player.getName().toLowerCase().trim().contains(partialName))
final Player player = it.next();
if (player.getName().toLowerCase().contains(partialName))
{
return removeGuest(player);
removeGuest(player);
return player;
}
}
return null;
}
public String guestListToString()
{
List<String> output = new ArrayList<String>();
Iterator<Map.Entry<Player, Player>> it = guestList.entrySet().iterator();
final List<String> output = new ArrayList<String>();
final Iterator<Map.Entry<Player, Player>> it = guestList.entrySet().iterator();
while (it.hasNext())
{
Map.Entry<Player, Player> entry = it.next();
Player player = entry.getKey();
Player supervisor = entry.getValue();
final Entry<Player, Player> entry = it.next();
final Player player = entry.getKey();
final Player supervisor = entry.getValue();
output.add(player.getName() + " (Supervisor: " + supervisor.getName() + ")");
}
return StringUtils.join(output, ", ");