mobs will now drop held items correctly while custom drops are enabled.

This commit is contained in:
Brianna 2019-08-29 21:10:13 -04:00
parent 44be74c2e3
commit 6af0f05dad
2 changed files with 57 additions and 5 deletions

View File

@ -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<ItemStack> 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;
}
}
}

View File

@ -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()));
}