/** * saves the PlayerInventory to his deathChest returns an empty list if player has no Permission * or no DeathChest exists for the player * * @param player * @return the list of Items saved */ private LinkedList<ItemStack> saveToDeathChest(Player player) { LinkedList<ItemStack> emptyReturnList = new LinkedList<ItemStack>(); if (!simplePermissionUse(player)) return emptyReturnList; ChestContainer container = plugin.getChestContainer(); if (!container.checkPlayerHasChest(player.getWorld(), player)) { return emptyReturnList; } int maxTransferItems = plugin.getChestContainer().getMaxTransferLimit(player); if (maxTransferItems <= 0) return emptyReturnList; ChestContainer chestContainer = container.getChestOfPlayer(player.getWorld(), player); ChestPosition chestPos = (ChestPosition) chestContainer; Location chestLocation = chestPos.getLocation(); Block chestBlock = chestLocation.getBlock(); if (chestBlock.getType() != Material.CHEST) { player.sendMessage( ChatColor.RED + "No chest found at Position: " + "X: " + chestLocation.getBlockX() + "Y: " + chestLocation.getBlockY() + "Z: " + chestLocation.getBlockZ()); return emptyReturnList; } double multiplicator = plugin.getConfigManager().getEXPMulti(); int totalExperience = (int) (player.getTotalExperience() * multiplicator); chestPos.addEXP(totalExperience); if (multiplicator != 0) player.setTotalExperience(0); LinkedList<ItemStack> toRemove = copyInventoryToChest((Chest) chestBlock.getState(), false, player); player.sendMessage( ChatColor.GREEN + "Your inventory was stored in your DeathChest on world: " + chestLocation.getWorld().getName() + "."); return toRemove; }
@EventHandler public void onPlayerDeath(PlayerDeathEvent event) { if (plugin.isBattleNight(event.getEntity())) return; boolean filledDeathChest = false; boolean filledSpawnChest = false; int originalDrops = event.getDrops().size(); if (event.getDrops().isEmpty() && event.getDroppedExp() == 0) return; Player player = (Player) event.getEntity(); int exp = player.getTotalExperience(); LinkedList<ItemStack> toRemove = saveToDeathChest(player); filledDeathChest = !toRemove.isEmpty(); if (exp != player.getTotalExperience()) { event.setDroppedExp(0); } for (ItemStack item : toRemove) event.getDrops().remove(item); if (event.getDrops().isEmpty() && (event.getDroppedExp() == 0 || plugin.getConfigManager().getEXPMulti() == 0)) return; if (!event.getDrops().isEmpty() || player.getTotalExperience() != 0) { toRemove = plugin.interactSpawnContainerController().createSpawnContainer(player); if (plugin.getConfigManager().getSpawnContainerUsage().equals(SpawnSign.class) && player.getTotalExperience() != exp) event.setDroppedExp(0); if (toRemove != null) { filledSpawnChest = !toRemove.isEmpty(); for (ItemStack item : toRemove) event.getDrops().remove(item); } } if (event.getDrops().size() > 0 && filledDeathChest) { int maxTransfer = plugin.getChestContainer().getMaxTransferLimit(player); if (originalDrops > maxTransfer) player.sendMessage( ChatColor.RED + "Only " + maxTransfer + " items could be transfered. The rest is dropped at your death location."); else player.sendMessage( ChatColor.RED + "Your total inventory did not fit in the box. The rest items were dropped at your death location."); } if (!filledDeathChest && !filledSpawnChest && simplePermissionUse(player)) player.sendMessage(ChatColor.RED + "You don't have a Chest set yet. Sorry for you. :("); }