make aw available to ops

This commit is contained in:
Super_ 2020-07-15 20:17:45 -04:00
parent a1418eb516
commit 03b22ac326
5 changed files with 14 additions and 254 deletions

View File

@ -302,8 +302,6 @@ public class AdminList extends FreedomService
} }
} }
plugin.wm.adminworld.wipeAccessCache();
} }
public Set<String> getAdminNames() public Set<String> getAdminNames()

View File

@ -14,14 +14,14 @@ import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH) @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.", @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 = "/<command> [guest < list | purge | add <player> | remove <player> > | time <morning | noon | evening | night> | weather <off | rain | storm>]", usage = "/<command> [time <morning | noon | evening | night> | weather <off | rain | storm>]",
aliases = "aw") aliases = "aw")
public class Command_adminworld extends FreedomCommand public class Command_adminworld extends FreedomCommand
{ {
private enum CommandMode private enum CommandMode
{ {
TELEPORT, GUEST, TIME, WEATHER TELEPORT, TIME, WEATHER
} }
@Override @Override
@ -35,11 +35,7 @@ public class Command_adminworld extends FreedomCommand
} }
else if (args.length >= 2) else if (args.length >= 2)
{ {
if ("guest".equalsIgnoreCase(args[0])) if ("time".equalsIgnoreCase(args[0]))
{
commandMode = CommandMode.GUEST;
}
else if ("time".equalsIgnoreCase(args[0]))
{ {
commandMode = CommandMode.TIME; commandMode = CommandMode.TIME;
} }
@ -80,79 +76,10 @@ public class Command_adminworld extends FreedomCommand
playerSender.teleport(server.getWorlds().get(0).getSpawnLocation()); playerSender.teleport(server.getWorlds().get(0).getSpawnLocation());
} }
else else
{
if (plugin.wm.adminworld.canAccessWorld(playerSender))
{ {
msg("Going to the AdminWorld."); msg("Going to the AdminWorld.");
plugin.wm.adminworld.sendToWorld(playerSender); 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;
}
}
break; break;
} }
@ -274,20 +201,6 @@ public class Command_adminworld extends FreedomCommand
return Arrays.asList("off", "rain", "storm"); 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(); return Collections.emptyList();
} }

View File

@ -1,14 +1,9 @@
package me.totalfreedom.totalfreedommod.world; package me.totalfreedom.totalfreedommod.world;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FLog;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
@ -17,7 +12,6 @@ import org.bukkit.WorldCreator;
import org.bukkit.WorldType; import org.bukkit.WorldType;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerMoveEvent; 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 static final String GENERATION_PARAMETERS = ConfigEntry.FLATLANDS_GENERATE_PARAMS.getString();
// //
private final Map<Player, Long> teleportCooldown = new HashMap<>(); private final Map<Player, Long> teleportCooldown = new HashMap<>();
private final Map<CommandSender, Boolean> accessCache = new HashMap<>();
// //
private Long cacheLastCleared = null;
private Map<Player, Player> guestList = new HashMap<>(); // Guest, Supervisor
private WorldWeather weather = WorldWeather.OFF; private WorldWeather weather = WorldWeather.OFF;
private WorldTime time = WorldTime.INHERIT; private WorldTime time = WorldTime.INHERIT;
@ -44,11 +35,6 @@ public final class AdminWorld extends CustomWorld
@Override @Override
public void sendToWorld(Player player) public void sendToWorld(Player player)
{ {
if (!canAccessWorld(player))
{
return;
}
super.sendToWorld(player); super.sendToWorld(player);
} }
@ -83,78 +69,6 @@ public final class AdminWorld extends CustomWorld
return world; 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<String> getGuestList()
{
List<String> guests = new ArrayList<>();
for (Player guest : guestList.keySet())
{
guests.add(guest.getName());
}
return guests;
}
public Player removeGuest(String partialName)
{
partialName = partialName.toLowerCase();
final Iterator<Player> 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<String> output = new ArrayList<>();
final Iterator<Map.Entry<Player, Player>> it = guestList.entrySet().iterator();
while (it.hasNext())
{
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, ", ");
}
public void purgeGuestList()
{
guestList.clear();
wipeAccessCache();
}
public boolean validateMovement(PlayerMoveEvent event) public boolean validateMovement(PlayerMoveEvent event)
{ {
World world; World world;
@ -173,10 +87,6 @@ public final class AdminWorld extends CustomWorld
} }
final Player player = event.getPlayer(); final Player player = event.getPlayer();
if (canAccessWorld(player))
{
return true;
}
Long lastTP = teleportCooldown.get(player); Long lastTP = teleportCooldown.get(player);
@ -190,40 +100,6 @@ public final class AdminWorld extends CustomWorld
return false; 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() public WorldWeather getWeatherMode()
{ {
return weather; return weather;

View File

@ -63,40 +63,6 @@ public class WorldManager extends FreedomService
hubworld.getWorld().save(); 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) @EventHandler(priority = EventPriority.HIGH)
public void onThunderChange(ThunderChangeEvent event) public void onThunderChange(ThunderChangeEvent event)
{ {

View File

@ -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; 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. */ 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 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)) 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); event.setCancelled(true);
} }
if (command.equals("coreprotect") || command.equals("core") || command.equals("co")) 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); event.setCancelled(true);
} }
} }