mirror of
https://github.com/songoda/UltimateStacker.git
synced 2024-06-28 23:55:16 +02: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.UltimateStacker;
|
||||||
import com.songoda.ultimatestacker.entity.EntityStack;
|
import com.songoda.ultimatestacker.entity.EntityStack;
|
||||||
import com.songoda.ultimatestacker.entity.EntityStackManager;
|
import com.songoda.ultimatestacker.entity.EntityStackManager;
|
||||||
|
import com.songoda.ultimatestacker.utils.Methods;
|
||||||
import org.bukkit.entity.*;
|
import org.bukkit.entity.*;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
@ -20,51 +21,6 @@ public class DeathListeners implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onEntityDeath(EntityDeathEvent event) {
|
public void onEntityDeath(EntityDeathEvent event) {
|
||||||
LivingEntity killed = event.getEntity();
|
Methods.onDeath(event.getEntity(), event.getDrops(), event.getDroppedExp());
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.CreatureSpawner;
|
import org.bukkit.block.CreatureSpawner;
|
||||||
import org.bukkit.entity.Creeper;
|
import org.bukkit.entity.Creeper;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.TNTPrimed;
|
import org.bukkit.entity.TNTPrimed;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
|
@ -16,6 +17,7 @@ import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class EntityListeners implements Listener {
|
public class EntityListeners implements Listener {
|
||||||
|
@ -30,6 +32,10 @@ public class EntityListeners implements Listener {
|
||||||
public void onBlow(EntityExplodeEvent event) {
|
public void onBlow(EntityExplodeEvent event) {
|
||||||
if (!(event.getEntity() instanceof Creeper) && !(event.getEntity() instanceof TNTPrimed)) return;
|
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();
|
List<Block> destroyed = event.blockList();
|
||||||
for (Block block : destroyed) {
|
for (Block block : destroyed) {
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package com.songoda.ultimatestacker.utils;
|
package com.songoda.ultimatestacker.utils;
|
||||||
|
|
||||||
import com.songoda.ultimatestacker.UltimateStacker;
|
import com.songoda.ultimatestacker.UltimateStacker;
|
||||||
|
import com.songoda.ultimatestacker.entity.EntityStack;
|
||||||
|
import com.songoda.ultimatestacker.entity.EntityStackManager;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.CreatureSpawner;
|
import org.bukkit.block.CreatureSpawner;
|
||||||
|
@ -16,6 +18,55 @@ import java.util.Map;
|
||||||
|
|
||||||
public class Methods {
|
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) {
|
public static List<Entity> getSimilarEntitesAroundEntity(Entity initalEntity) {
|
||||||
|
|
||||||
//Create a list of all entities around the initial entity.
|
//Create a list of all entities around the initial entity.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user