private void usePowertools(final PlayerAnimationEvent event) { if (event.getAnimationType() != PlayerAnimationType.ARM_SWING) { return; } final User user = ess.getUser(event.getPlayer()); final ItemStack is = user.getItemInHand(); if (is == null || is.getType() == Material.AIR || !user.arePowerToolsEnabled()) { return; } final List<String> commandList = user.getPowertool(is); if (commandList == null || commandList.isEmpty()) { return; } // We need to loop through each command and execute for (String command : commandList) { if (command.matches(".*\\{player\\}.*")) { // user.sendMessage("Click a player to use this command"); continue; } else if (command.startsWith("c:")) { for (Player p : server.getOnlinePlayers()) { p.sendMessage(user.getDisplayName() + ":" + command.substring(2)); } } else { user.getServer().dispatchCommand(event.getPlayer(), command); } } }
@EventHandler(priority = EventPriority.LOWEST) public void onEntityDamage(final EntityDamageByEntityEvent event) { final Entity eAttack = event.getDamager(); final Entity eDefend = event.getEntity(); if (eDefend instanceof Player && eAttack instanceof Player) { final User defender = ess.getUser(eDefend); final User attacker = ess.getUser(eAttack); attacker.updateActivity(true); final List<String> commandList = attacker.getPowertool(attacker.getItemInHand()); if (commandList != null && !commandList.isEmpty()) { for (String command : commandList) { if (command != null && !command.isEmpty()) { attacker.getServer().dispatchCommand(attacker, command.replaceAll("\\{player\\}", defender.getName())); event.setCancelled(true); return; } } } } else if (eDefend instanceof Animals && eAttack instanceof Player) { final User player = ess.getUser(eAttack); final ItemStack hand = player.getItemInHand(); if (hand != null && hand.getType() == Material.MILK_BUCKET) { ((Animals)eDefend).setAge(-24000); hand.setType(Material.BUCKET); player.setItemInHand(hand); player.updateInventory(); event.setCancelled(true); } } }