From 03b22ac326b70a406b9a356e5380af3fd63fc472 Mon Sep 17 00:00:00 2001 From: Super_ Date: Wed, 15 Jul 2020 20:17:45 -0400 Subject: [PATCH] make aw available to ops --- .../totalfreedommod/admin/AdminList.java | 2 - .../command/Command_adminworld.java | 97 +------------- .../totalfreedommod/world/AdminWorld.java | 124 ------------------ .../totalfreedommod/world/WorldManager.java | 34 ----- .../world/WorldRestrictions.java | 11 +- 5 files changed, 14 insertions(+), 254 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java b/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java index ee55af72..1ee13ca7 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java @@ -302,8 +302,6 @@ public class AdminList extends FreedomService } } - - plugin.wm.adminworld.wipeAccessCache(); } public Set getAdminNames() diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminworld.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminworld.java index 09a251e4..abbd9709 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminworld.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminworld.java @@ -14,14 +14,14 @@ import org.bukkit.entity.Player; @CommandPermissions(level = Rank.OP, source = SourceType.BOTH) @CommandParameters(description = "Allows for admins to configure guests, time, and weather of the AdminWorld, and allows for admins and guests to go to the AdminWorld.", - usage = "/ [guest < list | purge | add | remove > | time | weather ]", + usage = "/ [time | weather ]", aliases = "aw") public class Command_adminworld extends FreedomCommand { private enum CommandMode { - TELEPORT, GUEST, TIME, WEATHER + TELEPORT, TIME, WEATHER } @Override @@ -35,11 +35,7 @@ public class Command_adminworld extends FreedomCommand } else if (args.length >= 2) { - if ("guest".equalsIgnoreCase(args[0])) - { - commandMode = CommandMode.GUEST; - } - else if ("time".equalsIgnoreCase(args[0])) + if ("time".equalsIgnoreCase(args[0])) { commandMode = CommandMode.TIME; } @@ -81,77 +77,8 @@ public class Command_adminworld extends FreedomCommand } else { - if (plugin.wm.adminworld.canAccessWorld(playerSender)) - { - msg("Going to the AdminWorld."); - plugin.wm.adminworld.sendToWorld(playerSender); - } - else - { - msg("You don't have permission to access the AdminWorld."); - } - } - - break; - } - case GUEST: - { - if (args.length == 2) - { - if ("list".equalsIgnoreCase(args[1])) - { - msg("AdminWorld guest list: " + plugin.wm.adminworld.guestListToString()); - } - else if ("purge".equalsIgnoreCase(args[1])) - { - assertCommandPerms(sender, playerSender); - plugin.wm.adminworld.purgeGuestList(); - FUtil.adminAction(sender.getName(), "AdminWorld guest list purged.", false); - } - else - { - return false; - } - } - else if (args.length == 3) - { - assertCommandPerms(sender, playerSender); - - if ("add".equalsIgnoreCase(args[1])) - { - final Player player = getPlayer(args[2]); - - if (player == null) - { - sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND); - return true; - } - - if (plugin.wm.adminworld.addGuest(player, playerSender)) - { - FUtil.adminAction(sender.getName(), "AdminWorld guest added: " + player.getName(), false); - } - else - { - msg("Could not add player to guest list."); - } - } - else if ("remove".equals(args[1])) - { - final Player player = plugin.wm.adminworld.removeGuest(args[2]); - if (player != null) - { - FUtil.adminAction(sender.getName(), "AdminWorld guest removed: " + player.getName(), false); - } - else - { - msg("Can't find guest entry for: " + args[2]); - } - } - else - { - return false; - } + msg("Going to the AdminWorld."); + plugin.wm.adminworld.sendToWorld(playerSender); } break; @@ -274,20 +201,6 @@ public class Command_adminworld extends FreedomCommand return Arrays.asList("off", "rain", "storm"); } } - else if (args.length == 3) - { - if (args[0].equals("guest")) - { - if (args[1].equals("add")) - { - return FUtil.getPlayerList(); - } - else if (args[1].equals("remove")) - { - return plugin.wm.adminworld.getGuestList(); - } - } - } return Collections.emptyList(); } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/world/AdminWorld.java b/src/main/java/me/totalfreedom/totalfreedommod/world/AdminWorld.java index 4d125792..9a5b0f5b 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/world/AdminWorld.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/world/AdminWorld.java @@ -1,14 +1,9 @@ package me.totalfreedom.totalfreedommod.world; -import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; -import java.util.List; import java.util.Map; -import java.util.Map.Entry; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.util.FLog; -import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -17,7 +12,6 @@ import org.bukkit.WorldCreator; import org.bukkit.WorldType; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerMoveEvent; @@ -29,10 +23,7 @@ public final class AdminWorld extends CustomWorld private static final String GENERATION_PARAMETERS = ConfigEntry.FLATLANDS_GENERATE_PARAMS.getString(); // private final Map teleportCooldown = new HashMap<>(); - private final Map accessCache = new HashMap<>(); // - private Long cacheLastCleared = null; - private Map guestList = new HashMap<>(); // Guest, Supervisor private WorldWeather weather = WorldWeather.OFF; private WorldTime time = WorldTime.INHERIT; @@ -44,11 +35,6 @@ public final class AdminWorld extends CustomWorld @Override public void sendToWorld(Player player) { - if (!canAccessWorld(player)) - { - return; - } - super.sendToWorld(player); } @@ -83,78 +69,6 @@ public final class AdminWorld extends CustomWorld return world; } - public boolean addGuest(Player guest, Player supervisor) - { - if (guest == supervisor || plugin.al.isAdmin(guest)) - { - return false; - } - - if (plugin.al.isAdmin(supervisor)) - { - guestList.put(guest, supervisor); - wipeAccessCache(); - return true; - } - - return false; - } - - public Player removeGuest(Player guest) - { - final Player player = guestList.remove(guest); - wipeAccessCache(); - return player; - } - - public List getGuestList() - { - List guests = new ArrayList<>(); - for (Player guest : guestList.keySet()) - { - guests.add(guest.getName()); - } - return guests; - } - - public Player removeGuest(String partialName) - { - partialName = partialName.toLowerCase(); - final Iterator it = guestList.keySet().iterator(); - - while (it.hasNext()) - { - final Player player = it.next(); - if (player.getName().toLowerCase().contains(partialName)) - { - removeGuest(player); - return player; - } - } - - return null; - } - - public String guestListToString() - { - final List output = new ArrayList<>(); - final Iterator> it = guestList.entrySet().iterator(); - while (it.hasNext()) - { - final Entry entry = it.next(); - final Player player = entry.getKey(); - final 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) { World world; @@ -173,10 +87,6 @@ public final class AdminWorld extends CustomWorld } final Player player = event.getPlayer(); - if (canAccessWorld(player)) - { - return true; - } Long lastTP = teleportCooldown.get(player); @@ -190,40 +100,6 @@ public final class AdminWorld extends CustomWorld return false; } - public void wipeAccessCache() - { - cacheLastCleared = System.currentTimeMillis(); - accessCache.clear(); - } - - public boolean canAccessWorld(final Player player) - { - long currentTimeMillis = System.currentTimeMillis(); - if (cacheLastCleared == null || cacheLastCleared.longValue() + CACHE_CLEAR_FREQUENCY <= currentTimeMillis) - { - cacheLastCleared = currentTimeMillis; - accessCache.clear(); - } - - Boolean cached = accessCache.get(player); - if (cached == null) - { - boolean canAccess = plugin.al.isAdmin(player); - if (!canAccess) - { - Player supervisor = guestList.get(player); - canAccess = supervisor != null && supervisor.isOnline() && plugin.al.isAdmin(supervisor); - if (!canAccess) - { - guestList.remove(player); - } - } - cached = canAccess; - accessCache.put(player, cached); - } - return cached; - } - public WorldWeather getWeatherMode() { return weather; diff --git a/src/main/java/me/totalfreedom/totalfreedommod/world/WorldManager.java b/src/main/java/me/totalfreedom/totalfreedommod/world/WorldManager.java index 57c759fd..61a95871 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/world/WorldManager.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/world/WorldManager.java @@ -63,40 +63,6 @@ public class WorldManager extends FreedomService hubworld.getWorld().save(); } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onPlayerTeleport(PlayerTeleportEvent event) - { - final Player player = event.getPlayer(); - final FPlayer fPlayer = plugin.pl.getPlayer(player); - if (!plugin.al.isAdmin(player) && fPlayer.getFreezeData().isFrozen()) - { - return; // Don't process adminworld validation - } - - adminworld.validateMovement(event); - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onPlayerMove(PlayerMoveEvent event) - { - final Location from = event.getFrom(); - final Location to = event.getTo(); - - try - { - if (from.getWorld() == to.getWorld() && from.distanceSquared(to) < (0.0002 * 0.0002)) - { - // If player just rotated, but didn't move, don't process this event. - return; - } - } - catch (IllegalArgumentException ex) - { - } - - adminworld.validateMovement(event); - } - @EventHandler(priority = EventPriority.HIGH) public void onThunderChange(ThunderChangeEvent event) { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/world/WorldRestrictions.java b/src/main/java/me/totalfreedom/totalfreedommod/world/WorldRestrictions.java index 9ced82fa..73d69d81 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/world/WorldRestrictions.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/world/WorldRestrictions.java @@ -60,6 +60,11 @@ public class WorldRestrictions extends FreedomService } } + if (!plugin.al.isAdmin(player) && player.getWorld().equals(plugin.wm.adminworld.getWorld())) + { + return true; + } + return false; } @@ -131,15 +136,17 @@ public class WorldRestrictions extends FreedomService for obtaining a list of a plugin's commands are returning null for world edit. */ String command = event.getMessage().split("\\s+")[0].substring(1, event.getMessage().split("\\s+")[0].length()).toLowerCase(); + String allowed = player.getWorld().equals(plugin.wm.adminworld.getWorld()) ? "Admins" : "Master Builders"; + if (command.startsWith("/") || BLOCKED_WORLDEDIT_COMMANDS.contains(command)) { - player.sendMessage(ChatColor.RED + "Only Master Builders are allowed to use WorldEdit here."); + player.sendMessage(ChatColor.RED + "Only " + allowed + " are allowed to use WorldEdit here."); event.setCancelled(true); } if (command.equals("coreprotect") || command.equals("core") || command.equals("co")) { - player.sendMessage(ChatColor.RED + "Only Master Builders are allowed to use CoreProtect here."); + player.sendMessage(ChatColor.RED + "Only " + allowed + " are allowed to use CoreProtect here."); event.setCancelled(true); } }