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! #Build Number for ANT. Do not edit!
#Sun Jun 22 17:11:19 CEST 2014 #Sun Jun 22 17:51:33 CEST 2014
build.number=865 build.number=871

View File

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

View File

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