From 8ddee02fbd468bed2b78c9d450b6a4a1f74173e2 Mon Sep 17 00:00:00 2001 From: Penal Buffalo Date: Tue, 21 Dec 2021 08:01:18 -0600 Subject: [PATCH 01/10] 3.3.2 b588 * added compatibility with EliteBosses --- pom.xml | 2 +- .../ExternalCompatibilityManager.java | 19 ++++++++++++++++++- .../levelledmobs/misc/LevellableState.java | 6 ++++++ src/main/resources/predefined/rules_easy.yml | 1 + src/main/resources/predefined/rules_hard.yml | 1 + src/main/resources/rules.yml | 1 + 6 files changed, 28 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index dcebb06cd..a077fe9cb 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ me.lokka30 LevelledMobs - 3.3.1 b587 + 3.3.2 b588 jar LevelledMobs diff --git a/src/main/java/me/lokka30/levelledmobs/managers/ExternalCompatibilityManager.java b/src/main/java/me/lokka30/levelledmobs/managers/ExternalCompatibilityManager.java index 28ce44d5d..d5765c2b3 100644 --- a/src/main/java/me/lokka30/levelledmobs/managers/ExternalCompatibilityManager.java +++ b/src/main/java/me/lokka30/levelledmobs/managers/ExternalCompatibilityManager.java @@ -60,7 +60,9 @@ public enum ExternalCompatibility { // PlaceholderAPI plugin PLACEHOLDER_API, - SIMPLE_PETS + SIMPLE_PETS, + + ELITE_BOSSES } /* Store any external namespaced keys with null values by default */ @@ -113,6 +115,17 @@ private static boolean isMobOfSimplePets(@NotNull final LivingEntityWrapper lmEn return SimplePets.isPetEntity(lmEntity.getLivingEntity()); } + private static boolean isMobOfEliteBosses(@NotNull final LivingEntityWrapper lmEntity){ + final Plugin plugin = Bukkit.getPluginManager().getPlugin("EliteBosses"); + if (plugin == null) return false; + + for (final MetadataValue meta : lmEntity.getLivingEntity().getMetadata("EliteBosses")) { + if (meta.asInt() > 0) return true; + } + + return false; + } + public static boolean isMythicMob(@NotNull final LivingEntityWrapper lmEntity) { final Plugin p = Bukkit.getPluginManager().getPlugin("MythicMobs"); if (p == null) return false; @@ -203,6 +216,10 @@ static LevellableState checkAllExternalCompats(final LivingEntityWrapper lmEntit result == LevellableState.ALLOWED) result = LevellableState.DENIED_CONFIGURATION_COMPATIBILITY_SIMPLEPETS; + if (isMobOfEliteBosses(lmEntity) && !isExternalCompatibilityEnabled(ExternalCompatibility.ELITE_BOSSES, compatRules) && + result == LevellableState.ALLOWED) + result = LevellableState.DENIED_CONFIGURATION_COMPATIBILITY_ELITE_BOSSES; + return result; } diff --git a/src/main/java/me/lokka30/levelledmobs/misc/LevellableState.java b/src/main/java/me/lokka30/levelledmobs/misc/LevellableState.java index 8f2cc3f32..213d90ed0 100644 --- a/src/main/java/me/lokka30/levelledmobs/misc/LevellableState.java +++ b/src/main/java/me/lokka30/levelledmobs/misc/LevellableState.java @@ -81,6 +81,12 @@ public enum LevellableState { */ DENIED_CONFIGURATION_COMPATIBILITY_SIMPLEPETS, + /** + * A rule has been configured to block + * Elite Bosses from being levelled + */ + DENIED_CONFIGURATION_COMPATIBILITY_ELITE_BOSSES, + /** * A rule has been configured to block * nametagged mobs from being levelled. diff --git a/src/main/resources/predefined/rules_easy.yml b/src/main/resources/predefined/rules_easy.yml index 89cad9ac8..41326ba28 100644 --- a/src/main/resources/predefined/rules_easy.yml +++ b/src/main/resources/predefined/rules_easy.yml @@ -354,6 +354,7 @@ default-rule: CITIZENS: false SHOPKEEPERS: false SIMPLE_PETS: false + ELITE_BOSSES: false # apply-above-y: 64 # apply-below-y: 59 diff --git a/src/main/resources/predefined/rules_hard.yml b/src/main/resources/predefined/rules_hard.yml index 87510085a..a6b4c849c 100644 --- a/src/main/resources/predefined/rules_hard.yml +++ b/src/main/resources/predefined/rules_hard.yml @@ -354,6 +354,7 @@ default-rule: CITIZENS: false SHOPKEEPERS: false SIMPLE_PETS: false + ELITE_BOSSES: false # apply-above-y: 64 # apply-below-y: 59 diff --git a/src/main/resources/rules.yml b/src/main/resources/rules.yml index a7916f529..97eb55f0c 100644 --- a/src/main/resources/rules.yml +++ b/src/main/resources/rules.yml @@ -354,6 +354,7 @@ default-rule: CITIZENS: false SHOPKEEPERS: false SIMPLE_PETS: false + ELITE_BOSSES: false # apply-above-y: 64 # apply-below-y: 59 From af72889d6f9a107920a6e43e0392c5cd130b07cf Mon Sep 17 00:00:00 2001 From: Penal Buffalo Date: Tue, 21 Dec 2021 15:02:12 -0600 Subject: [PATCH 02/10] 3.3.2 b589 * prevent zombie-spawn-reinforcements from applying to zombified piglins --- pom.xml | 2 +- .../java/me/lokka30/levelledmobs/managers/MobDataManager.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a077fe9cb..e03b871e1 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ me.lokka30 LevelledMobs - 3.3.2 b588 + 3.3.2 b589 jar LevelledMobs diff --git a/src/main/java/me/lokka30/levelledmobs/managers/MobDataManager.java b/src/main/java/me/lokka30/levelledmobs/managers/MobDataManager.java index 0287a681f..c3a6e9eb7 100644 --- a/src/main/java/me/lokka30/levelledmobs/managers/MobDataManager.java +++ b/src/main/java/me/lokka30/levelledmobs/managers/MobDataManager.java @@ -73,6 +73,9 @@ void setAdditionsForLevel(@NotNull final LivingEntityWrapper lmEntity, final @No if (attrib == null) return; + // if zombified piglins get this attribute applied, they will spawn in zombies in the nether + if (attribute == Attribute.ZOMBIE_SPAWN_REINFORCEMENTS && lmEntity.getEntityType() == EntityType.ZOMBIFIED_PIGLIN) return; + double existingDamage = 0; if (attribute == Attribute.GENERIC_MAX_HEALTH && lmEntity.getLivingEntity().getAttribute(attribute) != null) existingDamage = Objects.requireNonNull(lmEntity.getLivingEntity().getAttribute(attribute)).getValue() - lmEntity.getLivingEntity().getHealth(); From ff0779853e77a3aa7e01e418eac1b85b095e8196 Mon Sep 17 00:00:00 2001 From: Penal Buffalo Date: Wed, 22 Dec 2021 20:08:45 -0600 Subject: [PATCH 03/10] 3.3.2 b590 * fix mob tamed or untamed rule behavior --- pom.xml | 2 +- .../lokka30/levelledmobs/managers/LevelManager.java | 5 ----- .../me/lokka30/levelledmobs/rules/RulesManager.java | 11 +++++++++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index e03b871e1..3acd805c2 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ me.lokka30 LevelledMobs - 3.3.2 b589 + 3.3.2 b590 jar LevelledMobs diff --git a/src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java b/src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java index 9f642cfee..0af357259 100644 --- a/src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java +++ b/src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java @@ -1111,11 +1111,6 @@ This is also ran in getLevellableState(EntityType), however it is important that main.rulesManager.getRule_MobCustomNameStatus(lmEntity) == MobCustomNameStatus.NOT_NAMETAGGED) return LevellableState.DENIED_CONFIGURATION_CONDITION_NAMETAGGED; - // Tamed mobs. - if (lmEntity.isMobTamed() && - main.rulesManager.getRule_MobTamedStatus(lmEntity) == MobTamedStatus.NOT_TAMED) - return LevellableState.DENIED_CONFIGURATION_CONDITION_TAMED; - return LevellableState.ALLOWED; } diff --git a/src/main/java/me/lokka30/levelledmobs/rules/RulesManager.java b/src/main/java/me/lokka30/levelledmobs/rules/RulesManager.java index b241042fc..ecc860b1d 100644 --- a/src/main/java/me/lokka30/levelledmobs/rules/RulesManager.java +++ b/src/main/java/me/lokka30/levelledmobs/rules/RulesManager.java @@ -14,6 +14,7 @@ import me.lokka30.levelledmobs.rules.strategies.LevellingStrategy; import org.bukkit.World; import org.bukkit.entity.Player; +import org.bukkit.entity.Tameable; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -614,6 +615,16 @@ private boolean isRuleApplicable_Entity(final LivingEntityWrapper lmEntity, @Not } } + if (ri.conditions_MobTamedStatus != MobTamedStatus.NOT_SPECIFIED && ri.conditions_MobTamedStatus != MobTamedStatus.EITHER && + lmEntity.getLivingEntity() instanceof Tameable){ + if (lmEntity.isMobTamed() && ri.conditions_MobTamedStatus == MobTamedStatus.NOT_TAMED || + !lmEntity.isMobTamed() && ri.conditions_MobTamedStatus == MobTamedStatus.TAMED){ + Utils.debugLog(main, DebugType.ENTITY_TAME, String.format("&b%s&7, mob: &b%s&7, tamed: %s, rule: %s", + ri.getRuleName(), lmEntity.getNameIfBaby(), lmEntity.isMobTamed(), ri.conditions_MobTamedStatus)); + return false; + } + } + return true; } From e2c16a725090456bca5647131de501beb45fe846 Mon Sep 17 00:00:00 2001 From: Penal Buffalo Date: Thu, 23 Dec 2021 22:05:10 -0600 Subject: [PATCH 04/10] 3.3.2 b591 * added new rule condition scoreboard-tags, uses a string modallist --- pom.xml | 2 +- .../me/lokka30/levelledmobs/misc/DebugType.java | 4 +++- .../me/lokka30/levelledmobs/rules/RuleInfo.java | 1 + .../lokka30/levelledmobs/rules/RulesManager.java | 16 ++++++++++++++++ .../levelledmobs/rules/RulesParsingManager.java | 1 + 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 3acd805c2..3b1a6a27e 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ me.lokka30 LevelledMobs - 3.3.2 b590 + 3.3.2 b591 jar LevelledMobs diff --git a/src/main/java/me/lokka30/levelledmobs/misc/DebugType.java b/src/main/java/me/lokka30/levelledmobs/misc/DebugType.java index 26f6ff894..0ece015bc 100644 --- a/src/main/java/me/lokka30/levelledmobs/misc/DebugType.java +++ b/src/main/java/me/lokka30/levelledmobs/misc/DebugType.java @@ -135,5 +135,7 @@ public enum DebugType { CUSTOM_DROPS, - THREAD_LOCKS + THREAD_LOCKS, + + SCOREBOARD_TAGS } diff --git a/src/main/java/me/lokka30/levelledmobs/rules/RuleInfo.java b/src/main/java/me/lokka30/levelledmobs/rules/RuleInfo.java index 9af841a3c..d025be2e8 100644 --- a/src/main/java/me/lokka30/levelledmobs/rules/RuleInfo.java +++ b/src/main/java/me/lokka30/levelledmobs/rules/RuleInfo.java @@ -93,6 +93,7 @@ public RuleInfo(final String id){ CachedModalList conditions_MM_Names; CachedModalList conditions_SpawnerNames; CachedModalList conditions_SpawnegEggNames; + CachedModalList conditions_ScoreboardTags; CachedModalList conditions_WorldTickTime; CachedModalList conditions_SpawnReasons; CachedModalList conditions_Permission; diff --git a/src/main/java/me/lokka30/levelledmobs/rules/RulesManager.java b/src/main/java/me/lokka30/levelledmobs/rules/RulesManager.java index ecc860b1d..8f3e90c8e 100644 --- a/src/main/java/me/lokka30/levelledmobs/rules/RulesManager.java +++ b/src/main/java/me/lokka30/levelledmobs/rules/RulesManager.java @@ -625,6 +625,22 @@ private boolean isRuleApplicable_Entity(final LivingEntityWrapper lmEntity, @Not } } + if (ri.conditions_ScoreboardTags != null){ + final Set tags = lmEntity.getLivingEntity().getScoreboardTags(); + if (tags.isEmpty()) tags.add("(none)"); + + boolean madeCriteria = false; + for (final String tag : tags){ + if (ri.conditions_ScoreboardTags.isEnabledInList(tag, lmEntity)) + madeCriteria = true; + } + if (!madeCriteria){ + Utils.debugLog(main, DebugType.SCOREBOARD_TAGS, String.format("&b%s&7, mob: &b%s&7", + ri.getRuleName(), lmEntity.getNameIfBaby())); + return false; + } + } + return true; } diff --git a/src/main/java/me/lokka30/levelledmobs/rules/RulesParsingManager.java b/src/main/java/me/lokka30/levelledmobs/rules/RulesParsingManager.java index 6c68d9e8d..999f592fa 100644 --- a/src/main/java/me/lokka30/levelledmobs/rules/RulesParsingManager.java +++ b/src/main/java/me/lokka30/levelledmobs/rules/RulesParsingManager.java @@ -739,6 +739,7 @@ private void parseConditions(final @Nullable ConfigurationSection cs){ parsingInfo.conditions_SpawnegEggNames = buildCachedModalListOfString(cs,"spawner-egg-names", parsingInfo.conditions_SpawnegEggNames); parsingInfo.conditions_WorldTickTime = parseWorldTimeTicks(cs, parsingInfo.conditions_WorldTickTime); parsingInfo.conditions_Permission = buildCachedModalListOfString(cs, "permission", parsingInfo.conditions_Permission); + parsingInfo.conditions_ScoreboardTags = buildCachedModalListOfString(cs, "scoreboard-tags", parsingInfo.conditions_ScoreboardTags); } private void parseStrategies(final ConfigurationSection cs){ From 4556e31432e374863b0323e2822b330a91af6199 Mon Sep 17 00:00:00 2001 From: Penal Buffalo Date: Fri, 24 Dec 2021 18:49:04 -0600 Subject: [PATCH 05/10] 3.3.2 b592 * added delay option to customCommand in customdrops.yml --- pom.xml | 2 +- .../customdrops/CustomCommand.java | 1 + .../customdrops/CustomDropsHandler.java | 21 +++++++++++++++++-- .../customdrops/CustomDropsParser.java | 1 + 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 3b1a6a27e..31cf9b5d1 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ me.lokka30 LevelledMobs - 3.3.2 b591 + 3.3.2 b592 jar LevelledMobs diff --git a/src/main/java/me/lokka30/levelledmobs/customdrops/CustomCommand.java b/src/main/java/me/lokka30/levelledmobs/customdrops/CustomCommand.java index 0787bd091..7c1ba578b 100644 --- a/src/main/java/me/lokka30/levelledmobs/customdrops/CustomCommand.java +++ b/src/main/java/me/lokka30/levelledmobs/customdrops/CustomCommand.java @@ -30,6 +30,7 @@ public class CustomCommand extends CustomDropBase { final public List commands; @NotNull final Map rangedEntries; + public int delay; public CustomCommand cloneItem() { CustomCommand copy = null; diff --git a/src/main/java/me/lokka30/levelledmobs/customdrops/CustomDropsHandler.java b/src/main/java/me/lokka30/levelledmobs/customdrops/CustomDropsHandler.java index 2b9837228..505a7fd1e 100644 --- a/src/main/java/me/lokka30/levelledmobs/customdrops/CustomDropsHandler.java +++ b/src/main/java/me/lokka30/levelledmobs/customdrops/CustomDropsHandler.java @@ -26,6 +26,7 @@ import org.bukkit.inventory.meta.Damageable; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.persistence.PersistentDataType; +import org.bukkit.scheduler.BukkitRunnable; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -680,11 +681,27 @@ private void executeCommand(@NotNull final CustomCommand customCommand, @NotNull Utils.debugLog(main, DebugType.CUSTOM_COMMANDS, debugCommand + command); - for (int i = 0; i < timesToRun; i++) - Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command); + if (customCommand.delay > 0) { + final String commandToRun = command; + final int finalTimesToRun = timesToRun; + final BukkitRunnable runnable = new BukkitRunnable() { + @Override + public void run() { + executeTheCommand(commandToRun, finalTimesToRun); + } + }; + runnable.runTaskLater(main, customCommand.delay); + } + else + executeTheCommand(command, timesToRun); } } + private void executeTheCommand(final String command, final int timesToRun){ + for (int i = 0; i < timesToRun; i++) + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command); + } + @NotNull private String processRangedCommand(@NotNull String command, final @NotNull CustomCommand cc){ if (cc.rangedEntries.isEmpty()) return command; diff --git a/src/main/java/me/lokka30/levelledmobs/customdrops/CustomDropsParser.java b/src/main/java/me/lokka30/levelledmobs/customdrops/CustomDropsParser.java index c18a498cb..30caad28f 100644 --- a/src/main/java/me/lokka30/levelledmobs/customdrops/CustomDropsParser.java +++ b/src/main/java/me/lokka30/levelledmobs/customdrops/CustomDropsParser.java @@ -378,6 +378,7 @@ else if (singleCommand != null) customCommand.commands.add(singleCommand); customCommand.commandName = ymlHelper.getString(cs,"name"); + customCommand.delay = ymlHelper.getInt(cs, "delay", 0); parseRangedVariables(customCommand, cs); if (customCommand.commands.isEmpty()) From 1817c43119ad7344507545bfa9b8821f5c27ad20 Mon Sep 17 00:00:00 2001 From: Penal Buffalo Date: Sat, 25 Dec 2021 10:22:16 -0600 Subject: [PATCH 06/10] 3.3.2 b593 * added player_caused as an option for cause-of-death in custom drops --- pom.xml | 2 +- .../customdrops/CauseOfDeathEnum.java | 34 ++++++++++++++++++ .../customdrops/CustomDropBase.java | 4 +-- .../customdrops/CustomDropProcessingInfo.java | 2 +- .../customdrops/CustomDropsDefaults.java | 2 +- .../customdrops/CustomDropsHandler.java | 36 ++++++++++++------- .../customdrops/CustomDropsParser.java | 10 +++--- .../me/lokka30/levelledmobs/misc/Utils.java | 3 +- 8 files changed, 70 insertions(+), 23 deletions(-) create mode 100644 src/main/java/me/lokka30/levelledmobs/customdrops/CauseOfDeathEnum.java diff --git a/pom.xml b/pom.xml index 31cf9b5d1..5b5ebc068 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ me.lokka30 LevelledMobs - 3.3.2 b592 + 3.3.2 b593 jar LevelledMobs diff --git a/src/main/java/me/lokka30/levelledmobs/customdrops/CauseOfDeathEnum.java b/src/main/java/me/lokka30/levelledmobs/customdrops/CauseOfDeathEnum.java new file mode 100644 index 000000000..88084b4d1 --- /dev/null +++ b/src/main/java/me/lokka30/levelledmobs/customdrops/CauseOfDeathEnum.java @@ -0,0 +1,34 @@ +package me.lokka30.levelledmobs.customdrops; + +public enum CauseOfDeathEnum { + BLOCK_EXPLOSION, + CONTACT, + CRAMMING, + CUSTOM, + DRAGON_BREATH, + DROWNING, + DRYOUT, + ENTITY_ATTACK, + ENTITY_EXPLOSION, + ENTITY_SWEEP_ATTACK, + FALL, + FALLING_BLOCK, + FIRE, + FIRE_TICK, + FLY_INTO_WALL, + FREEZE, + HOT_FLOOR, + LAVA, + LIGHTNING, + MAGIC, + MELTING, + POISON, + PROJECTILE, + STARVATION, + SUFFOCATION, + SUICIDE, + THORNS, + VOID, + WITHER, + PLAYER_CAUSED +} diff --git a/src/main/java/me/lokka30/levelledmobs/customdrops/CustomDropBase.java b/src/main/java/me/lokka30/levelledmobs/customdrops/CustomDropBase.java index f8c3a13fe..1235bf75a 100644 --- a/src/main/java/me/lokka30/levelledmobs/customdrops/CustomDropBase.java +++ b/src/main/java/me/lokka30/levelledmobs/customdrops/CustomDropBase.java @@ -44,7 +44,7 @@ public class CustomDropBase implements Cloneable { String playerLevelVariable; final public List permissions; final Set excludedMobs = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); - CachedModalList causeOfDeathReqs; + CachedModalList causeOfDeathReqs; public int getAmount(){ return this.amount; @@ -104,7 +104,7 @@ public CustomDropBase cloneItem() { copy = (CustomDropBase) super.clone(); if (this.causeOfDeathReqs != null) //noinspection unchecked - copy.causeOfDeathReqs = (CachedModalList) this.causeOfDeathReqs.clone(); + copy.causeOfDeathReqs = (CachedModalList) this.causeOfDeathReqs.clone(); } catch (final Exception e) { e.printStackTrace(); } diff --git a/src/main/java/me/lokka30/levelledmobs/customdrops/CustomDropProcessingInfo.java b/src/main/java/me/lokka30/levelledmobs/customdrops/CustomDropProcessingInfo.java index 524d5bba7..8fe95a348 100644 --- a/src/main/java/me/lokka30/levelledmobs/customdrops/CustomDropProcessingInfo.java +++ b/src/main/java/me/lokka30/levelledmobs/customdrops/CustomDropProcessingInfo.java @@ -44,7 +44,7 @@ class CustomDropProcessingInfo { boolean equippedOnly; boolean deathByFire; boolean wasKilledByPlayer; - EntityDamageEvent.DamageCause deathCause; + CauseOfDeathEnum deathCause; boolean doNotMultiplyDrops; boolean hasOverride; boolean hasCustomDropId; diff --git a/src/main/java/me/lokka30/levelledmobs/customdrops/CustomDropsDefaults.java b/src/main/java/me/lokka30/levelledmobs/customdrops/CustomDropsDefaults.java index 9cd5f244e..e0b68e2f6 100644 --- a/src/main/java/me/lokka30/levelledmobs/customdrops/CustomDropsDefaults.java +++ b/src/main/java/me/lokka30/levelledmobs/customdrops/CustomDropsDefaults.java @@ -39,7 +39,7 @@ class CustomDropsDefaults { String playerLevelVariable; public final List permissions; final List overallPermissions; - CachedModalList causeOfDeathReqs; + CachedModalList causeOfDeathReqs; CustomDropsDefaults() { // these are the defaults of the defaults diff --git a/src/main/java/me/lokka30/levelledmobs/customdrops/CustomDropsHandler.java b/src/main/java/me/lokka30/levelledmobs/customdrops/CustomDropsHandler.java index 505a7fd1e..c9c418cfd 100644 --- a/src/main/java/me/lokka30/levelledmobs/customdrops/CustomDropsHandler.java +++ b/src/main/java/me/lokka30/levelledmobs/customdrops/CustomDropsHandler.java @@ -97,7 +97,7 @@ public CustomDropResult getCustomItemDrops(final LivingEntityWrapper lmEntity, f processingInfo.wasKilledByPlayer = false; if (lmEntity.getLivingEntity().getLastDamageCause() != null) - processingInfo.deathCause = lmEntity.getLivingEntity().getLastDamageCause().getCause(); + processingInfo.deathCause = CauseOfDeathEnum.valueOf(lmEntity.getLivingEntity().getLastDamageCause().getCause().toString().toUpperCase()); processingInfo.addition = BigDecimal.valueOf(main.mobDataManager.getAdditionsForLevel(lmEntity, Addition.CUSTOM_ITEM_DROP, 0.0)) .setScale(0, RoundingMode.HALF_DOWN).intValueExact(); // truncate double to int @@ -318,17 +318,7 @@ private void getDropsFromCustomDropItem(@NotNull final CustomDropProcessingInfo if (!info.equippedOnly && dropBase.playerCausedOnly && (dropBase.causeOfDeathReqs == null || dropBase.causeOfDeathReqs.isEmpty()) && !info.wasKilledByPlayer) return; if (dropBase.noSpawner && info.isSpawner) return; - if (dropBase.causeOfDeathReqs != null && (info.deathCause == null || !Utils.isDamageCauseInModalList(dropBase.causeOfDeathReqs, info.deathCause))){ - if (isCustomDropsDebuggingEnabled()) { - final String itemName = dropBase instanceof CustomDropItem ? - ((CustomDropItem) dropBase).getMaterial().name() : "(command)"; - info.addDebugMessage(String.format( - "&8 - &7item: &b%s&7, death-cause: &b%s&7, death-cause-req: &b%s&7, dropped: &bfalse&7.", - itemName, info.deathCause, dropBase.causeOfDeathReqs) - ); - } - return; - } + if (shouldDenyDeathCause(dropBase, info)) return; if (!madePlayerLevelRequirement(info, dropBase)) return; @@ -543,6 +533,28 @@ else if (dropBase instanceof CustomCommand) { info.newDrops.add(newItem); } + private boolean shouldDenyDeathCause(final @NotNull CustomDropBase dropBase, final @NotNull CustomDropProcessingInfo info){ + if (dropBase.causeOfDeathReqs == null || info.deathCause == null) return false; + + if (info.wasKilledByPlayer && Utils.isDamageCauseInModalList(dropBase.causeOfDeathReqs, CauseOfDeathEnum.PLAYER_CAUSED)) + return false; + + if (!Utils.isDamageCauseInModalList(dropBase.causeOfDeathReqs, info.deathCause)){ + if (isCustomDropsDebuggingEnabled()) { + final String itemName = dropBase instanceof CustomDropItem ? + ((CustomDropItem) dropBase).getMaterial().name() : "(command)"; + info.addDebugMessage(String.format( + "&8 - &7item: &b%s&7, death-cause: &b%s&7, death-cause-req: &b%s&7, dropped: &bfalse&7.", + itemName, info.deathCause, dropBase.causeOfDeathReqs) + ); + } + + return true; + } + + return false; + } + private boolean checkDropPermissions(final @NotNull CustomDropProcessingInfo info, final @NotNull CustomDropBase dropBase){ if (info.equippedOnly || dropBase.permissions.isEmpty()) return true; diff --git a/src/main/java/me/lokka30/levelledmobs/customdrops/CustomDropsParser.java b/src/main/java/me/lokka30/levelledmobs/customdrops/CustomDropsParser.java index 30caad28f..4f658b39f 100644 --- a/src/main/java/me/lokka30/levelledmobs/customdrops/CustomDropsParser.java +++ b/src/main/java/me/lokka30/levelledmobs/customdrops/CustomDropsParser.java @@ -447,11 +447,11 @@ else if (singleCommand != null) } @NotNull - private CachedModalList buildCachedModalListOfDamageCause(final ConfigurationSection cs, - final CachedModalList defaultValue) { + private CachedModalList buildCachedModalListOfDamageCause(final ConfigurationSection cs, + final CachedModalList defaultValue) { if (cs == null) return defaultValue; - final CachedModalList cachedModalList = new CachedModalList<>(); + final CachedModalList cachedModalList = new CachedModalList<>(); final Object simpleStringOrArray = cs.get(ymlHelper.getKeyNameFromConfig(cs, "cause-of-death")); ConfigurationSection cs2 = null; List useList = null; @@ -481,7 +481,7 @@ else if (simpleStringOrArray instanceof String) continue; } try { - final EntityDamageEvent.DamageCause cause = EntityDamageEvent.DamageCause.valueOf(item.trim().toUpperCase()); + final CauseOfDeathEnum cause = CauseOfDeathEnum.valueOf(item.trim().toUpperCase()); cachedModalList.allowedList.add(cause); } catch (final IllegalArgumentException ignored) { Utils.logger.warning("Invalid damage cause: " + item); @@ -498,7 +498,7 @@ else if (simpleStringOrArray instanceof String) continue; } try { - final EntityDamageEvent.DamageCause cause = EntityDamageEvent.DamageCause.valueOf(item.trim().toUpperCase()); + final CauseOfDeathEnum cause = CauseOfDeathEnum.valueOf(item.trim().toUpperCase()); cachedModalList.excludedList.add(cause); } catch (final IllegalArgumentException ignored) { Utils.logger.warning("Invalid damage cause: " + item); diff --git a/src/main/java/me/lokka30/levelledmobs/misc/Utils.java b/src/main/java/me/lokka30/levelledmobs/misc/Utils.java index b5a70f5e3..03d132ac4 100644 --- a/src/main/java/me/lokka30/levelledmobs/misc/Utils.java +++ b/src/main/java/me/lokka30/levelledmobs/misc/Utils.java @@ -5,6 +5,7 @@ package me.lokka30.levelledmobs.misc; import me.lokka30.levelledmobs.LevelledMobs; +import me.lokka30.levelledmobs.customdrops.CauseOfDeathEnum; import me.lokka30.levelledmobs.rules.MinAndMax; import me.lokka30.levelledmobs.rules.RulesManager; import me.lokka30.microlib.messaging.MessageUtils; @@ -269,7 +270,7 @@ public static boolean isBiomeInModalList(@NotNull final CachedModalList l return list.isBlacklist() || list.allowedList.contains(biome); } - public static boolean isDamageCauseInModalList(@NotNull final CachedModalList list, final EntityDamageEvent.DamageCause cause) { + public static boolean isDamageCauseInModalList(@NotNull final CachedModalList list, final CauseOfDeathEnum cause) { if (list.allowAll) return true; if (list.excludeAll) return false; if (list.isEmpty()) return true; From 446cc40e83254b237ba34e808212eb9d1c4f26c7 Mon Sep 17 00:00:00 2001 From: Penal Buffalo Date: Sun, 26 Dec 2021 13:52:15 -0600 Subject: [PATCH 07/10] 3.3.2 b594 * fixed exception when a player is killed by a projectile source that is not a living entity, such as a dispenser --- pom.xml | 2 +- .../listeners/paper/PlayerDeathListener.java | 13 +++++++------ .../me/lokka30/levelledmobs/misc/SpigotUtils.java | 13 +++++++------ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index 5b5ebc068..c39914e44 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ me.lokka30 LevelledMobs - 3.3.2 b593 + 3.3.2 b594 jar LevelledMobs diff --git a/src/main/java/me/lokka30/levelledmobs/listeners/paper/PlayerDeathListener.java b/src/main/java/me/lokka30/levelledmobs/listeners/paper/PlayerDeathListener.java index 6c3acb630..34788b7bf 100644 --- a/src/main/java/me/lokka30/levelledmobs/listeners/paper/PlayerDeathListener.java +++ b/src/main/java/me/lokka30/levelledmobs/listeners/paper/PlayerDeathListener.java @@ -50,13 +50,14 @@ private LivingEntityWrapper getPlayersKiller(@NotNull final PlayerDeathEvent eve return null; final Entity damager = ((EntityDamageByEntityEvent) entityDamageEvent).getDamager(); - final LivingEntity killer; + LivingEntity killer = null; - if (damager instanceof Projectile) - killer = (LivingEntity) ((Projectile) damager).getShooter(); - else if (!(damager instanceof LivingEntity)) - return null; - else + if (damager instanceof Projectile) { + final Projectile projectile = (Projectile) damager; + if (projectile.getShooter() instanceof LivingEntity) + killer = (LivingEntity) projectile.getShooter(); + } + else if (damager instanceof LivingEntity) killer = (LivingEntity) damager; if (killer == null || Utils.isNullOrEmpty(killer.getName()) || killer instanceof Player) return null; diff --git a/src/main/java/me/lokka30/levelledmobs/misc/SpigotUtils.java b/src/main/java/me/lokka30/levelledmobs/misc/SpigotUtils.java index a7201ebbd..422872dff 100644 --- a/src/main/java/me/lokka30/levelledmobs/misc/SpigotUtils.java +++ b/src/main/java/me/lokka30/levelledmobs/misc/SpigotUtils.java @@ -59,13 +59,14 @@ public static LivingEntityWrapper getPlayersKiller(@NotNull final PlayerDeathEve return null; final Entity damager = ((EntityDamageByEntityEvent) entityDamageEvent).getDamager(); - final LivingEntity killer; + LivingEntity killer = null; - if (damager instanceof Projectile) - killer = (LivingEntity) ((Projectile) damager).getShooter(); - else if (!(damager instanceof LivingEntity)) - return null; - else + if (damager instanceof Projectile) { + final Projectile projectile = (Projectile) damager; + if (projectile.getShooter() instanceof LivingEntity) + killer = (LivingEntity) projectile.getShooter(); + } + else if (damager instanceof LivingEntity) killer = (LivingEntity) damager; if (killer == null || Utils.isNullOrEmpty(killer.getName()) || killer instanceof Player) return null; From 403284e71fefe81bad544bbf0a56140ba69e27e4 Mon Sep 17 00:00:00 2001 From: Penal Buffalo Date: Mon, 27 Dec 2021 08:03:39 -0600 Subject: [PATCH 08/10] v3.3.2 b595 * fix rare occurrence of the player death message not showing the player's name on Paper servers --- pom.xml | 2 +- .../listeners/paper/PlayerDeathListener.java | 37 ++++++++++++++++--- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index c39914e44..7659f854e 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ me.lokka30 LevelledMobs - 3.3.2 b594 + 3.3.2 b595 jar LevelledMobs diff --git a/src/main/java/me/lokka30/levelledmobs/listeners/paper/PlayerDeathListener.java b/src/main/java/me/lokka30/levelledmobs/listeners/paper/PlayerDeathListener.java index 34788b7bf..3ea3a005c 100644 --- a/src/main/java/me/lokka30/levelledmobs/listeners/paper/PlayerDeathListener.java +++ b/src/main/java/me/lokka30/levelledmobs/listeners/paper/PlayerDeathListener.java @@ -6,6 +6,7 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.TranslatableComponent; +import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; @@ -78,13 +79,8 @@ else if (damager instanceof LivingEntity) private void updateDeathMessage(@NotNull final PlayerDeathEvent event, final String mobName){ final TranslatableComponent tc = (TranslatableComponent) event.deathMessage(); if (tc == null) return; - String playerKilled = null; - - for (final net.kyori.adventure.text.Component com : tc.args()){ - if (com instanceof TextComponent) - playerKilled = ((TextComponent) com).content(); - } + final String playerKilled = extractPlayerName(tc); if (playerKilled == null) return; final TextComponent tcMobName = LegacyComponentSerializer.legacySection().deserialize(mobName); @@ -94,4 +90,33 @@ private void updateDeathMessage(@NotNull final PlayerDeathEvent event, final Str event.deathMessage(newCom); } + + @Nullable + private String extractPlayerName(final @NotNull TranslatableComponent tc){ + String playerKilled = null; + + for (final net.kyori.adventure.text.Component com : tc.args()){ + if (com instanceof TextComponent) { + final TextComponent tc2 = (TextComponent) com; + playerKilled = tc2.content(); + + if (playerKilled.isEmpty() && tc2.hoverEvent() != null) { + // in rare cases the above method returns a empty string + // we'll extract the player name from the hover event + final HoverEvent he = tc2.hoverEvent(); + if (he == null || !(he.value() instanceof HoverEvent.ShowEntity)) return null; + + final HoverEvent.ShowEntity se = (HoverEvent.ShowEntity) he.value(); + + if (se.name() instanceof TextComponent){ + final TextComponent tc3 = (TextComponent) se.name(); + playerKilled = tc3.content(); + } + } + } + } + + return playerKilled != null && playerKilled.isEmpty() ? + null : playerKilled; + } } From 8f97c5db298735a1d84911e62ca3ab50754254a7 Mon Sep 17 00:00:00 2001 From: lokka30 Date: Tue, 28 Dec 2021 08:23:52 +0800 Subject: [PATCH 09/10] update gitignore - remove libs folder, add mac os x file --- .gitignore | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 602de7a27..10f6a9aad 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,3 @@ -# Non-redistributables -# Why? We respect other developer's work. -/libs - # IntelliJ IDE # Why? Different developers use different IDE settings. /target/ @@ -18,3 +14,6 @@ LevelledMobs.iml /.idea/ .idea/jarRepositories.xml .idea/discord.xml + +# Mac OS X +._.git \ No newline at end of file From 376d3c1bb55ffedaae64fe03bf52bd7c3871ba87 Mon Sep 17 00:00:00 2001 From: Penal Buffalo Date: Mon, 27 Dec 2021 21:47:59 -0600 Subject: [PATCH 10/10] 3.3.2 b596 * fixed custom drops not being multiplied * overhauled debug messages when used with SET_LEVELLED_ITEM_DROPS --- pom.xml | 2 +- .../customdrops/CustomDropsHandler.java | 3 +- .../levelledmobs/managers/LevelManager.java | 34 ++++++++++++------- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/pom.xml b/pom.xml index 7659f854e..2131ede7e 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ me.lokka30 LevelledMobs - 3.3.2 b595 + 3.3.2 b596 jar LevelledMobs diff --git a/src/main/java/me/lokka30/levelledmobs/customdrops/CustomDropsHandler.java b/src/main/java/me/lokka30/levelledmobs/customdrops/CustomDropsHandler.java index c9c418cfd..47e66dd1d 100644 --- a/src/main/java/me/lokka30/levelledmobs/customdrops/CustomDropsHandler.java +++ b/src/main/java/me/lokka30/levelledmobs/customdrops/CustomDropsHandler.java @@ -99,7 +99,7 @@ public CustomDropResult getCustomItemDrops(final LivingEntityWrapper lmEntity, f if (lmEntity.getLivingEntity().getLastDamageCause() != null) processingInfo.deathCause = CauseOfDeathEnum.valueOf(lmEntity.getLivingEntity().getLastDamageCause().getCause().toString().toUpperCase()); - processingInfo.addition = BigDecimal.valueOf(main.mobDataManager.getAdditionsForLevel(lmEntity, Addition.CUSTOM_ITEM_DROP, 0.0)) + processingInfo.addition = BigDecimal.valueOf(main.mobDataManager.getAdditionsForLevel(lmEntity, Addition.CUSTOM_ITEM_DROP, 2)) .setScale(0, RoundingMode.HALF_DOWN).intValueExact(); // truncate double to int processingInfo.doNotMultiplyDrops = main.rulesManager.getRule_CheckIfNoDropMultiplierEntitiy(lmEntity); @@ -112,7 +112,6 @@ public CustomDropResult getCustomItemDrops(final LivingEntityWrapper lmEntity, f } if (!equippedOnly && isCustomDropsDebuggingEnabled()) { - final String mobLevel = lmEntity.getMobLevel() > 0 ? "&r (level " + lmEntity.getMobLevel() + ")" : ""; processingInfo.addDebugMessage("&7Custom drops for &b" + lmEntity.getNameIfBaby() + mobLevel); processingInfo.addDebugMessage("&8- &7Groups: &b" + String.join("&7, &b", lmEntity.getApplicableGroups()) + "&7."); diff --git a/src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java b/src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java index 0af357259..6531d4959 100644 --- a/src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java +++ b/src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java @@ -404,56 +404,64 @@ public int[] getMinAndMaxLevels(final @NotNull LivingEntityInterface lmInterface } // This sets the levelled currentDrops on a levelled mob that just died. - public void setLevelledItemDrops(final LivingEntityWrapper lmEntity, final List currentDrops) { + public void setLevelledItemDrops(final LivingEntityWrapper lmEntity, final @NotNull List currentDrops) { + final int vanillaDrops = currentDrops.size(); // this accomodates chested animals, saddles and armor on ridable creatures final List dropsToMultiply = getDropsToMultiply(lmEntity, currentDrops); final List customDrops = new LinkedList<>(); currentDrops.clear(); - Utils.debugLog(main, DebugType.SET_LEVELLED_ITEM_DROPS, "&81:&7 Method called. &b" + dropsToMultiply.size() + "&7 drops will be analysed."); - - Utils.debugLog(main, DebugType.SET_LEVELLED_ITEM_DROPS, "&82:&7 Level of the &b" + lmEntity.getTypeName() + "&7 entity is &b" + lmEntity.getMobLevel() + "&7."); - final boolean doNotMultiplyDrops = main.rulesManager.getRule_CheckIfNoDropMultiplierEntitiy(lmEntity); + boolean hasOverride = false; if (main.rulesManager.getRule_UseCustomDropsForMob(lmEntity).useDrops) { // custom drops also get multiplied in the custom drops handler final CustomDropResult dropResult = main.customDropsHandler.getCustomItemDrops(lmEntity, customDrops, false); if (dropResult == CustomDropResult.HAS_OVERRIDE) { - Utils.debugLog(main, DebugType.SET_LEVELLED_ITEM_DROPS, "&83:&7 Custom drop has override."); + hasOverride = true; removeVanillaDrops(lmEntity, dropsToMultiply); } } + int additionUsed = 0; + int dropsChecked = 0; + if (!doNotMultiplyDrops && !dropsToMultiply.isEmpty()) { // Get currentDrops added per level value final int addition = BigDecimal.valueOf(main.mobDataManager.getAdditionsForLevel(lmEntity, Addition.CUSTOM_ITEM_DROP, 2.0)) .setScale(0, RoundingMode.HALF_DOWN).intValueExact(); // truncate double to int - Utils.debugLog(main, DebugType.SET_LEVELLED_ITEM_DROPS, "&84:&7 Item drop addition is &b+" + addition + "&7."); + additionUsed = addition; // Modify current drops - Utils.debugLog(main, DebugType.SET_LEVELLED_ITEM_DROPS, "&85:&7 Scanning &b" + dropsToMultiply.size() + "&7 items..."); + dropsChecked = dropsToMultiply.size(); for (final ItemStack currentDrop : dropsToMultiply) multiplyDrop(lmEntity, currentDrop, addition, false); } if (!customDrops.isEmpty()) currentDrops.addAll(customDrops); if (!dropsToMultiply.isEmpty()) currentDrops.addAll(dropsToMultiply); + final String nameWithOverride = hasOverride ? + lmEntity.getNameIfBaby() + " (override)" : lmEntity.getNameIfBaby(); + Utils.debugLog(main, DebugType.SET_LEVELLED_ITEM_DROPS, String.format( + "&7Mob: &b%s&7, mob-lvl: &b%s&7, vanilla drops: &b%s&7, all drops: &b%s&7, addition: &b%s&7.", + nameWithOverride, lmEntity.getMobLevel(), vanillaDrops, currentDrops.size(), additionUsed)); } public void multiplyDrop(final LivingEntityWrapper lmEntity, @NotNull final ItemStack currentDrop, final int addition, final boolean isCustomDrop){ - Utils.debugLog(main, DebugType.SET_LEVELLED_ITEM_DROPS, "&86:&7 Scanning drop &b" + currentDrop.getType() + "&7 with current amount &b" + currentDrop.getAmount() + "&7..."); + final int oldAmount = currentDrop.getAmount(); if (isCustomDrop || main.mobDataManager.isLevelledDropManaged(lmEntity.getLivingEntity().getType(), currentDrop.getType())) { int useAmount = currentDrop.getAmount() + (currentDrop.getAmount() * addition); if (useAmount > currentDrop.getMaxStackSize()) useAmount = currentDrop.getMaxStackSize(); currentDrop.setAmount(useAmount); - Utils.debugLog(main, DebugType.SET_LEVELLED_ITEM_DROPS, "&87:&7 Item was managed. New amount: &b" + currentDrop.getAmount() + "&7."); - } else { - Utils.debugLog(main, DebugType.SET_LEVELLED_ITEM_DROPS, "&87:&7 Item was unmanaged."); + Utils.debugLog(main, DebugType.SET_LEVELLED_ITEM_DROPS, String.format( + "&7Drop: &b%s&7, old amount: &b%s&7, addition value: &b%s&7, new amount: &b%s&7.", + currentDrop.getType(), oldAmount, addition, currentDrop.getAmount())); } + else + Utils.debugLog(main, DebugType.SET_LEVELLED_ITEM_DROPS, "&7Item was unmanaged."); } @NotNull @@ -517,7 +525,7 @@ public void removeVanillaDrops(@NotNull final LivingEntityWrapper lmEntity, fina public int getLevelledExpDrops(@NotNull final LivingEntityWrapper lmEntity, final int xp) { if (lmEntity.isLevelled()) { final int newXp = (int) Math.round(xp + (xp * main.mobDataManager.getAdditionsForLevel(lmEntity, Addition.CUSTOM_XP_DROP, 3.0))); - Utils.debugLog(main, DebugType.SET_LEVELLED_XP_DROPS, String.format("%s: lvl: %s, xp-vanilla: %s, new-xp: %s", + Utils.debugLog(main, DebugType.SET_LEVELLED_XP_DROPS, String.format("&7Mob: &b%s&7: lvl: &b%s&7, xp-vanilla: &b%s&7, new-xp: &b%s&7", lmEntity.getNameIfBaby(), lmEntity.getMobLevel(), xp, newXp)); return newXp; } else