From 2a55f607d31610ba2c2c71118638e16766bb7e88 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 23 Dec 2023 14:18:32 +0100 Subject: [PATCH] Add dynamic spectator disable --- BauSystem_Main/src/BauSystem.properties | 8 --- BauSystem_Main/src/BauSystem_de.properties | 8 --- .../design/endstone/DesignEndStone.java | 9 ++-- .../endstone/DesignEndStoneCommand.java | 24 ++++++--- .../features/detonator/DetonatorListener.java | 3 +- .../killchecker/KillcheckerCommand.java | 19 ++++--- .../killchecker/KillcheckerVisualizer.java | 32 ++---------- .../features/loader/LoaderCommand.java | 14 +++++- .../observer/ObserverTracerCommand.java | 2 +- .../observer/ObserverTracerListener.java | 6 +++ .../features/region/RegionCommand.java | 50 ------------------- .../features/script/ScriptListener.java | 7 +++ .../shieldprinting/ShieldPrinting.java | 7 +++ .../features/simulator/SimulatorCursor.java | 13 ++++- .../tracer/show/TraceShowManager.java | 14 +++++- .../features/util/NoClipCommand.java | 13 ++++- .../features/util/PistonCalculator.java | 2 + .../util/PistonCalculatorCommand.java | 2 +- .../bausystem/features/util/SlotCommand.java | 6 +-- .../features/util/TNTClickListener.java | 2 +- .../features/world/BauMemberUpdate.java | 2 + .../features/world/ItemFrameListener.java | 2 +- .../features/world/WorldEditListener.java | 2 +- 23 files changed, 118 insertions(+), 129 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index 3928e0f4..d34ae1ef 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -804,8 +804,6 @@ REGION_REGION_HELP_RESTORE=§8/§eregion restore §8- §7Resets the region, with REGION_REGION_HELP_RESTORE_SCHEMATIC=§8/§eregion restore §8[§7Schematic§8] §8- §7Resets the region, withoout removing your builds REGION_REGION_HELP_COPYPOINT=§8/§eregion copypoint §8- §7Teleport to the regions copy point REGION_REGION_HELP_TESTBLOCKPOINT=§8/§eregion testblockpoint §8- §7Teleport to the regions dummy point -REGION_REGION_HELP_CHANGETYPE_INFO=§8/§eregion changetype §8- §7Returns the region type -REGION_REGION_HELP_CHANGETYPE=§8/§eregion changetype §8[§7Type§8] §8- §8Sets the region type REGION_REGION_HELP_CHANGESKIN_INFO=§8/§eregion changeskin §8- §7Returns the region skin REGION_REGION_HELP_CHANGESKIN=§8/§eregion changeskin §8[§7Skin§8] §8- §8Sets the region skin REGION_REGION_NOTHING_UNDO=§cNothing left to undo @@ -821,12 +819,6 @@ REGION_REGION_TP_COPY=§7Teleported to the copy point REGION_REGION_TP_TEST_BLOCK=§7Teleported to the tesblock REGION_REGION_TP_UNKNOWN=§cUndefined teleport point REGION_REGION_NO_REGION=§cYou are not inside any region -REGION_REGION_CHANGETYPE_INFO=§7RRegion type is §e{0} -REGION_REGION_CHANGETYPE_UNKNOWN=§cRegion type is invalid -REGION_REGION_CHANGETYPE_INVALID=§cRegion type is not allowed here -REGION_REGION_CHANGETYPE_CHANGE=§7Region type changed to §e{0} -REGION_REGION_CHANGETYPE_CHANGE_UPDATE=§7Click §e§lHERE §7to change the region type -REGION_REGION_CHANGETYPE_CHANGE_UPDATE_HOVER=§8/§ereset REGION_REGION_CHANGESKIN_INFO=§7Region skin is §e{0} REGION_REGION_CHANGESKIN_INFO_CREATOR=§7Skin created by §e{0} REGION_REGION_CHANGESKIN_UNKNOWN=§cRegion skin is invalid diff --git a/BauSystem_Main/src/BauSystem_de.properties b/BauSystem_Main/src/BauSystem_de.properties index ecb3deae..535caa3f 100644 --- a/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem_Main/src/BauSystem_de.properties @@ -767,8 +767,6 @@ REGION_REGION_HELP_RESTORE=§8/§eregion restore §8- §7Setzte die Region zurü REGION_REGION_HELP_RESTORE_SCHEMATIC=§8/§eregion restore §8[§7Schematic§8] §8- §7Setzte die Region zurück, ohne das Gebaute zu löschen REGION_REGION_HELP_COPYPOINT=§8/§eregion copypoint §8- §7Teleportiere dich zum Regions Kopierpunkt REGION_REGION_HELP_TESTBLOCKPOINT=§8/§eregion testblockpoint §8- §7Teleportiere dich zum Regions Testblockpunkt -REGION_REGION_HELP_CHANGETYPE_INFO=§8/§eregion changetype §8- §7Gebe den Regions Type aus -REGION_REGION_HELP_CHANGETYPE=§8/§eregion changetype §8[§7Type§8] §8- §8Setzte den Regions Type REGION_REGION_HELP_CHANGESKIN_INFO=§8/§eregion changeskin §8- §7Gebe den Regions Skin aus REGION_REGION_HELP_CHANGESKIN=§8/§eregion changeskin §8[§7Skin§8] §8- §8Setzte den Regions Skin REGION_REGION_NOTHING_UNDO=§cNichts zum rückgängig machen @@ -784,12 +782,6 @@ REGION_REGION_TP_COPY=§7Zum Kopierpunkt teleportiert REGION_REGION_TP_TEST_BLOCK=§7Zum Testblock teleportiert REGION_REGION_TP_UNKNOWN=§cNicht definierter Teleportierpunkt REGION_REGION_NO_REGION=§cDu bist in keiner Region -REGION_REGION_CHANGETYPE_INFO=§7Regions Type ist §e{0} -REGION_REGION_CHANGETYPE_UNKNOWN=§cRegions Type ist nicht valide -REGION_REGION_CHANGETYPE_INVALID=§cRegions Type ist nicht erlaubt hier -REGION_REGION_CHANGETYPE_CHANGE=§7Regions Type ist auf §e{0}§7 geändert -REGION_REGION_CHANGETYPE_CHANGE_UPDATE=§7Klicke §e§lHIER §7um den Type anzuwenden -REGION_REGION_CHANGETYPE_CHANGE_UPDATE_HOVER=§8/§ereset REGION_REGION_CHANGESKIN_INFO=§7Regions Skin ist §e{0} REGION_REGION_CHANGESKIN_INFO_CREATOR=§7Skin erstellt von §e{0} REGION_REGION_CHANGESKIN_UNKNOWN=§cRegions Skin ist nicht valide diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStone.java b/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStone.java index fd9899f8..0fa990aa 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStone.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStone.java @@ -44,7 +44,6 @@ public class DesignEndStone { private REntityServer entityServer = new REntityServer(); private List entities = new ArrayList<>(); private Set locations = new HashSet<>(); - private List players = new ArrayList<>(); public DesignEndStone(Region region) { this.minX = region.getMinPointBuild().getX(); @@ -95,12 +94,10 @@ public class DesignEndStone { } public void toggle(Player player) { - if (players.contains(player)) { - players.remove(player); + if (entityServer.getPlayers().contains(player)) { entityServer.removePlayer(player); BauSystem.MESSAGE.sendPrefixless("DESIGN_ENDSTONE_DISABLE", player, ChatMessageType.ACTION_BAR); } else { - players.add(player); entityServer.addPlayer(player); calc(); BauSystem.MESSAGE.sendPrefixless("DESIGN_ENDSTONE_ENABLE", player, ChatMessageType.ACTION_BAR); @@ -108,7 +105,7 @@ public class DesignEndStone { } public boolean removePlayer(Player player) { - players.remove(player); - return players.isEmpty(); + entityServer.removePlayer(player); + return entityServer.getPlayers().isEmpty(); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStoneCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStoneCommand.java index 35a7fa7a..92934c23 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStoneCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/design/endstone/DesignEndStoneCommand.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.features.design.endstone; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.utils.RegionType; +import de.steamwar.bausystem.utils.BauMemberUpdateEvent; import de.steamwar.command.SWCommand; import de.steamwar.linkage.Linked; import org.bukkit.Location; @@ -33,6 +34,7 @@ import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.player.PlayerQuitEvent; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; @Linked @@ -56,14 +58,20 @@ public class DesignEndStoneCommand extends SWCommand implements Listener { @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { - Region region = Region.getRegion(event.getPlayer().getLocation()); - DesignEndStone designEndStone = designEndStoneMap.get(region); - if (designEndStone == null) { - return; - } - if (designEndStone.removePlayer(event.getPlayer())) { - designEndStoneMap.remove(region); - } + disableDesignEndStone(event.getPlayer()); + } + + @EventHandler + public void onBauMemberUpdate(BauMemberUpdateEvent event) { + event.getNewSpectator().forEach(this::disableDesignEndStone); + } + + private void disableDesignEndStone(Player player) { + new HashSet<>(designEndStoneMap.entrySet()).forEach(regionDesignEndStoneEntry -> { + if (regionDesignEndStoneEntry.getValue().removePlayer(player)) { + designEndStoneMap.remove(regionDesignEndStoneEntry.getKey()); + } + }); } @EventHandler diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java index 0ea3c469..cabe00c6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/detonator/DetonatorListener.java @@ -92,8 +92,7 @@ public class DetonatorListener implements Listener { @EventHandler(ignoreCancelled = true) public void onPlayerMove(PlayerMoveEvent event) { - if(!Permission.BUILD.hasPermission(event.getPlayer())) return; - if (!Detonator.isDetonator(event.getPlayer().getInventory().getItemInMainHand())) { + if (!Permission.BUILD.hasPermission(event.getPlayer()) ||!Detonator.isDetonator(event.getPlayer().getInventory().getItemInMainHand())) { if (Detonator.hasActiveDetonatorShow(event.getPlayer())) { Detonator.hideDetonator(event.getPlayer()); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java index bbba61ea..9ca7a480 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerCommand.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.features.killchecker; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.utils.BauMemberUpdateEvent; import de.steamwar.bausystem.utils.bossbar.BossBarService; import de.steamwar.command.SWCommand; import de.steamwar.linkage.Linked; @@ -74,16 +75,22 @@ public class KillcheckerCommand extends SWCommand implements Listener { BauSystem.MESSAGE.send("KILLCHECKER_DISABLE", player); } + @EventHandler + public void onBauMemberUpdate(BauMemberUpdateEvent event) { + event.getNewSpectator().forEach(this::hide); + } + @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { - Player player = event.getPlayer(); - Set regions = new HashSet<>(); - visualizers.forEach((region, visualizer) -> { - if (visualizer.disconnect(player)) { - regions.add(region); + hide(event.getPlayer()); + } + + private void hide(Player player) { + new HashSet<>(visualizers.entrySet()).forEach(regionKillcheckerVisualizerEntry -> { + if (regionKillcheckerVisualizerEntry.getValue().hide(player)) { + visualizers.remove(regionKillcheckerVisualizerEntry.getKey()); } }); - regions.forEach(visualizers::remove); } private void recalc(Block block) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java index d7c89254..c68ad901 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/killchecker/KillcheckerVisualizer.java @@ -57,9 +57,6 @@ public class KillcheckerVisualizer { private final int zArea; private final int xArea; - private final Set players = new HashSet<>(); - private final Set areaPlayers = new HashSet<>(); - private final Region region; private final BossBarService bossBarService; @@ -261,7 +258,7 @@ public class KillcheckerVisualizer { double zPercent = xCount / (double) zArea; percent = (xPercent + yPercent + zPercent) / 3; kills = zKills + yKills + xKills; - players.forEach(this::updateBossBar); + outline.getPlayers().forEach(this::updateBossBar); Set pointSet = new HashSet<>(killCount.keySet()); Set outlinePointsCacheLast = new HashSet<>(outlinePointsCache); @@ -356,40 +353,21 @@ public class KillcheckerVisualizer { return new Cuboid(minX, minY, minZ, maxX, maxY, maxZ); } - public boolean show(Player player, boolean onlyOutline) { + public void show(Player player, boolean onlyOutline) { outline.addPlayer(player); if (!onlyOutline) { inner.addPlayer(player); - areaPlayers.add(player); - } else if (areaPlayers.contains(player)) { + } else { inner.removePlayer(player); - areaPlayers.remove(player); } updateBossBar(player); - return players.add(player); } public boolean hide(Player player) { outline.removePlayer(player); - if (areaPlayers.contains(player)) { - inner.removePlayer(player); - } - players.remove(player); - areaPlayers.remove(player); + inner.removePlayer(player); bossBarService.remove(player, region, "killchecker"); - if (players.isEmpty()) { - outline.close(); - inner.close(); - return true; - } - return false; - } - - public boolean disconnect(Player player) { - players.remove(player); - areaPlayers.remove(player); - bossBarService.remove(player, region, "killchecker"); - if (players.isEmpty()) { + if (outline.getPlayers().isEmpty() && inner.getPlayers().isEmpty()) { outline.close(); inner.close(); return true; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java index 55264ec2..ffe27e64 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/loader/LoaderCommand.java @@ -21,13 +21,16 @@ package de.steamwar.bausystem.features.loader; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.utils.BauMemberUpdateEvent; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeValidator; import de.steamwar.linkage.Linked; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; @Linked -public class LoaderCommand extends SWCommand { +public class LoaderCommand extends SWCommand implements Listener { public LoaderCommand() { super("loader"); @@ -101,4 +104,13 @@ public class LoaderCommand extends SWCommand { BauSystem.MESSAGE.send("LOADER_NEW_LOAD_TIME", p, delay); loader.setTicksBetweenBlocks(delay); } + + @EventHandler + public void onBauMemberUpdate(BauMemberUpdateEvent event) { + event.getNewSpectator().forEach(player -> { + Loader loader = Loader.getLoader(player); + if (loader == null) return; + loader.stop(); + }); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerCommand.java index dbd3e48a..531eda68 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerCommand.java @@ -47,7 +47,7 @@ public class ObserverTracerCommand extends SWCommand { } @Register(value = "delete", description = "OBSERVER_HELP_DELETE") - public void delete(Player p) { + public void delete(@Validator Player p) { ObserverTracerListener.observerTracerMap.remove(p); BauSystem.MESSAGE.send("OBSERVER_DELETE", p); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerListener.java index 801f9ce0..a2d9c991 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracerListener.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.features.observer; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.utils.BauMemberUpdateEvent; import de.steamwar.linkage.Linked; import org.bukkit.Bukkit; import org.bukkit.GameMode; @@ -89,6 +90,11 @@ public class ObserverTracerListener implements Listener { } } + @EventHandler + public void onBauMemberUpdate(BauMemberUpdateEvent event) { + event.getNewSpectator().forEach(observerTracerMap::remove); + } + @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { enabled.add(event.getPlayer()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java index 28da6094..efad26fd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java @@ -164,36 +164,6 @@ public class RegionCommand extends SWCommand { BauSystem.MESSAGE.send("REGION_REGION_TP_TEST_BLOCK", p); } - @Register(value = "changetype", description = "REGION_REGION_HELP_CHANGETYPE_INFO") - @Register("type") - public void changeTypeCommand(Player p) { - Region region = Region.getRegion(p.getLocation()); - if (checkGlobalRegion(region, p)) { - return; - } - BauSystem.MESSAGE.send("REGION_REGION_CHANGETYPE_INFO", p, region.getPrototype().getDisplayName()); - } - - @Register(value = "changetype", description = "REGION_REGION_HELP_CHANGETYPE") - @Register("type") - public void changeTypeCommand(@Validator Player p, @Mapper("regionTypeMapper") String s) { - Region region = Region.getRegion(p.getLocation()); - if (checkGlobalRegion(region, p)) { - return; - } - Prototype prototype = Prototype.getByDisplayName(s); - if (prototype == null) { - BauSystem.MESSAGE.send("REGION_REGION_CHANGETYPE_UNKNOWN", p); - } else { - if (region.setPrototype(prototype)) { - BauSystem.MESSAGE.send("REGION_REGION_CHANGETYPE_CHANGE", p, s); - BauSystem.MESSAGE.send("REGION_REGION_CHANGETYPE_CHANGE_UPDATE", p, BauSystem.MESSAGE.parse("REGION_REGION_CHANGETYPE_CHANGE_UPDATE_HOVER", p), new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/reset")); - } else { - BauSystem.MESSAGE.send("REGION_REGION_CHANGETYPE_INVALID", p); - } - } - } - @Register(value = "changeskin", description = "REGION_REGION_HELP_CHANGESKIN_INFO") @Register("skin") public void changeSkinCommand(Player p) { @@ -227,26 +197,6 @@ public class RegionCommand extends SWCommand { } } - @Mapper(value = "regionTypeMapper", local = true) - private TypeMapper regionTypeMapper() { - return new TypeMapper() { - @Override - public List tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) { - Player p = (Player) commandSender; - Region region = Region.getRegion(p.getLocation()); - if (region.isGlobal()) { - return Collections.emptyList(); - } - return region.getPrototypes().stream().map(Prototype::getByName).map(Prototype::getDisplayName).map(c -> c.replace(' ', '_')).collect(Collectors.toList()); - } - - @Override - public String map(CommandSender commandSender, PreviousArguments previousArguments, String s) { - return s.replace('_', ' '); - } - }; - } - @Mapper(value = "skinTypeMapper", local = true) private TypeMapper skinTypeMapper() { return new TypeMapper() { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java index ed88d2ee..14f8d983 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptListener.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.features.script; import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.utils.BauMemberUpdateEvent; import de.steamwar.bausystem.utils.FlatteningWrapper; import de.steamwar.linkage.Linked; import org.bukkit.entity.Player; @@ -74,4 +75,10 @@ public class ScriptListener implements Listener { if(!Permission.BUILD.hasPermission(event.getPlayer())) return; ScriptRunner.updateGlobalScript(event.getPlayer()); } + + @EventHandler + public void onBauMemberUpdate(BauMemberUpdateEvent event) { + event.getNewSpectator().forEach(ScriptRunner::remove); + event.getNewBuilder().forEach(ScriptRunner::updateGlobalScript); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java index 197300d0..1e3fd6e1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/shieldprinting/ShieldPrinting.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.features.shieldprinting; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.shieldprinting.impl.*; import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.utils.BauMemberUpdateEvent; import de.steamwar.bausystem.utils.bossbar.BauSystemBossbar; import de.steamwar.bausystem.utils.bossbar.BossBarService; import de.steamwar.inventory.SWItem; @@ -273,6 +274,12 @@ public class ShieldPrinting implements Listener { updateBossbar(event.getPlayer()); } + @EventHandler + public void onBauMemberUpdate(BauMemberUpdateEvent event) { + event.getNewSpectator().forEach(player -> BossBarService.instance.remove(player, region, "shieldprinting")); + event.getNewBuilder().forEach(this::updateBossbar); + } + private void updateBossbars() { for (Player player : Bukkit.getOnlinePlayers()) { updateBossbar(player); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java index 5dd31b6a..bc09a7b3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java @@ -35,6 +35,7 @@ import de.steamwar.bausystem.features.simulator.execute.SimulatorExecutor; import de.steamwar.bausystem.features.simulator.gui.SimulatorGroupGui; import de.steamwar.bausystem.features.simulator.gui.SimulatorGui; import de.steamwar.bausystem.features.simulator.gui.base.SimulatorBaseGui; +import de.steamwar.bausystem.utils.BauMemberUpdateEvent; import de.steamwar.bausystem.utils.ItemUtils; import de.steamwar.bausystem.utils.RayTraceUtils; import de.steamwar.entity.REntity; @@ -95,6 +96,7 @@ public class SimulatorCursor implements Listener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { + if (Permission.SPECTATOR.hasPermission(event.getPlayer())) return; Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { calcCursor(event.getPlayer()); }, 0); @@ -102,16 +104,23 @@ public class SimulatorCursor implements Listener { @EventHandler public void onPlayerDropItem(PlayerDropItemEvent event) { + if (Permission.SPECTATOR.hasPermission(event.getPlayer())) return; calcCursor(event.getPlayer()); } @EventHandler public void onPlayerItemHeld(PlayerItemHeldEvent event) { + if (Permission.SPECTATOR.hasPermission(event.getPlayer())) return; Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> { calcCursor(event.getPlayer()); }, 1); } + @EventHandler + public void onBauMemberUpdate(BauMemberUpdateEvent event) { + event.getChanged().forEach(this::calcCursor); + } + @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { cursorType.remove(event.getPlayer()); @@ -143,13 +152,12 @@ public class SimulatorCursor implements Listener { } public synchronized void calcCursor(Player player) { - if (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand())) { + if (Permission.SPECTATOR.hasPermission(player) || (!isSimulatorItem(player.getInventory().getItemInMainHand()) && !isSimulatorItem(player.getInventory().getItemInOffHand()))) { if (removeCursor(player) || SimulatorWatcher.show(null, player)) { SWUtils.sendToActionbar(player, ""); } return; } - if(!Permission.BUILD.hasPermission(player)) return; Simulator simulator = SimulatorStorage.getSimulator(player); SimulatorWatcher.show(simulator, player); @@ -316,6 +324,7 @@ public class SimulatorCursor implements Listener { @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { + if (Permission.SPECTATOR.hasPermission(event.getPlayer())) return; if (!ItemUtils.isItem(event.getItem(), "simulator")) { return; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/TraceShowManager.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/TraceShowManager.java index 695c8115..7c335052 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/TraceShowManager.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/TraceShowManager.java @@ -23,6 +23,7 @@ import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.tracer.TNTPosition; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.shared.ShowMode; +import de.steamwar.bausystem.utils.BauMemberUpdateEvent; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -131,12 +132,21 @@ public class TraceShowManager implements Listener { @EventHandler public void onLeave(PlayerQuitEvent event) { + hideComplete(event.getPlayer()); + } + + @EventHandler + public void onBauMemberUpdate(BauMemberUpdateEvent event) { + event.getNewSpectator().forEach(this::hideComplete); + } + + private void hideComplete(Player player) { showModes.forEach((region, playerShowModeMap) -> { - ShowMode showMode = playerShowModeMap.remove(event.getPlayer()); + ShowMode showMode = playerShowModeMap.remove(player); if (showMode != null) showMode.hide(); }); showFilters.forEach((region, playerPredicateMap) -> { - playerPredicateMap.remove(event.getPlayer()); + playerPredicateMap.remove(player); }); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java index ba5d5000..867ad83d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java @@ -24,6 +24,7 @@ import com.comphenix.tinyprotocol.TinyProtocol; import com.mojang.authlib.GameProfile; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.tpslimit.TPSUtils; +import de.steamwar.bausystem.utils.BauMemberUpdateEvent; import de.steamwar.bausystem.utils.NMSWrapper; import de.steamwar.command.SWCommand; import de.steamwar.core.ProtocolWrapper; @@ -97,7 +98,7 @@ public class NoClipCommand extends SWCommand implements Listener { } @Register(help = true) - public void genericCommand(Player player, String... args) { + public void genericCommand(@Validator Player player) { if (NOCLIPS.contains(player)) { NOCLIPS.remove(player); player.setGameMode(GameMode.CREATIVE); @@ -116,6 +117,16 @@ public class NoClipCommand extends SWCommand implements Listener { } } + @EventHandler + public void onBauMemberUpdate(BauMemberUpdateEvent event) { + event.getNewSpectator().forEach(player -> { + if (NOCLIPS.contains(player)) { + NOCLIPS.remove(player); + player.setGameMode(GameMode.CREATIVE); + } + }); + } + @EventHandler(ignoreCancelled = true) public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) { if (NOCLIPS.contains(event.getPlayer())) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculator.java index 0f1cfe5e..6703bd5c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculator.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.features.util; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; import de.steamwar.entity.REntityServer; import de.steamwar.entity.RFallingBlockEntity; import de.steamwar.linkage.Linked; @@ -49,6 +50,7 @@ public class PistonCalculator implements Listener { @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { + if (Permission.SPECTATOR.hasPermission(event.getPlayer())) return; if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; if (!event.hasItem() || event.getItem().getType() != Material.SLIME_BALL) return; if (event.getClickedBlock() == null) return; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculatorCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculatorCommand.java index 8aef617f..71fefaa4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculatorCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculatorCommand.java @@ -32,7 +32,7 @@ public class PistonCalculatorCommand extends SWCommand { } @Register - public void help(Player player) { + public void help(@Validator Player player) { BauSystem.MESSAGE.send("PISTON_HELP_1", player); BauSystem.MESSAGE.send("PISTON_HELP_2", player); BauSystem.MESSAGE.send("PISTON_HELP_3", player); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/SlotCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/SlotCommand.java index 4ea5d62b..37ff3b89 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/SlotCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/SlotCommand.java @@ -41,7 +41,7 @@ public class SlotCommand extends SWCommand { } @Register - public void slotCommand(Player player, Integer slot) { + public void slotCommand(@Validator Player player, Integer slot) { if (slot < 1 || slot > 9) { BauSystem.MESSAGE.send("OTHER_SLOT_INVALID_SLOT", player); return; @@ -50,7 +50,7 @@ public class SlotCommand extends SWCommand { } @Register(value = "pick", description = "OTHER_NOCLIP_SLOT_HELP_PICK") - public void eyedropBlock(Player player) { + public void eyedropBlock(@Validator Player player) { Block block = player.getTargetBlockExact(6); ItemStack itemStack; if (block == null) { @@ -61,7 +61,7 @@ public class SlotCommand extends SWCommand { } @Register(value = "drop", description = "OTHER_NOCLIP_SLOT_HELP_DROP") - public void dropBlock(Player player) { + public void dropBlock(@Validator Player player) { player.getInventory().setItemInMainHand(new ItemStack(Material.AIR)); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/TNTClickListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/TNTClickListener.java index 85f73e04..19cede21 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/TNTClickListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/TNTClickListener.java @@ -35,8 +35,8 @@ public class TNTClickListener implements Listener { @EventHandler public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { + if (Permission.SPECTATOR.hasPermission(event.getPlayer())) return; if (event.getHand() != EquipmentSlot.HAND) return; - if (!Permission.BUILD.hasPermission(event.getPlayer())); Entity entity = event.getRightClicked(); if (event.getRightClicked() instanceof TNTPrimed) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauMemberUpdate.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauMemberUpdate.java index 576b4fa1..b48ccad5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauMemberUpdate.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauMemberUpdate.java @@ -81,6 +81,8 @@ public class BauMemberUpdate extends PacketHandler implements Listener { if (Permission.SPECTATOR.hasPermission(event.getPlayer())) { SPECTATORS.add(event.getPlayer()); event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.GLOWING, -1, 1, false,false, false)); + } else { + event.getPlayer().removePotionEffect(PotionEffectType.GLOWING); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/ItemFrameListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/ItemFrameListener.java index 535551ab..13cf0d0c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/ItemFrameListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/ItemFrameListener.java @@ -42,7 +42,7 @@ public class ItemFrameListener implements Listener { return; } - if(!Permission.BUILD.hasPermission((Player) event.getDamager())) return; + if(Permission.SPECTATOR.hasPermission((Player) event.getDamager())) return; event.setCancelled(true); ItemFrame itemFrame = (ItemFrame) event.getEntity(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditListener.java index a377db87..40e32eda 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/WorldEditListener.java @@ -40,7 +40,7 @@ public class WorldEditListener implements Listener { if (!isWorldEditCommand(e.getMessage().split(" ")[0])) return; Player p = e.getPlayer(); - if (!Permission.BUILD.hasPermission(e.getPlayer())) { + if (Permission.SPECTATOR.hasPermission(e.getPlayer())) { BauSystem.MESSAGE.send("NO_PERMISSION", p); e.setCancelled(true); e.setMessage("/");