diff --git a/src/main/java/com/songoda/ultimatestacker/listeners/DeathListeners.java b/src/main/java/com/songoda/ultimatestacker/listeners/DeathListeners.java index fd95e42..7b57379 100644 --- a/src/main/java/com/songoda/ultimatestacker/listeners/DeathListeners.java +++ b/src/main/java/com/songoda/ultimatestacker/listeners/DeathListeners.java @@ -3,7 +3,11 @@ package com.songoda.ultimatestacker.listeners; import com.songoda.lootables.loot.Drop; import com.songoda.ultimatestacker.UltimateStacker; import com.songoda.ultimatestacker.utils.DropUtils; +import com.songoda.ultimatestacker.utils.ServerVersion; import com.songoda.ultimatestacker.utils.settings.Setting; +import org.bukkit.Material; +import org.bukkit.entity.ChestedHorse; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -12,6 +16,7 @@ import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.inventory.ItemStack; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; public class DeathListeners implements Listener { @@ -33,7 +38,11 @@ public class DeathListeners implements Listener { for (ItemStack item : event.getDrops()) drops.add(new Drop(item)); } - event.getDrops().clear(); + System.out.println(event.getDrops()); + for (ItemStack item : new ArrayList<>(event.getDrops())) { + if (!shouldDrop(event.getEntity(), item.getType())) + event.getDrops().remove(item); + } if (instance.getEntityStackManager().isStacked(event.getEntity())) instance.getEntityStackManager().getStack(event.getEntity()) @@ -41,4 +50,51 @@ public class DeathListeners implements Listener { else DropUtils.processStackedDrop(event.getEntity(), drops); } + + private boolean shouldDrop(LivingEntity entity, Material material) { + if (entity.getEquipment() != null && entity.getEquipment().getArmorContents().length != 0) { + List items = new ArrayList<>(Arrays.asList(entity.getEquipment().getArmorContents())); + items.add(entity.getEquipment().getItemInHand()); + if (instance.isServerVersionAtLeast(ServerVersion.V1_9)) + items.add(entity.getEquipment().getItemInOffHand()); + for (ItemStack item : items) { + if (item.getType() == material) + return true; + } + } + if (instance.isServerVersionAtLeast(ServerVersion.V1_11) && entity instanceof ChestedHorse) { + if (((ChestedHorse) entity).getInventory().contains(material)) + return true; + } + + switch (material.name()) { + case "SADDLE": + return !entity.getType().name().equals("RAVAGER"); + case "DIAMOND_HORSE_ARMOR": + case "GOLDEN_HORSE_ARMOR": + case "IRON_HORSE_ARMOR": + case "LEATHER_HORSE_ARMOR": + case "CYAN_CARPET": + case "BLACK_CARPET": + case "BLUE_CARPET": + case "BROWN_CARPET": + case "GRAY_CARPET": + case "GREEN_CARPET": + case "LIGHT_BLUE_CARPET": + case "LIGHT_GRAY_CARPET": + case "LIME_CARPET": + case "MAGENTA_CARPET": + case "ORANGE_CARPET": + case "PINK_CARPET": + case "PURPLE_CARPET": + case "RED_CARPET": + case "WHITE_CARPET": + case "YELLOW_CARPET": + case "CARPET": + case "CHEST": + return true; + default: + return false; + } + } } diff --git a/src/main/java/com/songoda/ultimatestacker/lootables/LootablesManager.java b/src/main/java/com/songoda/ultimatestacker/lootables/LootablesManager.java index 4e1112d..dc6d4ec 100644 --- a/src/main/java/com/songoda/ultimatestacker/lootables/LootablesManager.java +++ b/src/main/java/com/songoda/ultimatestacker/lootables/LootablesManager.java @@ -197,10 +197,6 @@ public class LootablesManager { new LootBuilder() .setMaterial(Material.GOLD_INGOT) .setChance(5) - .addOnlyDropFors(EntityType.PLAYER).build(), - new LootBuilder() - .setMaterial(Material.TRIDENT) - .setChance(1) .addOnlyDropFors(EntityType.PLAYER).build())); }