diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_adminworld.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_adminworld.java index 181e0b02..5650c68b 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_adminworld.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_adminworld.java @@ -1,7 +1,9 @@ package me.StevenLawson.TotalFreedomMod.Commands; import me.StevenLawson.TotalFreedomMod.TFM_AdminWorld; +import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList; import me.StevenLawson.TotalFreedomMod.TFM_Util; +import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import org.bukkit.World; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -87,6 +89,12 @@ public class Command_adminworld extends TFM_Command } else if (args.length == 3) { + if (!(sender instanceof Player) || sender_p == null || !TFM_SuperadminList.isUserSuperadmin(sender)) + { + sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); + return true; + } + if ("add".equalsIgnoreCase(args[1])) { //add args[2] @@ -102,6 +110,13 @@ public class Command_adminworld extends TFM_Command case TIME: { // /adminworld time + + if (!(sender instanceof Player) || sender_p == null || !TFM_SuperadminList.isUserSuperadmin(sender)) + { + sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); + return true; + } + if (args.length == 2) { //set time = args[1] @@ -112,6 +127,13 @@ public class Command_adminworld extends TFM_Command case WEATHER: { // /adminworld weather + + if (!(sender instanceof Player) || sender_p == null || !TFM_SuperadminList.isUserSuperadmin(sender)) + { + sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS); + return true; + } + if (args.length == 2) { //set weather = args[1] diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_AdminWorld.java b/src/me/StevenLawson/TotalFreedomMod/TFM_AdminWorld.java index 6bf4a650..eb7e2188 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_AdminWorld.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_AdminWorld.java @@ -21,6 +21,7 @@ public final class TFM_AdminWorld extends TFM_CustomWorld private final Map accessCache = new HashMap(); // private Long cacheLastCleared = null; + private Map guestList = new HashMap(); private TFM_AdminWorld() { @@ -69,6 +70,19 @@ public final class TFM_AdminWorld extends TFM_CustomWorld return world; } + public void addGuest(Player guest, Player supervisor) + { + if (TFM_SuperadminList.isUserSuperadmin(supervisor)) + { + guestList.put(guest, supervisor); + } + } + + public void removeGuest(Player guest) + { + guestList.remove(guest); + } + public boolean validateMovement(PlayerMoveEvent event) { World world; @@ -115,7 +129,7 @@ public final class TFM_AdminWorld extends TFM_CustomWorld accessCache.clear(); } - public boolean canAccessWorld(CommandSender user) + public boolean canAccessWorld(Player player) { long currentTimeMillis = System.currentTimeMillis(); if (cacheLastCleared == null || cacheLastCleared.longValue() + CACHE_CLEAR_FREQUENCY <= currentTimeMillis) @@ -124,11 +138,17 @@ public final class TFM_AdminWorld extends TFM_CustomWorld accessCache.clear(); } - Boolean cached = accessCache.get(user); + Boolean cached = accessCache.get(player); if (cached == null) { - cached = TFM_SuperadminList.isUserSuperadmin(user); - accessCache.put(user, cached); + boolean canAccess = TFM_SuperadminList.isUserSuperadmin(player); + if (!canAccess) + { + Player supervisor = guestList.get(player); + canAccess = supervisor != null && supervisor.isOnline() && TFM_SuperadminList.isUserSuperadmin(supervisor); + } + cached = canAccess; + accessCache.put(player, cached); } return cached; }