diff --git a/src/de/steamwar/lobby/LobbySystem.java b/src/de/steamwar/lobby/LobbySystem.java index e035935..4bf3b87 100644 --- a/src/de/steamwar/lobby/LobbySystem.java +++ b/src/de/steamwar/lobby/LobbySystem.java @@ -19,7 +19,7 @@ package de.steamwar.lobby; -import de.steamwar.lobby.command.DebugCommand; +import de.steamwar.lobby.command.ModifyCommand; import de.steamwar.lobby.command.FlyCommand; import de.steamwar.lobby.command.HologramCommand; import de.steamwar.lobby.command.PortalCommand; @@ -47,7 +47,7 @@ public class LobbySystem extends JavaPlugin { new PortalCommand(); new HologramCommand(); new FlyCommand(); - new DebugCommand(); + new ModifyCommand(); config = new Config(getConfig()); new PlayerSpawn(); diff --git a/src/de/steamwar/lobby/command/HologramCommand.java b/src/de/steamwar/lobby/command/HologramCommand.java index 15832b0..4d101dc 100644 --- a/src/de/steamwar/lobby/command/HologramCommand.java +++ b/src/de/steamwar/lobby/command/HologramCommand.java @@ -43,7 +43,7 @@ public class HologramCommand extends SWCommand { public void portalCreate(Player player, String id, String... text) { if (PortalCommand.noPermissions(player)) return; - new Hologram(id, player.getLocation(), String.join(" ", text)); + new Hologram(id, player.getLocation(), String.join(" ", text), false); LobbySystem.config().save(); } diff --git a/src/de/steamwar/lobby/command/DebugCommand.java b/src/de/steamwar/lobby/command/ModifyCommand.java similarity index 80% rename from src/de/steamwar/lobby/command/DebugCommand.java rename to src/de/steamwar/lobby/command/ModifyCommand.java index 4d87b04..dcf0644 100644 --- a/src/de/steamwar/lobby/command/DebugCommand.java +++ b/src/de/steamwar/lobby/command/ModifyCommand.java @@ -33,32 +33,32 @@ import org.bukkit.event.player.PlayerQuitEvent; import java.util.HashSet; import java.util.Set; -public class DebugCommand extends SWCommand implements Listener { +public class ModifyCommand extends SWCommand implements Listener { - private static final Set debugMode = new HashSet<>(); + private static final Set modifying = new HashSet<>(); - public static boolean debugging(HumanEntity player) { - return debugMode.contains(player); + public static boolean modifying(HumanEntity player) { + return modifying.contains(player); } - public DebugCommand() { - super("debug"); + public ModifyCommand() { + super("modify"); Bukkit.getPluginManager().registerEvents(this, LobbySystem.getPlugin()); } @Register - public void debug(Player player) { + public void modify(Player player) { SteamwarUser user = SteamwarUser.get(player.getUniqueId()); if(!user.getUserGroup().isTeamGroup()) return; - debugMode.add(player); + modifying.add(player); player.setGameMode(GameMode.CREATIVE); player.setOp(true); } @EventHandler public void onLeave(PlayerQuitEvent event) { - debugMode.remove(event.getPlayer()); + modifying.remove(event.getPlayer()); } } diff --git a/src/de/steamwar/lobby/display/Displayable.java b/src/de/steamwar/lobby/display/Displayable.java index b84ca97..0d7b272 100644 --- a/src/de/steamwar/lobby/display/Displayable.java +++ b/src/de/steamwar/lobby/display/Displayable.java @@ -32,6 +32,7 @@ import org.bukkit.event.player.PlayerQuitEvent; import java.util.HashSet; import java.util.Set; import java.util.function.Consumer; +import java.util.function.Function; public class Displayable extends BasicListener { @@ -41,14 +42,20 @@ public class Displayable extends BasicListener { private final int chunkZ; private final Consumer show; private final Consumer hide; + private final Function playerFilter; public Displayable(Location location, Consumer show, Consumer hide) { + this(location, show, hide, player -> true); + } + + public Displayable(Location location, Consumer show, Consumer hide, Function playerFilter) { this.chunkX = posToChunk(location.getX()); this.chunkZ = posToChunk(location.getZ()); this.show = show; this.hide = hide; + this.playerFilter = playerFilter; - Bukkit.getOnlinePlayers().forEach(player -> checkLocation(player, player.getLocation())); + Bukkit.getOnlinePlayers().forEach(this::checkLocation); } public Set getVisitors() { @@ -57,15 +64,19 @@ public class Displayable extends BasicListener { @EventHandler public void onJoin(PlayerJoinEvent e) { - checkLocation(e.getPlayer(), e.getPlayer().getLocation()); + checkLocation(e.getPlayer()); } @EventHandler public void onMove(PlayerMoveEvent e) { - checkLocation(e.getPlayer(), e.getTo()); + checkLocation(e.getPlayer()); } - private void checkLocation(Player player, Location at) { + public void checkLocation(Player player) { + if(!playerFilter.apply(player)) + return; + + Location at = player.getLocation(); boolean shown = visible.contains(player); int viewDistance = player.getClientViewDistance() / 2; boolean see = Math.abs(chunkX - posToChunk(at.getX())) < viewDistance && Math.abs(chunkZ - posToChunk(at.getZ())) < viewDistance; diff --git a/src/de/steamwar/lobby/display/Hologram.java b/src/de/steamwar/lobby/display/Hologram.java index c032d18..5b0b519 100644 --- a/src/de/steamwar/lobby/display/Hologram.java +++ b/src/de/steamwar/lobby/display/Hologram.java @@ -21,6 +21,7 @@ package de.steamwar.lobby.display; import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; +import de.steamwar.lobby.command.ModifyCommand; import org.bukkit.Location; import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.bukkit.entity.Player; @@ -101,7 +102,6 @@ public class Hologram implements ConfigurationSerializable { public static Hologram getHologram(String id) { return holograms.get(id); } - private final Displayable display; private final int entityId; @@ -115,10 +115,10 @@ public class Hologram implements ConfigurationSerializable { private String text; public Hologram(Map map) { - this((String) map.get("id"), (Location) map.get("location"), (String) map.get("text")); + this((String) map.get("id"), (Location) map.get("location"), (String) map.get("text"), false); } - public Hologram(String id, Location location, String text) { + public Hologram(String id, Location location, String text, boolean debugHologram) { this.id = id; this.location = location; this.text = text; @@ -136,7 +136,7 @@ public class Hologram implements ConfigurationSerializable { destroy = destroyPacket(entityId); - display = new Displayable(location, this::show, this::hide); + display = new Displayable(location, this::show, this::hide, debugHologram ? ModifyCommand::modifying : player -> true); if(id != null) holograms.put(id, this); diff --git a/src/de/steamwar/lobby/listener/InventoryInteraction.java b/src/de/steamwar/lobby/listener/InventoryInteraction.java index 616eb5d..8b41119 100644 --- a/src/de/steamwar/lobby/listener/InventoryInteraction.java +++ b/src/de/steamwar/lobby/listener/InventoryInteraction.java @@ -19,7 +19,7 @@ package de.steamwar.lobby.listener; -import de.steamwar.lobby.command.DebugCommand; +import de.steamwar.lobby.command.ModifyCommand; import org.bukkit.Material; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -38,7 +38,7 @@ public class InventoryInteraction extends BasicListener { event.getItem().setAmount(2); return; } - if(!DebugCommand.debugging(event.getPlayer())) + if(!ModifyCommand.modifying(event.getPlayer())) event.setCancelled(true); } @@ -54,13 +54,13 @@ public class InventoryInteraction extends BasicListener { @EventHandler(priority = EventPriority.LOWEST) public void handleInventoryClick(InventoryClickEvent event) { - if(!DebugCommand.debugging(event.getWhoClicked())) + if(!ModifyCommand.modifying(event.getWhoClicked())) event.setCancelled(true); } @EventHandler public void handlePlayerSwapHandItemsEvent(PlayerSwapHandItemsEvent event) { - if(!DebugCommand.debugging(event.getPlayer())) + if(!ModifyCommand.modifying(event.getPlayer())) event.setCancelled(true); } diff --git a/src/de/steamwar/lobby/listener/WorldInteraction.java b/src/de/steamwar/lobby/listener/WorldInteraction.java index 180f6db..9528104 100644 --- a/src/de/steamwar/lobby/listener/WorldInteraction.java +++ b/src/de/steamwar/lobby/listener/WorldInteraction.java @@ -19,7 +19,7 @@ package de.steamwar.lobby.listener; -import de.steamwar.lobby.command.DebugCommand; +import de.steamwar.lobby.command.ModifyCommand; import org.bukkit.entity.HumanEntity; import org.bukkit.event.EventHandler; import org.bukkit.event.block.BlockBreakEvent; @@ -42,19 +42,19 @@ public class WorldInteraction extends BasicListener { @EventHandler public void handleBlockBreak(BlockBreakEvent event) { - if(!DebugCommand.debugging(event.getPlayer())) + if(!ModifyCommand.modifying(event.getPlayer())) event.setCancelled(true); } @EventHandler public void handleBlockPlace(BlockPlaceEvent event) { - if(!DebugCommand.debugging(event.getPlayer())) + if(!ModifyCommand.modifying(event.getPlayer())) event.setCancelled(true); } @EventHandler public void handleHangingBreak(HangingBreakByEntityEvent event) { - if(!DebugCommand.debugging((HumanEntity) event.getRemover())) + if(!ModifyCommand.modifying((HumanEntity) event.getRemover())) event.setCancelled(true); } } diff --git a/src/de/steamwar/lobby/portal/FightserverPortal.java b/src/de/steamwar/lobby/portal/FightserverPortal.java index e2546c3..e8f87f7 100644 --- a/src/de/steamwar/lobby/portal/FightserverPortal.java +++ b/src/de/steamwar/lobby/portal/FightserverPortal.java @@ -76,7 +76,7 @@ public class FightserverPortal implements PortalHandler, Comparable chunkPortals.computeIfAbsent(coords, coords1 -> new ArrayList<>()).add(this)); diff --git a/src/de/steamwar/lobby/portal/TeleportPortal.java b/src/de/steamwar/lobby/portal/TeleportPortal.java index e4e3ba5..9a945f8 100644 --- a/src/de/steamwar/lobby/portal/TeleportPortal.java +++ b/src/de/steamwar/lobby/portal/TeleportPortal.java @@ -20,7 +20,7 @@ package de.steamwar.lobby.portal; import de.steamwar.lobby.LobbySystem; -import de.steamwar.lobby.command.DebugCommand; +import de.steamwar.lobby.command.ModifyCommand; import de.steamwar.lobby.listener.Portals; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -72,7 +72,7 @@ public class TeleportPortal implements PortalHandler { player.sendMessage("§cAus unbekannten Gründen führt dieses Portal zurzeit in den Limbus"); return; } - if(DebugCommand.debugging(player)) + if(ModifyCommand.modifying(player)) player.sendMessage("teleport " + portal.getId() + " -> " + target.getId()); player.teleport(target.denormalize(portal.normalize(to)).toLocation(to.getWorld(), (float) (to.getYaw() - Math.toDegrees(target.getYrotation() - portal.getYrotation())), to.getPitch()), PlayerTeleportEvent.TeleportCause.PLUGIN);