From 12798edacac7c8454cf726cf11a399454ac7e18e Mon Sep 17 00:00:00 2001 From: jascotty2 Date: Sun, 18 Aug 2019 20:48:35 -0500 Subject: [PATCH] add spawn reason filter for stacking --- .../ultimatestacker/tasks/StackingTask.java | 16 +++++++++++----- .../ultimatestacker/utils/settings/Setting.java | 11 +++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/songoda/ultimatestacker/tasks/StackingTask.java b/src/main/java/com/songoda/ultimatestacker/tasks/StackingTask.java index d35eb17..01e6e32 100644 --- a/src/main/java/com/songoda/ultimatestacker/tasks/StackingTask.java +++ b/src/main/java/com/songoda/ultimatestacker/tasks/StackingTask.java @@ -90,12 +90,18 @@ public class StackingTask extends BukkitRunnable { // Make sure the entity is not in love. || entity.hasMetadata("inLove") // Or in breeding cooldown. - || entity.hasMetadata("breedCooldown") + || entity.hasMetadata("breedCooldown")) + return false; - // If only stack from spawners is enabled make sure the entity spawned from a spawner. - || Setting.ONLY_STACK_FROM_SPAWNERS.getBoolean() - && !(entity.hasMetadata("US_REASON") - && entity.getMetadata("US_REASON").get(0).asString().equals("SPAWNER"))) + // Allow spawn if stackreasons are set and match, or if from a spawner + final String spawnReason = entity.hasMetadata("US_REASON") ? entity.getMetadata("US_REASON").get(0).asString() : null; + List stackReasons; + if (Setting.ONLY_STACK_FROM_SPAWNERS.getBoolean()) { + // If only stack from spawners is enabled, make sure the entity spawned from a spawner. + if (!"SPAWNER".equals(spawnReason)) + return false; + } else if (!(stackReasons = Setting.STACK_REASONS.getStringList()).isEmpty() && !stackReasons.contains(spawnReason)) + // Only stack if on the list of events to stack return false; // Cast our entity to living entity. diff --git a/src/main/java/com/songoda/ultimatestacker/utils/settings/Setting.java b/src/main/java/com/songoda/ultimatestacker/utils/settings/Setting.java index 8581c13..6b120ca 100644 --- a/src/main/java/com/songoda/ultimatestacker/utils/settings/Setting.java +++ b/src/main/java/com/songoda/ultimatestacker/utils/settings/Setting.java @@ -113,6 +113,17 @@ public enum Setting { "if the entity originated from a spawner or not is wiped on", "server restart."), + STACK_REASONS("Entities.Stack Reasons", Arrays.asList(), + "This will limit mob stacking to mobs who spawned via the listed reasons.", + "This list is ignored if Only Stack From Spawners = true.", + "The following reasons can be added to the list:", + "NATURAL, JOCKEY, CHUNK_GEN, SPAWNER, EGG, SPAWNER_EGG, LIGHTNING, BUILD_SNOWMAN, ", + "BUILD_IRONGOLEM, BUILD_WITHER, VILLAGE_DEFENSE, VILLAGE_INVASION, BREEDING,", + "SLIME_SPLIT, REINFORCEMENTS, NETHER_PORTAL, DISPENSE_EGG, INFECTION,", + "CURED, OCELOT_BABY, SILVERFISH_BLOCK, MOUNT, TRAP, ENDER_PEARL, ", + "SHOULDER_ENTITY, DROWNED, SHEARED, EXPLOSION" + ), + CARRY_OVER_METADATA_ON_DEATH("Entities.Carry Over Metadata On Death", true, "With this enabled any metadata assigned from supported plugins such", "as EpicSpawners and mcMMO will be preserved when the entity is killed."),