Example #1
0
  @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. :(");
  }
 @Override
 public void run() {
   plugin.interactSpawnContainerController().tick();
 }