From d6c04253966b0d59411f08e3c48fe25ba232160e Mon Sep 17 00:00:00 2001 From: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com> Date: Mon, 11 Mar 2024 23:05:44 -0500 Subject: [PATCH] add permission checks to wand --- .../slimefun/WandListener.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/dev/j3fftw/worldeditslimefun/slimefun/WandListener.java b/src/main/java/dev/j3fftw/worldeditslimefun/slimefun/WandListener.java index c0bfa38..80945b3 100644 --- a/src/main/java/dev/j3fftw/worldeditslimefun/slimefun/WandListener.java +++ b/src/main/java/dev/j3fftw/worldeditslimefun/slimefun/WandListener.java @@ -2,8 +2,12 @@ import dev.j3fftw.worldeditslimefun.utils.PositionManager; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; +import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.libraries.dough.blocks.BlockPosition; +import io.github.thebusybiscuit.slimefun4.libraries.dough.protection.Interaction; +import org.bukkit.ChatColor; import org.bukkit.block.Block; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -12,26 +16,35 @@ public class WandListener implements Listener { - @EventHandler(priority = EventPriority.HIGHEST) + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPlayerInteract(PlayerInteractEvent event) { SlimefunItem slimefunItem = SlimefunItem.getByItem(event.getItem()); if (slimefunItem == null || !slimefunItem.getId().equals("WESF_WAND")) { return; } - event.setCancelled(true); - Block block = event.getClickedBlock(); if (block == null) { return; } + Player player = event.getPlayer(); + if (!Slimefun.getProtectionManager().hasPermission(player, block, Interaction.PLACE_BLOCK) + || !Slimefun.getProtectionManager().hasPermission(player, block, Interaction.BREAK_BLOCK) + || !Slimefun.getProtectionManager().hasPermission(player, block, Interaction.INTERACT_BLOCK) + || !player.hasPermission("wesf.admin")) { + player.sendMessage(ChatColor.RED + "You don't have permission!"); + return; + } + + event.setCancelled(true); + Action action = event.getAction(); BlockPosition position = new BlockPosition(block); if (action == Action.LEFT_CLICK_BLOCK) { - PositionManager.addPositionOne(event.getPlayer(), position); + PositionManager.addPositionOne(player, position); } else if (action == Action.RIGHT_CLICK_BLOCK) { - PositionManager.addPositionTwo(event.getPlayer(), position); + PositionManager.addPositionTwo(player, position); } } }