mirror of
https://github.com/songoda/UltimateStacker.git
synced 2025-03-01 09:41:03 +01:00
Exploding entities will now respect stack sizes.
This commit is contained in:
parent
f97a9506c1
commit
adc3f9d916
@ -3,6 +3,7 @@ package com.songoda.ultimatestacker.events;
|
||||
import com.songoda.ultimatestacker.UltimateStacker;
|
||||
import com.songoda.ultimatestacker.entity.EntityStack;
|
||||
import com.songoda.ultimatestacker.entity.EntityStackManager;
|
||||
import com.songoda.ultimatestacker.utils.Methods;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -20,51 +21,6 @@ public class DeathListeners implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onEntityDeath(EntityDeathEvent event) {
|
||||
LivingEntity killed = event.getEntity();
|
||||
|
||||
EntityStackManager stackManager = instance.getEntityStackManager();
|
||||
|
||||
if (!stackManager.isStacked(killed)) return;
|
||||
|
||||
killed.setCustomName(null);
|
||||
killed.setCustomNameVisible(false);
|
||||
|
||||
EntityStack stack = stackManager.getStack(killed);
|
||||
|
||||
if (instance.getConfig().getBoolean("Entity.Kill Whole Stack On Death") && stack.getAmount() != 1) {
|
||||
for (int i = 1; i < stack.getAmount(); i++) {
|
||||
for (ItemStack item : event.getDrops()) {
|
||||
killed.getWorld().dropItemNaturally(killed.getLocation(), item);
|
||||
}
|
||||
killed.getWorld().spawn(killed.getLocation(), ExperienceOrb.class).setExperience(event.getDroppedExp());
|
||||
}
|
||||
} else {
|
||||
Entity newEntity = newEntity(killed);
|
||||
stack = stackManager.updateStack(killed, newEntity);
|
||||
|
||||
stack.addAmount(-1);
|
||||
if (stack.getAmount() <= 1) {
|
||||
stackManager.removeStack(newEntity);
|
||||
newEntity.setCustomNameVisible(false);
|
||||
newEntity.setCustomName(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private LivingEntity newEntity(LivingEntity killed) {
|
||||
LivingEntity newEntity = (LivingEntity) killed.getWorld().spawnEntity(killed.getLocation(), killed.getType());
|
||||
newEntity.setVelocity(killed.getVelocity());
|
||||
if (killed instanceof Ageable && !((Ageable) killed).isAdult()) {
|
||||
((Ageable) newEntity).setBaby();
|
||||
} else if (killed instanceof Sheep) {
|
||||
((Sheep) newEntity).setColor(((Sheep) killed).getColor());
|
||||
} else if (killed instanceof Villager) {
|
||||
((Villager) newEntity).setProfession(((Villager) killed).getProfession());
|
||||
}
|
||||
|
||||
newEntity.setFireTicks(killed.getFireTicks());
|
||||
newEntity.addPotionEffects(killed.getActivePotionEffects());
|
||||
|
||||
return newEntity;
|
||||
Methods.onDeath(event.getEntity(), event.getDrops(), event.getDroppedExp());
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
import org.bukkit.entity.Creeper;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -16,6 +17,7 @@ import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class EntityListeners implements Listener {
|
||||
@ -30,6 +32,10 @@ public class EntityListeners implements Listener {
|
||||
public void onBlow(EntityExplodeEvent event) {
|
||||
if (!(event.getEntity() instanceof Creeper) && !(event.getEntity() instanceof TNTPrimed)) return;
|
||||
|
||||
if (event.getEntity() instanceof Creeper) {
|
||||
Methods.onDeath((LivingEntity)event.getEntity(), new ArrayList<>(), 0);
|
||||
}
|
||||
|
||||
List<Block> destroyed = event.blockList();
|
||||
for (Block block : destroyed) {
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.songoda.ultimatestacker.utils;
|
||||
|
||||
import com.songoda.ultimatestacker.UltimateStacker;
|
||||
import com.songoda.ultimatestacker.entity.EntityStack;
|
||||
import com.songoda.ultimatestacker.entity.EntityStackManager;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
@ -16,6 +18,55 @@ import java.util.Map;
|
||||
|
||||
public class Methods {
|
||||
|
||||
public static void onDeath(LivingEntity killed, List<ItemStack> items, int droppedExp) {
|
||||
UltimateStacker instance = UltimateStacker.getInstance();
|
||||
|
||||
EntityStackManager stackManager = instance.getEntityStackManager();
|
||||
|
||||
if (!stackManager.isStacked(killed)) return;
|
||||
|
||||
killed.setCustomName(null);
|
||||
killed.setCustomNameVisible(false);
|
||||
|
||||
EntityStack stack = stackManager.getStack(killed);
|
||||
|
||||
if (instance.getConfig().getBoolean("Entity.Kill Whole Stack On Death") && stack.getAmount() != 1) {
|
||||
for (int i = 1; i < stack.getAmount(); i++) {
|
||||
for (ItemStack item : items) {
|
||||
killed.getWorld().dropItemNaturally(killed.getLocation(), item);
|
||||
}
|
||||
killed.getWorld().spawn(killed.getLocation(), ExperienceOrb.class).setExperience(droppedExp);
|
||||
}
|
||||
} else {
|
||||
Entity newEntity = newEntity(killed);
|
||||
stack = stackManager.updateStack(killed, newEntity);
|
||||
|
||||
stack.addAmount(-1);
|
||||
if (stack.getAmount() <= 1) {
|
||||
stackManager.removeStack(newEntity);
|
||||
newEntity.setCustomNameVisible(false);
|
||||
newEntity.setCustomName(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static LivingEntity newEntity(LivingEntity killed) {
|
||||
LivingEntity newEntity = (LivingEntity) killed.getWorld().spawnEntity(killed.getLocation(), killed.getType());
|
||||
newEntity.setVelocity(killed.getVelocity());
|
||||
if (killed instanceof Ageable && !((Ageable) killed).isAdult()) {
|
||||
((Ageable) newEntity).setBaby();
|
||||
} else if (killed instanceof Sheep) {
|
||||
((Sheep) newEntity).setColor(((Sheep) killed).getColor());
|
||||
} else if (killed instanceof Villager) {
|
||||
((Villager) newEntity).setProfession(((Villager) killed).getProfession());
|
||||
}
|
||||
|
||||
newEntity.setFireTicks(killed.getFireTicks());
|
||||
newEntity.addPotionEffects(killed.getActivePotionEffects());
|
||||
|
||||
return newEntity;
|
||||
}
|
||||
|
||||
public static List<Entity> getSimilarEntitesAroundEntity(Entity initalEntity) {
|
||||
|
||||
//Create a list of all entities around the initial entity.
|
||||
|
Loading…
Reference in New Issue
Block a user