Finish guest list.

This commit is contained in:
StevenLawson 2013-08-23 14:43:58 -04:00
parent 6d0b8362b7
commit bf7877addc
2 changed files with 170 additions and 79 deletions

View File

@ -10,7 +10,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.OP, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Go to the AdminWorld.", usage = "/<command> [guest < list | add <player> | remove <player> > | time <worldtime>]")
@CommandParameters(description = "Go to the AdminWorld.", usage = "/<command> [guest < list | purge | add <player> | remove <player> > | time <morning | noon | evening | night> | weather <off | on | storm>]")
public class Command_adminworld extends TFM_Command
{
private enum CommandMode
@ -48,11 +48,12 @@ public class Command_adminworld extends TFM_Command
return false;
}
try
{
switch (commandMode)
{
case TELEPORT:
{
// /adminworld
World adminWorld = null;
try
{
@ -77,31 +78,54 @@ public class Command_adminworld extends TFM_Command
}
case GUEST:
{
// /adminworld guest list
// /adminworld guest add <player>
// /adminworld guest remove <player>
if (args.length == 2)
{
if ("list".equalsIgnoreCase(args[1]))
{
//list
playerMsg("AdminWorld Guest List: " + TFM_AdminWorld.getInstance().guestListToString());
}
else if ("purge".equalsIgnoreCase(args[1]))
{
assertCommandPerms(sender, sender_p);
TFM_AdminWorld.getInstance().purgeGuestList();
playerMsg("AdminWorld guest list purged.");
}
else
{
return false;
}
}
else if (args.length == 3)
{
if (!(sender instanceof Player) || sender_p == null || !TFM_SuperadminList.isUserSuperadmin(sender))
{
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
return true;
}
assertCommandPerms(sender, sender_p);
if ("add".equalsIgnoreCase(args[1]))
{
//add args[2]
try
{
TFM_AdminWorld.getInstance().addGuest(getPlayer(args[2]), sender_p);
}
catch (PlayerNotFoundException ex)
{
sender.sendMessage(ex.getMessage());
return true;
}
}
else if (TFM_Util.isRemoveCommand(args[1]))
{
//remove args[2]
Player player = TFM_AdminWorld.getInstance().removeGuest(args[2]);
if (player != null)
{
playerMsg("Guest removed: " + player.getName());
}
else
{
playerMsg("Can't find guest entry for: " + args[2]);
}
}
else
{
return false;
}
}
@ -109,34 +133,34 @@ public class Command_adminworld extends TFM_Command
}
case TIME:
{
// /adminworld time <morning|noon|evening|night>
if (!(sender instanceof Player) || sender_p == null || !TFM_SuperadminList.isUserSuperadmin(sender))
{
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
return true;
}
assertCommandPerms(sender, sender_p);
if (args.length == 2)
{
//set time = args[1]
//set time = args[1] : <morning|noon|evening|night>
playerMsg("Feature not implemented.");
}
else
{
return false;
}
break;
}
case WEATHER:
{
// /adminworld weather <off|on|storm>
if (!(sender instanceof Player) || sender_p == null || !TFM_SuperadminList.isUserSuperadmin(sender))
{
sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
return true;
}
assertCommandPerms(sender, sender_p);
if (args.length == 2)
{
//set weather = args[1]
//set weather = args[1] : <off|on|storm>
playerMsg("Feature not implemented.");
}
else
{
return false;
}
break;
@ -146,7 +170,28 @@ public class Command_adminworld extends TFM_Command
return false;
}
}
}
catch (PermissionDeniedException ex)
{
sender.sendMessage(ex.getMessage());
}
return true;
}
private void assertCommandPerms(CommandSender sender, Player sender_p) throws PermissionDeniedException
{
if (!(sender instanceof Player) || sender_p == null || !TFM_SuperadminList.isUserSuperadmin(sender))
{
throw new PermissionDeniedException(TotalFreedomMod.MSG_NO_PERMS);
}
}
private class PermissionDeniedException extends Exception
{
public PermissionDeniedException(String string)
{
super(string);
}
}
}

View File

@ -1,7 +1,11 @@
package me.StevenLawson.TotalFreedomMod;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
@ -75,12 +79,50 @@ public final class TFM_AdminWorld extends TFM_CustomWorld
if (TFM_SuperadminList.isUserSuperadmin(supervisor))
{
guestList.put(guest, supervisor);
wipeAccessCache();
}
}
public void removeGuest(Player guest)
public Player removeGuest(Player guest)
{
guestList.remove(guest);
Player player = guestList.remove(guest);
wipeAccessCache();
return player;
}
public Player removeGuest(String partialName)
{
partialName = partialName.toLowerCase().trim();
Iterator<Player> it = guestList.values().iterator();
while (it.hasNext())
{
Player player = it.next();
if (player.getName().toLowerCase().trim().contains(partialName))
{
return removeGuest(player);
}
}
return null;
}
public String guestListToString()
{
List<String> output = new ArrayList<String>();
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();
output.add(player.getName() + " (Supervisor: " + supervisor.getName() + ")");
}
return StringUtils.join(output, ", ");
}
public void purgeGuestList()
{
guestList.clear();
wipeAccessCache();
}
public boolean validateMovement(PlayerMoveEvent event)
@ -129,7 +171,7 @@ public final class TFM_AdminWorld extends TFM_CustomWorld
accessCache.clear();
}
public boolean canAccessWorld(Player player)
public boolean canAccessWorld(final Player player)
{
long currentTimeMillis = System.currentTimeMillis();
if (cacheLastCleared == null || cacheLastCleared.longValue() + CACHE_CLEAR_FREQUENCY <= currentTimeMillis)
@ -146,6 +188,10 @@ public final class TFM_AdminWorld extends TFM_CustomWorld
{
Player supervisor = guestList.get(player);
canAccess = supervisor != null && supervisor.isOnline() && TFM_SuperadminList.isUserSuperadmin(supervisor);
if (!canAccess)
{
guestList.remove(player);
}
}
cached = canAccess;
accessCache.put(player, cached);