@Override public void onPlayerEggThrow(final PlayerEggThrowEvent event) { final User user = ess.getUser(event.getPlayer()); final ItemStack is = new ItemStack(Material.EGG, 1); if (user.hasUnlimited(is)) { user.getInventory().addItem(is); user.updateInventory(); } }
@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); } } }
public static void expandItems(final IEssentials ess, final User user, final List<String> items) throws Exception { try { boolean spew = false; for (String d : items) { final String[] parts = d.split(" "); final String[] item = parts[0].split("[:+',;.]", 2); final int id = Material.getMaterial(Integer.parseInt(item[0])).getId(); final short data = item.length > 1 ? Short.parseShort(item[1]) : 0; final int amount = parts.length > 1 ? Integer.parseInt(parts[1]) : 1; final ItemStack stack = new ItemStack(id, amount, data); if (parts.length > 2) { for (int i = 2; i < parts.length; i++) { final String[] split = parts[i].split("[:+',;.]", 2); if (split.length < 1) { continue; } final Enchantment enchantment = Commandenchant.getEnchantment(split[0], user); int level; if (split.length > 1) { level = Integer.parseInt(split[1]); } else { level = enchantment.getMaxLevel(); } stack.addEnchantment(enchantment, level); } } final Map<Integer, ItemStack> overfilled; if (user.isAuthorized("essentials.oversizedstacks")) { overfilled = InventoryWorkaround.addItem(user.getInventory(), true, ess.getSettings().getOversizedStackSize(), stack); } else { overfilled = InventoryWorkaround.addItem(user.getInventory(), true, new ItemStack(id, amount, data)); } for (ItemStack itemStack : overfilled.values()) { user.getWorld().dropItemNaturally(user.getLocation(), itemStack); spew = true; } } user.updateInventory(); if (spew) { user.sendMessage(_("kitInvFull")); } } catch (Exception e) { user.updateInventory(); throw new Exception(_("kitError2")); } }