Skip to content

Commit

Permalink
add permission checks to wand
Browse files Browse the repository at this point in the history
  • Loading branch information
JustAHuman-xD committed Mar 12, 2024
1 parent 8defb52 commit d6c0425
Showing 1 changed file with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
}

0 comments on commit d6c0425

Please sign in to comment.