Performance boost.

This commit is contained in:
Brianna 2019-07-31 00:29:10 -04:00
parent 40c95c6936
commit b5c82f4e11
9 changed files with 481 additions and 475 deletions

View File

@ -16,10 +16,7 @@ import com.songoda.ultimatestacker.storage.StorageRow;
import com.songoda.ultimatestacker.storage.types.StorageMysql;
import com.songoda.ultimatestacker.storage.types.StorageYaml;
import com.songoda.ultimatestacker.tasks.StackingTask;
import com.songoda.ultimatestacker.utils.ConfigWrapper;
import com.songoda.ultimatestacker.utils.Methods;
import com.songoda.ultimatestacker.utils.Metrics;
import com.songoda.ultimatestacker.utils.ServerVersion;
import com.songoda.ultimatestacker.utils.*;
import com.songoda.ultimatestacker.utils.locale.Locale;
import com.songoda.ultimatestacker.utils.settings.Setting;
import com.songoda.ultimatestacker.utils.settings.SettingsManager;
@ -56,6 +53,8 @@ public class UltimateStacker extends JavaPlugin {
private StackingTask stackingTask;
private Hologram hologram;
private EntityUtils entityUtils;
private List<StackerHook> stackerHooks = new ArrayList<>();
private ServerVersion serverVersion = ServerVersion.fromPackageName(Bukkit.getServer().getClass().getPackage().getName());
@ -92,6 +91,8 @@ public class UltimateStacker extends JavaPlugin {
this.commandManager = new CommandManager(this);
this.entityUtils = new EntityUtils();
this.lootablesManager = new LootablesManager();
this.lootablesManager.createDefaultLootables();
this.getLootablesManager().getLootManager().loadLootables();
@ -220,6 +221,12 @@ public class UltimateStacker extends JavaPlugin {
public void reload() {
this.locale = Locale.getLocale(getConfig().getString("System.Language Mode"));
this.locale.reloadMessages();
this.entityUtils = new EntityUtils();
this.stackingTask.cancel();
this.stackingTask = new StackingTask(this);
this.mobFile = new ConfigWrapper(this, "", "mobs.yml");
this.itemFile = new ConfigWrapper(this, "", "items.yml");
this.spawnerFile = new ConfigWrapper(this, "", "spawners.yml");
@ -290,4 +297,8 @@ public class UltimateStacker extends JavaPlugin {
public ConfigWrapper getSpawnerFile() {
return spawnerFile;
}
public EntityUtils getEntityUtils() {
return entityUtils;
}
}

View File

@ -28,6 +28,7 @@ public class EntityStack {
private int amount;
private Deque<Double> health = new ArrayDeque<>();
UltimateStacker plugin = UltimateStacker.getInstance();
public EntityStack(LivingEntity entity, int amount) {
this(entity.getUniqueId(), amount);
@ -132,16 +133,15 @@ public class EntityStack {
}
private void handleSingleStackDeath(LivingEntity killed) {
UltimateStacker instance = UltimateStacker.getInstance();
EntityStackManager stackManager = instance.getEntityStackManager();
LivingEntity newEntity = Methods.newEntity(killed);
EntityStackManager stackManager = plugin.getEntityStackManager();
LivingEntity newEntity = plugin.getEntityUtils().newEntity(killed);
updateHealth(newEntity);
newEntity.getEquipment().clear();
if (killed.getType() == EntityType.PIG_ZOMBIE)
newEntity.getEquipment().setItemInHand(new ItemStack(instance.isServerVersionAtLeast(ServerVersion.V1_13)
newEntity.getEquipment().setItemInHand(new ItemStack(plugin.isServerVersionAtLeast(ServerVersion.V1_13)
? Material.GOLDEN_SWORD : Material.valueOf("GOLD_SWORD")));
if (Setting.CARRY_OVER_METADATA_ON_DEATH.getBoolean()) {

View File

@ -12,20 +12,16 @@ import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.SheepDyeWoolEvent;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.util.Vector;
import java.util.concurrent.ThreadLocalRandom;
public class InteractListeners implements Listener {
private final UltimateStacker instance;
private final UltimateStacker plugin;
public InteractListeners(UltimateStacker instance) {
this.instance = instance;
public InteractListeners(UltimateStacker plugin) {
this.plugin = plugin;
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
@ -36,11 +32,11 @@ public class InteractListeners implements Listener {
ItemStack item = player.getInventory().getItemInHand();
if (!instance.getEntityStackManager().isStacked(entity)) return;
if (!plugin.getEntityStackManager().isStacked(entity)) return;
if (item.getType() != Material.NAME_TAG && !correctFood(item, entity)) return;
EntityStack stack = instance.getEntityStackManager().getStack(entity);
EntityStack stack = plugin.getEntityStackManager().getStack(entity);
if (stack.getAmount() <= 1
|| item.getType() == Material.NAME_TAG
@ -54,7 +50,7 @@ public class InteractListeners implements Listener {
else if (entity instanceof Ageable && !((Ageable) entity).isAdult())
return;
Methods.splitFromStack(entity);
plugin.getEntityUtils().splitFromStack(entity);
if (item.getType() == Material.NAME_TAG) {
entity.setCustomName(item.getItemMeta().getDisplayName());
@ -63,24 +59,24 @@ public class InteractListeners implements Listener {
&& !((Ageable) entity).isAdult()) {
return;
}
entity.setMetadata("inLove", new FixedMetadataValue(instance, true));
entity.setMetadata("inLove", new FixedMetadataValue(plugin, true));
Bukkit.getScheduler().runTaskLaterAsynchronously(instance, () -> {
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, () -> {
if (entity.isDead()) return;
entity.removeMetadata("inLove", instance);
entity.removeMetadata("inLove", plugin);
}, 20 * 20);
}
}
private boolean correctFood(ItemStack is, Entity entity) {
boolean is13 = instance.isServerVersionAtLeast(ServerVersion.V1_13);
boolean is13 = plugin.isServerVersionAtLeast(ServerVersion.V1_13);
Material type = is.getType();
switch (entity.getType().name()) {
case "COW":
case "SHEEP":
return type == Material.WHEAT;
case "PIG":
return type == Material.CARROT || (instance.isServerVersionAtLeast(ServerVersion.V1_8) && type == Material.BEETROOT) || type == Material.POTATO;
return type == Material.CARROT || (plugin.isServerVersionAtLeast(ServerVersion.V1_8) && type == Material.BEETROOT) || type == Material.POTATO;
case "CHICKEN":
return type == (is13 ? Material.WHEAT_SEEDS : Material.valueOf("SEEDS"))
|| type == Material.MELON_SEEDS

View File

@ -1,12 +1,10 @@
package com.songoda.ultimatestacker.listeners;
import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.entity.EntityStack;
import com.songoda.ultimatestacker.entity.EntityStackManager;
import com.songoda.ultimatestacker.entity.Split;
import com.songoda.ultimatestacker.utils.Methods;
import com.songoda.ultimatestacker.utils.settings.Setting;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
@ -14,16 +12,13 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerShearEntityEvent;
import org.bukkit.util.Vector;
import java.util.concurrent.ThreadLocalRandom;
public class ShearListeners implements Listener {
private UltimateStacker instance;
private UltimateStacker plugin;
public ShearListeners(UltimateStacker instance) {
this.instance = instance;
public ShearListeners(UltimateStacker plugin) {
this.plugin = plugin;
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
@ -31,7 +26,7 @@ public class ShearListeners implements Listener {
Entity entity = event.getEntity();
if (entity.getType() != EntityType.SHEEP && entity.getType() != EntityType.MUSHROOM_COW) return;
EntityStackManager stackManager = instance.getEntityStackManager();
EntityStackManager stackManager = plugin.getEntityStackManager();
if (!stackManager.isStacked(entity)) return;
if (event.getEntity().getType() == EntityType.SHEEP
@ -40,6 +35,6 @@ public class ShearListeners implements Listener {
&& Setting.SPLIT_CHECKS.getStringList().stream().noneMatch(line -> Split.valueOf(line) == Split.MUSHROOM_SHEAR))
return;
Methods.splitFromStack((LivingEntity)entity);
plugin.getEntityUtils().splitFromStack((LivingEntity)entity);
}
}

View File

@ -1,42 +1,33 @@
package com.songoda.ultimatestacker.listeners;
import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.entity.EntityStack;
import com.songoda.ultimatestacker.entity.EntityStackManager;
import com.songoda.ultimatestacker.entity.Split;
import com.songoda.ultimatestacker.utils.Methods;
import com.songoda.ultimatestacker.utils.settings.Setting;
import org.bukkit.Material;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.SheepDyeWoolEvent;
import org.bukkit.event.player.PlayerShearEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Wool;
import org.bukkit.util.Vector;
import java.util.concurrent.ThreadLocalRandom;
public class SheepDyeListeners implements Listener {
private UltimateStacker instance;
private UltimateStacker plugin;
public SheepDyeListeners(UltimateStacker instance) {
this.instance = instance;
public SheepDyeListeners(UltimateStacker plugin) {
this.plugin = plugin;
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onDye(SheepDyeWoolEvent event) {
LivingEntity entity = event.getEntity();
EntityStackManager stackManager = instance.getEntityStackManager();
EntityStackManager stackManager = plugin.getEntityStackManager();
if (!stackManager.isStacked(entity)) return;
if (Setting.SPLIT_CHECKS.getStringList().stream().noneMatch(line -> Split.valueOf(line) == Split.SHEEP_DYE))
return;
Methods.splitFromStack(entity);
plugin.getEntityUtils().splitFromStack(entity);
}
}

View File

@ -3,7 +3,6 @@ package com.songoda.ultimatestacker.listeners;
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.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Tameable;
@ -17,30 +16,30 @@ import java.util.concurrent.ThreadLocalRandom;
public class TameListeners implements Listener {
private UltimateStacker instance;
private UltimateStacker plugin;
public TameListeners(UltimateStacker instance) {
this.instance = instance;
public TameListeners(UltimateStacker plugin) {
this.plugin = plugin;
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onTame(EntityTameEvent event) {
Entity entity = event.getEntity();
EntityStackManager stackManager = instance.getEntityStackManager();
EntityStackManager stackManager = plugin.getEntityStackManager();
if (!stackManager.isStacked(entity)) return;
Tameable tameable = (Tameable) entity;
EntityStack stack = instance.getEntityStackManager().getStack(entity);
EntityStack stack = plugin.getEntityStackManager().getStack(entity);
if (stack.getAmount() <= 1) return;
LivingEntity newEntity = Methods.newEntity((LivingEntity) tameable);
LivingEntity newEntity = plugin.getEntityUtils().newEntity((LivingEntity) tameable);
instance.getEntityStackManager().addStack(new EntityStack(newEntity, stack.getAmount() - 1));
plugin.getEntityStackManager().addStack(new EntityStack(newEntity, stack.getAmount() - 1));
stack.setAmount(1);
instance.getEntityStackManager().removeStack(entity);
plugin.getEntityStackManager().removeStack(entity);
entity.setVelocity(getRandomVector());
}

View File

@ -22,7 +22,7 @@ import java.util.stream.Collectors;
public class StackingTask extends BukkitRunnable {
private final UltimateStacker instance;
private final UltimateStacker plugin;
private EntityStackManager stackManager;
@ -30,13 +30,15 @@ public class StackingTask extends BukkitRunnable {
private List<UUID> processed = new ArrayList<>();
private int maxEntityStackSize = Setting.MAX_STACK_ENTITIES.getInt();
private int minEntityStackSize = Setting.MIN_STACK_ENTITIES.getInt();
public StackingTask(UltimateStacker instance) {
this.instance = instance;
this.stackManager = instance.getEntityStackManager();
public StackingTask(UltimateStacker plugin) {
this.plugin = plugin;
this.stackManager = plugin.getEntityStackManager();
// Start stacking task.
runTaskTimer(instance, 0, Setting.STACK_SEARCH_TICK_SPEED.getInt());
runTaskTimer(plugin, 0, Setting.STACK_SEARCH_TICK_SPEED.getInt());
}
@Override
@ -106,7 +108,7 @@ public class StackingTask extends BukkitRunnable {
private void processEntity(LivingEntity livingEntity) {
// Get the stack from the entity. It should be noted that this value will
// be null if our entity is not a stack.
EntityStack stack = instance.getEntityStackManager().getStack(livingEntity);
EntityStack stack = plugin.getEntityStackManager().getStack(livingEntity);
// Is this entity stacked?
boolean isStack = stack != null;
@ -122,13 +124,11 @@ public class StackingTask extends BukkitRunnable {
|| !configurationSection.getBoolean("Mobs." + livingEntity.getType().name() + ".Enabled"))
return;
// Get the minimum stack size.
int minEntityStackSize = Setting.MIN_STACK_ENTITIES.getInt();
// Get the maximum stack size for this entity.
int maxEntityStackSize = getEntityStackSize(livingEntity);
// Get similar entities around our entity and make sure those entities are both compatible and stackable.
List<LivingEntity> stackableFriends = Methods.getSimilarEntitiesAroundEntity(livingEntity)
List<LivingEntity> stackableFriends = plugin.getEntityUtils().getSimilarEntitiesAroundEntity(livingEntity)
.stream().filter(this::isEntityStackable).collect(Collectors.toList());
// Loop through our similar stackable entities.
@ -254,8 +254,8 @@ public class StackingTask extends BukkitRunnable {
if (stackSize <= maxEntityStackAmount) return false;
for (int i = stackSize; i > 0; i -= maxEntityStackAmount)
this.processed.add(instance.getEntityStackManager()
.addStack(Methods.newEntity(livingEntity), i > maxEntityStackAmount ? maxEntityStackAmount : i).getEntityUniqueId());
this.processed.add(plugin.getEntityStackManager()
.addStack(plugin.getEntityUtils().newEntity(livingEntity), Math.min(i, maxEntityStackAmount)).getEntityUniqueId());
// Remove our entities stack from the stack manager.
stackManager.removeStack(livingEntity);
@ -273,7 +273,6 @@ public class StackingTask extends BukkitRunnable {
}
private int getEntityStackSize(LivingEntity initialEntity) {
int maxEntityStackSize = Setting.MAX_STACK_ENTITIES.getInt();
if (configurationSection.getInt("Mobs." + initialEntity.getType().name() + ".Max Stack Size") != -1)
maxEntityStackSize = configurationSection.getInt("Mobs." + initialEntity.getType().name() + ".Max Stack Size");
return maxEntityStackSize;

View File

@ -0,0 +1,421 @@
package com.songoda.ultimatestacker.utils;
import com.google.common.collect.Lists;
import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.entity.Check;
import com.songoda.ultimatestacker.entity.EntityStack;
import com.songoda.ultimatestacker.utils.settings.Setting;
import org.bukkit.Axis;
import org.bukkit.Chunk;
import org.bukkit.entity.*;
import org.bukkit.util.BoundingBox;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
public class EntityUtils {
private List<String> checks = Setting.STACK_CHECKS.getStringList();
private boolean stackFlyingDown = Setting.ONLY_STACK_FLYING_DOWN.getBoolean();
private boolean keepFire = Setting.KEEP_FIRE.getBoolean();
private boolean keepPotion = Setting.KEEP_POTION.getBoolean();
private int searchRadius = Setting.SEARCH_RADIUS.getInt();
public LivingEntity newEntity(LivingEntity toClone) {
LivingEntity newEntity = (LivingEntity) toClone.getWorld().spawnEntity(toClone.getLocation(), toClone.getType());
newEntity.setVelocity(toClone.getVelocity());
for (String checkStr : checks) {
Check check = Check.valueOf(checkStr);
switch (check) {
case AGE: {
if (!(toClone instanceof Ageable) || ((Ageable) toClone).isAdult()) break;
((Ageable) newEntity).setBaby();
break;
}
case NERFED: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_9)) break;
if (!toClone.hasAI()) newEntity.setAI(false);
}
case IS_TAMED: {
if (!(toClone instanceof Tameable)) break;
((Tameable) newEntity).setTamed(((Tameable) toClone).isTamed());
}
case ANIMAL_OWNER: {
if (!(toClone instanceof Tameable)) break;
((Tameable) newEntity).setOwner(((Tameable) toClone).getOwner());
}
case SKELETON_TYPE: {
if (!(toClone instanceof Skeleton)
|| UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_12)) break;
((Skeleton) newEntity).setSkeletonType(((Skeleton) toClone).getSkeletonType());
break;
}
case SHEEP_COLOR: {
if (!(toClone instanceof Sheep)) break;
((Sheep) newEntity).setColor(((Sheep) toClone).getColor());
break;
}
case SHEEP_SHEERED: {
if (!(toClone instanceof Sheep)) break;
((Sheep) newEntity).setSheared(((Sheep) toClone).isSheared());
break;
}
case LLAMA_COLOR: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_11)
|| !(toClone instanceof Llama)) break;
((Llama) newEntity).setColor(((Llama) toClone).getColor());
break;
}
case LLAMA_STRENGTH: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_11)
|| !(toClone instanceof Llama)) break;
((Llama) newEntity).setStrength(((Llama) toClone).getStrength());
break;
}
case VILLAGER_PROFESSION: {
if (!(toClone instanceof Villager)) break;
((Villager) newEntity).setProfession(((Villager) toClone).getProfession());
break;
}
case SLIME_SIZE: {
if (!(toClone instanceof Slime)) break;
((Slime) newEntity).setSize(((Slime) toClone).getSize());
break;
}
case HORSE_JUMP: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_11)
|| !(toClone instanceof AbstractHorse)) break;
((AbstractHorse) newEntity).setJumpStrength(((AbstractHorse) toClone).getJumpStrength());
break;
}
case HORSE_COLOR: {
if (!(toClone instanceof Horse)) break;
((Horse) newEntity).setColor(((Horse) toClone).getColor());
break;
}
case HORSE_STYLE: {
if (!(toClone instanceof Horse)) break;
((Horse) newEntity).setStyle(((Horse) toClone).getStyle());
break;
}
case ZOMBIE_BABY: {
if (!(toClone instanceof Zombie)) break;
((Zombie) newEntity).setBaby(((Zombie) toClone).isBaby());
break;
}
case WOLF_COLLAR_COLOR: {
if (!(toClone instanceof Wolf)) break;
((Wolf) newEntity).setCollarColor(((Wolf) toClone).getCollarColor());
break;
}
case OCELOT_TYPE: {
if (!(toClone instanceof Ocelot)
|| UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_14)) break;
((Ocelot) newEntity).setCatType(((Ocelot) toClone).getCatType());
}
case CAT_TYPE: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_14)
|| !(toClone instanceof Cat)) break;
((Cat) newEntity).setCatType(((Cat) toClone).getCatType());
break;
}
case RABBIT_TYPE: {
if (!(toClone instanceof Rabbit)) break;
((Rabbit) newEntity).setRabbitType(((Rabbit) toClone).getRabbitType());
break;
}
case PARROT_TYPE: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_12)
|| !(toClone instanceof Parrot)) break;
((Parrot) newEntity).setVariant(((Parrot) toClone).getVariant());
break;
}
case PUFFERFISH_STATE: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_13)
|| !(toClone instanceof PufferFish)) break;
((PufferFish) newEntity).setPuffState(((PufferFish) toClone).getPuffState());
break;
}
case TROPICALFISH_PATTERN: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_13)
|| !(toClone instanceof TropicalFish)) break;
((TropicalFish) newEntity).setPattern(((TropicalFish) toClone).getPattern());
break;
}
case TROPICALFISH_PATTERN_COLOR: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_13)
|| !(toClone instanceof TropicalFish)) break;
((TropicalFish) newEntity).setPatternColor(((TropicalFish) toClone).getPatternColor());
break;
}
case TROPICALFISH_BODY_COLOR: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_13)
|| !(toClone instanceof TropicalFish)) break;
((TropicalFish) newEntity).setBodyColor(((TropicalFish) toClone).getBodyColor());
break;
}
case PHANTOM_SIZE: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_13)
|| !(toClone instanceof Phantom)) break;
((Phantom) newEntity).setSize(((Phantom) toClone).getSize());
break;
}
}
}
if (keepFire)
newEntity.setFireTicks(toClone.getFireTicks());
if (keepPotion)
newEntity.addPotionEffects(toClone.getActivePotionEffects());
return newEntity;
}
public List<LivingEntity> getSimilarEntitiesAroundEntity(LivingEntity initalEntity) {
//Create a list of all entities around the initial entity of the same type.
List<LivingEntity> entityList = initalEntity.getNearbyEntities(searchRadius, searchRadius, searchRadius)
.stream().filter(entity -> entity.getType() == initalEntity.getType() && entity != initalEntity)
.map(entity -> (LivingEntity) entity).collect(Collectors.toList());
if (stackFlyingDown && Methods.canFly(initalEntity))
entityList.removeIf(entity -> entity.getLocation().getY() > initalEntity.getLocation().getY());
for (String checkStr : checks) {
Check check = Check.valueOf(checkStr);
switch (check) {
case SPAWN_REASON: {
if (initalEntity.hasMetadata("US_REASON"))
entityList.removeIf(entity -> entity.hasMetadata("US_REASON") && !entity.getMetadata("US_REASON").get(0).asString().equals("US_REASON"));
}
case AGE: {
if (!(initalEntity instanceof Ageable)) break;
if (((Ageable) initalEntity).isAdult()) {
entityList.removeIf(entity -> !((Ageable) entity).isAdult());
} else {
entityList.removeIf(entity -> ((Ageable) entity).isAdult());
}
break;
}
case NERFED: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_9)) break;
entityList.removeIf(entity -> entity.hasAI() != initalEntity.hasAI());
}
case IS_TAMED: {
if (!(initalEntity instanceof Tameable)) break;
entityList.removeIf(entity -> ((Tameable) entity).isTamed());
}
case ANIMAL_OWNER: {
if (!(initalEntity instanceof Tameable)) break;
Tameable tameable = ((Tameable) initalEntity);
entityList.removeIf(entity -> ((Tameable) entity).getOwner() != tameable.getOwner());
}
case PIG_SADDLE: {
if (!(initalEntity instanceof Pig)) break;
entityList.removeIf(entity -> ((Pig) entity).hasSaddle());
break;
}
case SKELETON_TYPE: {
if (!(initalEntity instanceof Skeleton)) break;
Skeleton skeleton = (Skeleton) initalEntity;
entityList.removeIf(entity -> ((Skeleton) entity).getSkeletonType() != skeleton.getSkeletonType());
break;
}
case SHEEP_COLOR: {
if (!(initalEntity instanceof Sheep)) break;
Sheep sheep = ((Sheep) initalEntity);
entityList.removeIf(entity -> ((Sheep) entity).getColor() != sheep.getColor());
break;
}
case SHEEP_SHEERED: {
if (!(initalEntity instanceof Sheep)) break;
Sheep sheep = ((Sheep) initalEntity);
if (sheep.isSheared()) {
entityList.removeIf(entity -> !((Sheep) entity).isSheared());
} else {
entityList.removeIf(entity -> ((Sheep) entity).isSheared());
}
break;
}
case LLAMA_COLOR: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_11)
|| !(initalEntity instanceof Llama)) break;
Llama llama = ((Llama) initalEntity);
entityList.removeIf(entity -> ((Llama) entity).getColor() != llama.getColor());
break;
}
case LLAMA_STRENGTH: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_11)
|| !(initalEntity instanceof Llama)) break;
Llama llama = ((Llama) initalEntity);
entityList.removeIf(entity -> ((Llama) entity).getStrength() != llama.getStrength());
break;
}
case VILLAGER_PROFESSION: {
if (!(initalEntity instanceof Villager)) break;
Villager villager = ((Villager) initalEntity);
entityList.removeIf(entity -> ((Villager) entity).getProfession() != villager.getProfession());
break;
}
case SLIME_SIZE: {
if (!(initalEntity instanceof Slime)) break;
Slime slime = ((Slime) initalEntity);
entityList.removeIf(entity -> ((Slime) entity).getSize() != slime.getSize());
break;
}
case HORSE_CARRYING_CHEST: {
if (UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_11)) {
if (!(initalEntity instanceof ChestedHorse)) break;
entityList.removeIf(entity -> ((ChestedHorse) entity).isCarryingChest());
} else {
if (!(initalEntity instanceof Horse)) break;
entityList.removeIf(entity -> ((Horse) entity).isCarryingChest());
}
break;
}
case HORSE_HAS_ARMOR: {
if (!(initalEntity instanceof Horse)) break;
entityList.removeIf(entity -> ((Horse) entity).getInventory().getArmor() != null);
break;
}
case HORSE_HAS_SADDLE: {
if (UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_13)
&& initalEntity instanceof AbstractHorse) {
entityList.removeIf(entity -> ((AbstractHorse) entity).getInventory().getSaddle() != null);
break;
}
if (!(initalEntity instanceof Horse)) break;
entityList.removeIf(entity -> ((Horse) entity).getInventory().getSaddle() != null);
break;
}
case HORSE_JUMP: {
if (UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_11)) {
if (!(initalEntity instanceof AbstractHorse)) break;
AbstractHorse horse = ((AbstractHorse) initalEntity);
entityList.removeIf(entity -> ((AbstractHorse) entity).getJumpStrength() != horse.getJumpStrength());
} else {
if (!(initalEntity instanceof Horse)) break;
Horse horse = ((Horse) initalEntity);
entityList.removeIf(entity -> ((Horse) entity).getJumpStrength() != horse.getJumpStrength());
}
break;
}
case HORSE_COLOR: {
if (!(initalEntity instanceof Horse)) break;
Horse horse = ((Horse) initalEntity);
entityList.removeIf(entity -> ((Horse) entity).getColor() != horse.getColor());
break;
}
case HORSE_STYLE: {
if (!(initalEntity instanceof Horse)) break;
Horse horse = ((Horse) initalEntity);
entityList.removeIf(entity -> ((Horse) entity).getStyle() != horse.getStyle());
break;
}
case ZOMBIE_BABY: {
if (!(initalEntity instanceof Zombie)) break;
Zombie zombie = (Zombie) initalEntity;
entityList.removeIf(entity -> ((Zombie) entity).isBaby() != zombie.isBaby());
break;
}
case WOLF_COLLAR_COLOR: {
if (!(initalEntity instanceof Wolf)) break;
Wolf wolf = (Wolf) initalEntity;
entityList.removeIf(entity -> ((Wolf) entity).getCollarColor() != wolf.getCollarColor());
break;
}
case OCELOT_TYPE: {
if (!(initalEntity instanceof Ocelot)) break;
Ocelot ocelot = (Ocelot) initalEntity;
entityList.removeIf(entity -> ((Ocelot) entity).getCatType() != ocelot.getCatType());
}
case CAT_TYPE: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_14)
|| !(initalEntity instanceof Cat)) break;
Cat cat = (Cat) initalEntity;
entityList.removeIf(entity -> ((Cat) entity).getCatType() != cat.getCatType());
break;
}
case RABBIT_TYPE: {
if (!(initalEntity instanceof Rabbit)) break;
Rabbit rabbit = (Rabbit) initalEntity;
entityList.removeIf(entity -> ((Rabbit) entity).getRabbitType() != rabbit.getRabbitType());
break;
}
case PARROT_TYPE: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_12)
|| !(initalEntity instanceof Parrot)) break;
Parrot parrot = (Parrot) initalEntity;
entityList.removeIf(entity -> ((Parrot) entity).getVariant() != parrot.getVariant());
break;
}
case PUFFERFISH_STATE: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_13)
|| !(initalEntity instanceof PufferFish)) break;
PufferFish pufferFish = (PufferFish) initalEntity;
entityList.removeIf(entity -> ((PufferFish) entity).getPuffState() != pufferFish.getPuffState());
break;
}
case TROPICALFISH_PATTERN: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_13)
|| !(initalEntity instanceof TropicalFish)) break;
TropicalFish tropicalFish = (TropicalFish) initalEntity;
entityList.removeIf(entity -> ((TropicalFish) entity).getPattern() != tropicalFish.getPattern());
break;
}
case TROPICALFISH_PATTERN_COLOR: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_13)
|| !(initalEntity instanceof TropicalFish)) break;
TropicalFish tropicalFish = (TropicalFish) initalEntity;
entityList.removeIf(entity -> ((TropicalFish) entity).getPatternColor() != tropicalFish.getPatternColor());
break;
}
case TROPICALFISH_BODY_COLOR: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_13)
|| !(initalEntity instanceof TropicalFish)) break;
TropicalFish tropicalFish = (TropicalFish) initalEntity;
entityList.removeIf(entity -> ((TropicalFish) entity).getBodyColor() != tropicalFish.getBodyColor());
break;
}
case PHANTOM_SIZE: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_13)
|| !(initalEntity instanceof Phantom)) break;
Phantom phantom = (Phantom) initalEntity;
entityList.removeIf(entity -> ((Phantom) entity).getSize() != phantom.getSize());
break;
}
}
}
if (initalEntity.hasMetadata("breedCooldown")) {
entityList.removeIf(entity -> !entity.hasMetadata("breedCooldown"));
}
return entityList;
}
public void splitFromStack(LivingEntity entity) {
UltimateStacker instance = UltimateStacker.getInstance();
EntityStack stack = instance.getEntityStackManager().getStack(entity);
if (stack.getAmount() <= 1) return;
LivingEntity newEntity = newEntity(entity);
int newAmount = stack.getAmount() - 1;
if (newAmount != 1)
instance.getEntityStackManager().addStack(new EntityStack(newEntity, newAmount));
stack.setAmount(1);
instance.getEntityStackManager().removeStack(entity);
entity.setVelocity(Methods.getRandomVector());
}
}

