Wand Event Handlers
SladeHazard opened this issue · 2 comments
Hey, I'm trying to stop players from using magic wands in certain regions, but I cannot find an appropriate event for it, this causes intense lag as it's being fired a million times, when players hold the wand in their hand, rather than on activation:
@EventHandler(priority = EventPriority.HIGHEST)
public void onHoeUse(WandPreActivateEvent event) {
Mage mage = event.getMage();
Player player = mage.getPlayer(); // Get the player from Mage
Wand wand = event.getWand();
ItemStack item = wand.getItem(); // Get the ItemStack from the Wand
if (item != null && (item.getType() == Material.DIAMOND_HOE || item.getType() == Material.GOLD_HOE || item.getType() == Material.IRON_HOE)) {
if (!player.getWorld().getName().equalsIgnoreCase("mine")) {
event.setCancelled(true);
return;
}
Region region = getNearbyRegion(player, 10);
if (region == null) {
event.setCancelled(true);
}
}
}
is there a better event for this? I couldn't find any, WandActivatedEvent can't be cancelled
Are you only trying to stop them from casting spells with the wand?
If so your best bet is probably to implement CastPermissionManager and then register it via MageController.register.
This will cause Magic to ask your plugin any time a player tries to cast a spell.
Alternately, use the PreCastEvent
.
If by "use a wand" you mean something other than casting a spell, such as activating passive non-spell effects, then you're right that's probably a little different and maybe trickier.
PreCastEvent solved it, thank you. I wanted to prevent spell casting only that happens on right clicking a wand