mirror of
https://github.com/songoda/UltimateStacker.git
synced 2024-11-27 12:35:17 +01:00
Redid drop system to be compatible with drop manipulating plugins.
This commit is contained in:
parent
fe21f02b8c
commit
67a57a1001
@ -15,6 +15,7 @@ import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.ExperienceOrb;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
|
||||
@ -108,7 +109,7 @@ public class EntityStack {
|
||||
return null;
|
||||
}
|
||||
|
||||
private void handleWholeStackDeath(LivingEntity killed, List<Drop> drops, boolean custom, int droppedExp) {
|
||||
private void handleWholeStackDeath(LivingEntity killed, List<Drop> drops, boolean custom, int droppedExp, EntityDeathEvent event) {
|
||||
Location killedLocation = killed.getLocation();
|
||||
List<Drop> preStackedDrops = new ArrayList<>();
|
||||
for (int i = 1; i < amount; i++) {
|
||||
@ -124,7 +125,7 @@ public class EntityStack {
|
||||
preStackedDrops.addAll(drops);
|
||||
}
|
||||
if (!preStackedDrops.isEmpty())
|
||||
DropUtils.processStackedDrop(killed, preStackedDrops);
|
||||
DropUtils.processStackedDrop(killed, preStackedDrops, event);
|
||||
|
||||
if (droppedExp > 0)
|
||||
killedLocation.getWorld().spawn(killedLocation, ExperienceOrb.class).setExperience(droppedExp * amount);
|
||||
@ -133,7 +134,7 @@ public class EntityStack {
|
||||
UltimateStacker.getInstance().addExp(killed.getKiller(), this);
|
||||
}
|
||||
|
||||
private void handleSingleStackDeath(LivingEntity killed, List<Drop> drops) {
|
||||
private void handleSingleStackDeath(LivingEntity killed, List<Drop> drops, EntityDeathEvent event) {
|
||||
EntityStackManager stackManager = plugin.getEntityStackManager();
|
||||
LivingEntity newEntity = plugin.getEntityUtils().newEntity(killed);
|
||||
|
||||
@ -153,7 +154,7 @@ public class EntityStack {
|
||||
newEntity.setMetadata(entityMetadataKey, new FixedMetadataValue(UltimateStacker.getInstance(), true));
|
||||
}
|
||||
|
||||
DropUtils.processStackedDrop(killed, drops);
|
||||
DropUtils.processStackedDrop(killed, drops, event);
|
||||
|
||||
EntityStack entityStack = stackManager.updateStack(killed, newEntity);
|
||||
|
||||
@ -166,7 +167,7 @@ public class EntityStack {
|
||||
}
|
||||
}
|
||||
|
||||
public void onDeath(LivingEntity killed, List<Drop> drops, boolean custom, int droppedExp) {
|
||||
public void onDeath(LivingEntity killed, List<Drop> drops, boolean custom, int droppedExp, EntityDeathEvent event) {
|
||||
killed.setCustomName(null);
|
||||
killed.setCustomNameVisible(true);
|
||||
killed.setCustomName(Methods.formatText("&7"));
|
||||
@ -175,7 +176,7 @@ public class EntityStack {
|
||||
|| plugin.getMobFile().getBoolean("Mobs." + killed.getType().name() + ".Kill Whole Stack");
|
||||
|
||||
if (killWholeStack && getAmount() != 1) {
|
||||
handleWholeStackDeath(killed, drops, custom, droppedExp);
|
||||
handleWholeStackDeath(killed, drops, custom, droppedExp, event);
|
||||
} else if (getAmount() != 1) {
|
||||
List<String> reasons = Settings.INSTANT_KILL.getStringList();
|
||||
EntityDamageEvent lastDamageCause = killed.getLastDamageCause();
|
||||
@ -184,11 +185,11 @@ public class EntityStack {
|
||||
EntityDamageEvent.DamageCause cause = lastDamageCause.getCause();
|
||||
for (String s : reasons) {
|
||||
if (!cause.name().equalsIgnoreCase(s)) continue;
|
||||
handleWholeStackDeath(killed, drops, custom, Settings.NO_EXP_INSTANT_KILL.getBoolean() ? 0 : droppedExp);
|
||||
handleWholeStackDeath(killed, drops, custom, Settings.NO_EXP_INSTANT_KILL.getBoolean() ? 0 : droppedExp, event);
|
||||
return;
|
||||
}
|
||||
}
|
||||
handleSingleStackDeath(killed, drops);
|
||||
handleSingleStackDeath(killed, drops, event);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,13 +19,12 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DeathListeners implements Listener {
|
||||
|
||||
@ -43,22 +42,21 @@ public class DeathListeners implements Listener {
|
||||
|| event.getEntityType() == EntityType.ARMOR_STAND) return;
|
||||
|
||||
boolean custom = Settings.CUSTOM_DROPS.getBoolean();
|
||||
List<Drop> drops = custom ? instance.getLootablesManager().getDrops(event.getEntity()) : new ArrayList<>();
|
||||
List<Drop> drops = custom ? instance.getLootablesManager().getDrops(event.getEntity())
|
||||
: event.getDrops().stream().map(Drop::new).collect(Collectors.toList());
|
||||
|
||||
if (!custom) {
|
||||
for (ItemStack item : event.getDrops())
|
||||
drops.add(new Drop(item));
|
||||
}
|
||||
for (ItemStack item : new ArrayList<>(event.getDrops())) {
|
||||
if (!shouldDrop(event.getEntity(), item.getType()))
|
||||
event.getDrops().remove(item);
|
||||
if (custom) {
|
||||
for (ItemStack item : new ArrayList<>(event.getDrops())) {
|
||||
if (shouldDrop(event.getEntity(), item.getType()))
|
||||
drops.add(new Drop(item));
|
||||
}
|
||||
}
|
||||
|
||||
if (instance.getEntityStackManager().isStacked(event.getEntity()))
|
||||
instance.getEntityStackManager().getStack(event.getEntity())
|
||||
.onDeath(event.getEntity(), drops, custom, event.getDroppedExp());
|
||||
.onDeath(event.getEntity(), drops, custom, event.getDroppedExp(), event);
|
||||
else
|
||||
DropUtils.processStackedDrop(event.getEntity(), drops);
|
||||
DropUtils.processStackedDrop(event.getEntity(), drops, event);
|
||||
}
|
||||
|
||||
private boolean shouldDrop(LivingEntity entity, Material material) {
|
||||
@ -128,7 +126,7 @@ public class DeathListeners implements Listener {
|
||||
if (checkUnbreakingChance(unbreakingLevel))
|
||||
actualDamage++;
|
||||
|
||||
tool.setDurability((short)(tool.getDurability() + actualDamage));
|
||||
tool.setDurability((short) (tool.getDurability() + actualDamage));
|
||||
|
||||
if (!this.hasEnoughDurability(tool, 1))
|
||||
player.getInventory().setItemInHand(null);
|
||||
|
@ -3,24 +3,15 @@ package com.songoda.ultimatestacker.utils;
|
||||
import com.songoda.lootables.loot.Drop;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class DropUtils {
|
||||
|
||||
public static void processDrop(LivingEntity entity, Drop drop) {
|
||||
if (drop == null) return;
|
||||
|
||||
if (drop.getItemStack() != null)
|
||||
dropItems(entity, Collections.singletonList(drop.getItemStack()));
|
||||
if (drop.getCommand() != null)
|
||||
runCommands(entity, Collections.singletonList(drop.getCommand()));
|
||||
}
|
||||
|
||||
public static void processStackedDrop(LivingEntity entity, List<Drop> drops) {
|
||||
public static void processStackedDrop(LivingEntity entity, List<Drop> drops, EntityDeathEvent event) {
|
||||
List<ItemStack> items = new ArrayList<>();
|
||||
List<String> commands = new ArrayList<>();
|
||||
for (Drop drop : drops) {
|
||||
@ -44,14 +35,15 @@ public class DropUtils {
|
||||
commands.add(drop.getCommand());
|
||||
}
|
||||
if (!items.isEmpty())
|
||||
dropItems(entity, items);
|
||||
dropItems(items, event);
|
||||
else if (!commands.isEmpty())
|
||||
runCommands(entity, commands);
|
||||
}
|
||||
|
||||
private static void dropItems(LivingEntity entity, List<ItemStack> items) {
|
||||
private static void dropItems(List<ItemStack> items, EntityDeathEvent event) {
|
||||
event.getDrops().clear();
|
||||
for (ItemStack item : items)
|
||||
entity.getWorld().dropItemNaturally(entity.getLocation(), item);
|
||||
event.getDrops().add(item);
|
||||
}
|
||||
|
||||
private static void runCommands(LivingEntity entity, List<String> commands) {
|
||||
|
Loading…
Reference in New Issue
Block a user