View File

@ -2,8 +2,6 @@ package com.songoda.ultimatestacker.utils;
import com.songoda.lootables.loot.Drop;
import com.songoda.ultimatestacker.UltimateStacker;
import com.songoda.ultimatestacker.entity.Check;
import com.songoda.ultimatestacker.entity.EntityStack;
import com.songoda.ultimatestacker.utils.settings.Setting;
import org.bukkit.*;
import org.bukkit.block.Block;
@ -21,7 +19,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;
public class Methods {
@ -126,410 +123,7 @@ public class Methods {
}
}
public static LivingEntity newEntity(LivingEntity toClone) {
LivingEntity newEntity = (LivingEntity) toClone.getWorld().spawnEntity(toClone.getLocation(), toClone.getType());
newEntity.setVelocity(toClone.getVelocity());
List<String> checks = Setting.STACK_CHECKS.getStringList();
for (String checkStr : checks) {
Check check = Check.valueOf(checkStr);
switch (check) {
case AGE: {
if (!(toClone instanceof Ageable) || ((Ageable) toClone).isAdult()) break;
((Ageable) newEntity).setBaby();
break;
}
case NERFED: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_9)) break;
if (!toClone.hasAI()) newEntity.setAI(false);
}
case IS_TAMED: {
if (!(toClone instanceof Tameable)) break;
((Tameable) newEntity).setTamed(((Tameable) toClone).isTamed());
}
case ANIMAL_OWNER: {
if (!(toClone instanceof Tameable)) break;
((Tameable) newEntity).setOwner(((Tameable) toClone).getOwner());
}
case SKELETON_TYPE: {
if (!(toClone instanceof Skeleton)
|| UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_12)) break;
((Skeleton) newEntity).setSkeletonType(((Skeleton) toClone).getSkeletonType());
break;
}
case SHEEP_COLOR: {
if (!(toClone instanceof Sheep)) break;
((Sheep) newEntity).setColor(((Sheep) toClone).getColor());
break;
}
case SHEEP_SHEERED: {
if (!(toClone instanceof Sheep)) break;
((Sheep) newEntity).setSheared(((Sheep) toClone).isSheared());
break;
}
case LLAMA_COLOR: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_11)
|| !(toClone instanceof Llama)) break;
((Llama) newEntity).setColor(((Llama) toClone).getColor());
break;
}
case LLAMA_STRENGTH: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_11)
|| !(toClone instanceof Llama)) break;
((Llama) newEntity).setStrength(((Llama) toClone).getStrength());
break;
}
case VILLAGER_PROFESSION: {
if (!(toClone instanceof Villager)) break;
((Villager) newEntity).setProfession(((Villager) toClone).getProfession());
break;
}
case SLIME_SIZE: {
if (!(toClone instanceof Slime)) break;
((Slime) newEntity).setSize(((Slime) toClone).getSize());
break;
}
case HORSE_JUMP: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_11)
|| !(toClone instanceof AbstractHorse)) break;
((AbstractHorse) newEntity).setJumpStrength(((AbstractHorse) toClone).getJumpStrength());
break;
}
case HORSE_COLOR: {
if (!(toClone instanceof Horse)) break;
((Horse) newEntity).setColor(((Horse) toClone).getColor());
break;
}
case HORSE_STYLE: {
if (!(toClone instanceof Horse)) break;
((Horse) newEntity).setStyle(((Horse) toClone).getStyle());
break;
}
case ZOMBIE_BABY: {
if (!(toClone instanceof Zombie)) break;
((Zombie) newEntity).setBaby(((Zombie) toClone).isBaby());
break;
}
case WOLF_COLLAR_COLOR: {
if (!(toClone instanceof Wolf)) break;
((Wolf) newEntity).setCollarColor(((Wolf) toClone).getCollarColor());
break;
}
case OCELOT_TYPE: {
if (!(toClone instanceof Ocelot)
|| UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_14)) break;
((Ocelot) newEntity).setCatType(((Ocelot) toClone).getCatType());
}
case CAT_TYPE: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_14)
|| !(toClone instanceof Cat)) break;
((Cat) newEntity).setCatType(((Cat) toClone).getCatType());
break;
}
case RABBIT_TYPE: {
if (!(toClone instanceof Rabbit)) break;
((Rabbit) newEntity).setRabbitType(((Rabbit) toClone).getRabbitType());
break;
}
case PARROT_TYPE: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_12)
|| !(toClone instanceof Parrot)) break;
((Parrot) newEntity).setVariant(((Parrot) toClone).getVariant());
break;
}
case PUFFERFISH_STATE: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_13)
|| !(toClone instanceof PufferFish)) break;
((PufferFish) newEntity).setPuffState(((PufferFish) toClone).getPuffState());
break;
}
case TROPICALFISH_PATTERN: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_13)
|| !(toClone instanceof TropicalFish)) break;
((TropicalFish) newEntity).setPattern(((TropicalFish) toClone).getPattern());
break;
}
case TROPICALFISH_PATTERN_COLOR: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_13)
|| !(toClone instanceof TropicalFish)) break;
((TropicalFish) newEntity).setPatternColor(((TropicalFish) toClone).getPatternColor());
break;
}
case TROPICALFISH_BODY_COLOR: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_13)
|| !(toClone instanceof TropicalFish)) break;
((TropicalFish) newEntity).setBodyColor(((TropicalFish) toClone).getBodyColor());
break;
}
case PHANTOM_SIZE: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_13)
|| !(toClone instanceof Phantom)) break;
((Phantom) newEntity).setSize(((Phantom) toClone).getSize());
break;
}
}
}
if (Setting.KEEP_FIRE.getBoolean())
newEntity.setFireTicks(toClone.getFireTicks());
if (Setting.KEEP_POTION.getBoolean())
newEntity.addPotionEffects(toClone.getActivePotionEffects());
return newEntity;
}
public static List<LivingEntity> getSimilarEntitiesAroundEntity(LivingEntity initalEntity) {
int searchRadius = Setting.SEARCH_RADIUS.getInt();
//Create a list of all entities around the initial entity of the same type.
List<LivingEntity> entityList = initalEntity.getNearbyEntities(searchRadius, searchRadius, searchRadius).stream()
.filter(entity -> entity.getType() == initalEntity.getType() && entity != initalEntity)
.map(entity -> (LivingEntity) entity).collect(Collectors.toList());
List<String> checks = Setting.STACK_CHECKS.getStringList();
if (Setting.ONLY_STACK_FLYING_DOWN.getBoolean() && Methods.canFly(initalEntity))
entityList.removeIf(entity -> entity.getLocation().getY() > initalEntity.getLocation().getY());
for (String checkStr : checks) {
Check check = Check.valueOf(checkStr);
switch (check) {
case SPAWN_REASON: {
if (initalEntity.hasMetadata("US_REASON"))
entityList.removeIf(entity -> entity.hasMetadata("US_REASON") && !entity.getMetadata("US_REASON").get(0).asString().equals("US_REASON"));
}
case AGE: {
if (!(initalEntity instanceof Ageable)) break;
if (((Ageable) initalEntity).isAdult()) {
entityList.removeIf(entity -> !((Ageable) entity).isAdult());
} else {
entityList.removeIf(entity -> ((Ageable) entity).isAdult());
}
break;
}
case NERFED: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_9)) break;
entityList.removeIf(entity -> entity.hasAI() != initalEntity.hasAI());
}
case IS_TAMED: {
if (!(initalEntity instanceof Tameable)) break;
entityList.removeIf(entity -> ((Tameable) entity).isTamed());
}
case ANIMAL_OWNER: {
if (!(initalEntity instanceof Tameable)) break;
Tameable tameable = ((Tameable) initalEntity);
entityList.removeIf(entity -> ((Tameable) entity).getOwner() != tameable.getOwner());
}
case PIG_SADDLE: {
if (!(initalEntity instanceof Pig)) break;
entityList.removeIf(entity -> ((Pig) entity).hasSaddle());
break;
}
case SKELETON_TYPE: {
if (!(initalEntity instanceof Skeleton)) break;
Skeleton skeleton = (Skeleton) initalEntity;
entityList.removeIf(entity -> ((Skeleton) entity).getSkeletonType() != skeleton.getSkeletonType());
break;
}
case SHEEP_COLOR: {
if (!(initalEntity instanceof Sheep)) break;
Sheep sheep = ((Sheep) initalEntity);
entityList.removeIf(entity -> ((Sheep) entity).getColor() != sheep.getColor());
break;
}
case SHEEP_SHEERED: {
if (!(initalEntity instanceof Sheep)) break;
Sheep sheep = ((Sheep) initalEntity);
if (sheep.isSheared()) {
entityList.removeIf(entity -> !((Sheep) entity).isSheared());
} else {
entityList.removeIf(entity -> ((Sheep) entity).isSheared());
}
break;
}
case LLAMA_COLOR: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_11)
|| !(initalEntity instanceof Llama)) break;
Llama llama = ((Llama) initalEntity);
entityList.removeIf(entity -> ((Llama) entity).getColor() != llama.getColor());
break;
}
case LLAMA_STRENGTH: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_11)
|| !(initalEntity instanceof Llama)) break;
Llama llama = ((Llama) initalEntity);
entityList.removeIf(entity -> ((Llama) entity).getStrength() != llama.getStrength());
break;
}
case VILLAGER_PROFESSION: {
if (!(initalEntity instanceof Villager)) break;
Villager villager = ((Villager) initalEntity);
entityList.removeIf(entity -> ((Villager) entity).getProfession() != villager.getProfession());
break;
}
case SLIME_SIZE: {
if (!(initalEntity instanceof Slime)) break;
Slime slime = ((Slime) initalEntity);
entityList.removeIf(entity -> ((Slime) entity).getSize() != slime.getSize());
break;
}
case HORSE_CARRYING_CHEST: {
if (UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_11)) {
if (!(initalEntity instanceof ChestedHorse)) break;
entityList.removeIf(entity -> ((ChestedHorse) entity).isCarryingChest());
} else {
if (!(initalEntity instanceof Horse)) break;
entityList.removeIf(entity -> ((Horse) entity).isCarryingChest());
}
break;
}
case HORSE_HAS_ARMOR: {
if (!(initalEntity instanceof Horse)) break;
entityList.removeIf(entity -> ((Horse) entity).getInventory().getArmor() != null);
break;
}
case HORSE_HAS_SADDLE: {
if (UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_13)
&& initalEntity instanceof AbstractHorse) {
entityList.removeIf(entity -> ((AbstractHorse) entity).getInventory().getSaddle() != null);
break;
}
if (!(initalEntity instanceof Horse)) break;
entityList.removeIf(entity -> ((Horse) entity).getInventory().getSaddle() != null);
break;
}
case HORSE_JUMP: {
if (UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_11)) {
if (!(initalEntity instanceof AbstractHorse)) break;
AbstractHorse horse = ((AbstractHorse) initalEntity);
entityList.removeIf(entity -> ((AbstractHorse) entity).getJumpStrength() != horse.getJumpStrength());
} else {
if (!(initalEntity instanceof Horse)) break;
Horse horse = ((Horse) initalEntity);
entityList.removeIf(entity -> ((Horse) entity).getJumpStrength() != horse.getJumpStrength());
}
break;
}
case HORSE_COLOR: {
if (!(initalEntity instanceof Horse)) break;
Horse horse = ((Horse) initalEntity);
entityList.removeIf(entity -> ((Horse) entity).getColor() != horse.getColor());
break;
}
case HORSE_STYLE: {
if (!(initalEntity instanceof Horse)) break;
Horse horse = ((Horse) initalEntity);
entityList.removeIf(entity -> ((Horse) entity).getStyle() != horse.getStyle());
break;
}
case ZOMBIE_BABY: {
if (!(initalEntity instanceof Zombie)) break;
Zombie zombie = (Zombie) initalEntity;
entityList.removeIf(entity -> ((Zombie) entity).isBaby() != zombie.isBaby());
break;
}
case WOLF_COLLAR_COLOR: {
if (!(initalEntity instanceof Wolf)) break;
Wolf wolf = (Wolf) initalEntity;
entityList.removeIf(entity -> ((Wolf) entity).getCollarColor() != wolf.getCollarColor());
break;
}
case OCELOT_TYPE: {
if (!(initalEntity instanceof Ocelot)) break;
Ocelot ocelot = (Ocelot) initalEntity;
entityList.removeIf(entity -> ((Ocelot) entity).getCatType() != ocelot.getCatType());
}
case CAT_TYPE: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_14)
|| !(initalEntity instanceof Cat)) break;
Cat cat = (Cat) initalEntity;
entityList.removeIf(entity -> ((Cat) entity).getCatType() != cat.getCatType());
break;
}
case RABBIT_TYPE: {
if (!(initalEntity instanceof Rabbit)) break;
Rabbit rabbit = (Rabbit) initalEntity;
entityList.removeIf(entity -> ((Rabbit) entity).getRabbitType() != rabbit.getRabbitType());
break;
}
case PARROT_TYPE: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_12)
|| !(initalEntity instanceof Parrot)) break;
Parrot parrot = (Parrot) initalEntity;
entityList.removeIf(entity -> ((Parrot) entity).getVariant() != parrot.getVariant());
break;
}
case PUFFERFISH_STATE: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_13)
|| !(initalEntity instanceof PufferFish)) break;
PufferFish pufferFish = (PufferFish) initalEntity;
entityList.removeIf(entity -> ((PufferFish) entity).getPuffState() != pufferFish.getPuffState());
break;
}
case TROPICALFISH_PATTERN: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_13)
|| !(initalEntity instanceof TropicalFish)) break;
TropicalFish tropicalFish = (TropicalFish) initalEntity;
entityList.removeIf(entity -> ((TropicalFish) entity).getPattern() != tropicalFish.getPattern());
break;
}
case TROPICALFISH_PATTERN_COLOR: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_13)
|| !(initalEntity instanceof TropicalFish)) break;
TropicalFish tropicalFish = (TropicalFish) initalEntity;
entityList.removeIf(entity -> ((TropicalFish) entity).getPatternColor() != tropicalFish.getPatternColor());
break;
}
case TROPICALFISH_BODY_COLOR: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_13)
|| !(initalEntity instanceof TropicalFish)) break;
TropicalFish tropicalFish = (TropicalFish) initalEntity;
entityList.removeIf(entity -> ((TropicalFish) entity).getBodyColor() != tropicalFish.getBodyColor());
break;
}
case PHANTOM_SIZE: {
if (!UltimateStacker.getInstance().isServerVersionAtLeast(ServerVersion.V1_13)
|| !(initalEntity instanceof Phantom)) break;
Phantom phantom = (Phantom) initalEntity;
entityList.removeIf(entity -> ((Phantom) entity).getSize() != phantom.getSize());
break;
}
}
}
if (initalEntity.hasMetadata("breedCooldown")) {
entityList.removeIf(entity -> !entity.hasMetadata("breedCooldown"));
}
return entityList;
}
public static void splitFromStack(LivingEntity entity) {
UltimateStacker instance = UltimateStacker.getInstance();
EntityStack stack = instance.getEntityStackManager().getStack(entity);
if (stack.getAmount() <= 1) return;
LivingEntity newEntity = Methods.newEntity(entity);
int newAmount = stack.getAmount() - 1;
if (newAmount != 1)
instance.getEntityStackManager().addStack(new EntityStack(newEntity, newAmount));
stack.setAmount(1);
instance.getEntityStackManager().removeStack(entity);
entity.setVelocity(getRandomVector());
}
private static Vector getRandomVector() {
static Vector getRandomVector() {
return new Vector(ThreadLocalRandom.current().nextDouble(-1, 1.01), 0, ThreadLocalRandom.current().nextDouble(-1, 1.01)).normalize().multiply(0.5);
}