From 6305453e1588e961334edd99b448c7f19493dac2 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 16 Dec 2023 21:34:29 +0100 Subject: [PATCH] Fix Permission for SignEdit and other stuff --- .../src/de/steamwar/bausystem/Permission.java | 4 +-- .../bausystem/features/bau/InfoCommand.java | 33 ++++++++++--------- .../features/world/SignEditFrom20.java | 2 ++ .../features/world/SignEditUntil19.java | 2 ++ .../features/world/SpectatorListener.java | 26 ++++++++++++--- 5 files changed, 45 insertions(+), 22 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/Permission.java b/BauSystem_Main/src/de/steamwar/bausystem/Permission.java index 50251be3..8e51d97d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/Permission.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/Permission.java @@ -32,10 +32,10 @@ public enum Permission { OWNER(bauweltMember -> false), SUPERVISOR(bauweltMember -> { - return false; // TODO: Needs to be changed later on + return bauweltMember.isWorld(); }), BUILD(bauweltMember -> { - return bauweltMember.isWorld() || bauweltMember.isWorldEdit() || SUPERVISOR.permissionPredicate.test(bauweltMember); + return bauweltMember.isWorldEdit() || SUPERVISOR.permissionPredicate.test(bauweltMember); }), SPECTATOR(bauweltMember -> { return !BUILD.permissionPredicate.test(bauweltMember); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java index 1a7e1551..9f53f563 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java @@ -43,24 +43,27 @@ public class InfoCommand extends SWCommand { } } - List members = BauweltMember.getMembers(bauServer.getOwnerID()); - StringBuilder membermessage = new StringBuilder(); - membermessage.append(BauSystem.MESSAGE.parsePrefixed("BAU_INFO_COMMAND_MEMBER", p, members.size())); + if (Permission.BUILD.hasPermission(p)) { + List members = BauweltMember.getMembers(bauServer.getOwnerID()); + StringBuilder membermessage = new StringBuilder(); + membermessage.append(BauSystem.MESSAGE.parsePrefixed("BAU_INFO_COMMAND_MEMBER", p, members.size())); - for (int i = 0; i < members.size(); i++) { - if (i != 0) { - membermessage.append(", "); - } - BauweltMember member = members.get(i); - if (Permission.SUPERVISOR.hasPermission(member)) { - membermessage.append("§c").append(SteamwarUser.get(member.getMemberID()).getUserName()); - } else if (Permission.BUILD.hasPermission(member)) { - membermessage.append("§e").append(SteamwarUser.get(member.getMemberID()).getUserName()); - } else { - membermessage.append("§7").append(SteamwarUser.get(member.getMemberID()).getUserName()); + for (int i = 0; i < members.size(); i++) { + if (i != 0) { + membermessage.append("§8, "); + } + BauweltMember member = members.get(i); + if (Permission.SUPERVISOR.hasPermission(member)) { + membermessage.append("§e"); + } else if (Permission.BUILD.hasPermission(member)) { + membermessage.append("§6"); + } else { + membermessage.append("§7"); + } + membermessage.append(SteamwarUser.get(member.getMemberID()).getUserName()); } + p.sendMessage(membermessage.toString()); } - p.sendMessage(membermessage.toString()); StringBuilder tpsMessage = new StringBuilder(); tpsMessage.append(BauSystem.MESSAGE.parsePrefixed("BAU_INFO_COMMAND_TPS", p)); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditFrom20.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditFrom20.java index 7956a3ef..df4935dc 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditFrom20.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditFrom20.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.features.world; import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.utils.PlaceItemUtils; import de.steamwar.linkage.Linked; import de.steamwar.linkage.MinVersion; @@ -81,6 +82,7 @@ public class SignEditFrom20 implements Listener { } private void edit(Player player, Block block) { + if (Permission.SPECTATOR.hasPermission(player)) return; Sign sign = (Sign) block.getState(); Side side = signSide(player, block); SignSide signSide = sign.getSide(side); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditUntil19.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditUntil19.java index 19184032..89a4120d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditUntil19.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditUntil19.java @@ -22,6 +22,7 @@ package de.steamwar.bausystem.features.world; import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; import de.steamwar.linkage.Linked; import de.steamwar.linkage.MaxVersion; import org.bukkit.Bukkit; @@ -68,6 +69,7 @@ public class SignEditUntil19 implements Listener { } private void edit(Player player, Block block) { + if (Permission.SPECTATOR.hasPermission(player)) return; Sign sign = (org.bukkit.block.Sign) block.getState(); String[] lines = sign.getLines(); for (int i = 0; i < lines.length; i++) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java index f80661aa..a15c1e4f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/SpectatorListener.java @@ -27,10 +27,11 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockCanBuildEvent; -import org.bukkit.event.block.BlockMultiPlaceEvent; -import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.block.*; +import org.bukkit.event.entity.EntityChangeBlockEvent; +import org.bukkit.event.entity.EntityEnterBlockEvent; +import org.bukkit.event.entity.EntityInteractEvent; +import org.bukkit.event.entity.EntityPickupItemEvent; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.player.*; import org.bukkit.inventory.ItemStack; @@ -73,7 +74,7 @@ public class SpectatorListener implements Listener { } } - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + @EventHandler public void onInventoryClick(InventoryClickEvent event) { ItemStack itemStack = event.getCurrentItem(); if (itemStack == null || !itemStack.hasItemMeta()) { @@ -161,4 +162,19 @@ public class SpectatorListener implements Listener { event.setCancelled(true); } } + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onPlayerDropItem(PlayerDropItemEvent event) { + if (Permission.SPECTATOR.hasPermission(event.getPlayer())) { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onEntityPickupItem(EntityPickupItemEvent event) { + if (!(event.getEntity() instanceof Player)) return; + if (Permission.SPECTATOR.hasPermission((Player) event.getEntity())) { + event.setCancelled(true); + } + } }