From 62d8a322f7851e0816c080a6ea00fcedd4e40856 Mon Sep 17 00:00:00 2001 From: stumper66 Date: Thu, 28 Oct 2021 11:29:56 -0500 Subject: [PATCH 01/10] 3.2.4 b548 * attempt to fix exceptions --- pom.xml | 2 +- .../levelledmobs/managers/LevelManager.java | 17 +++---- .../managers/NametagQueueManager.java | 2 + .../misc/LivingEntityWrapper.java | 45 ++++++++++++++----- 4 files changed, 45 insertions(+), 21 deletions(-) diff --git a/pom.xml b/pom.xml index 584d632c3..ba834bc9a 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ me.lokka30 LevelledMobs - 3.2.3 b546 + 3.2.4 b547 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 ec51218ff..4f65ab90b 100644 --- a/src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java +++ b/src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java @@ -690,6 +690,7 @@ private void runNametagCheck_aSync(final @NotNull Map> entit } boolean useResetTimer = false; + if (lmEntity.getLivingEntity() == null) continue; final List nametagVisibilityEnums = main.rulesManager.getRule_CreatureNametagVisbility(lmEntity); final int nametagVisibleTime = lmEntity.getNametagCooldownTime(); if (nametagVisibleTime > 0 && @@ -769,6 +770,7 @@ private void checkEntityForPlayerLevelling(final @NotNull LivingEntityWrapper lm } private void checkLevelledEntity(@NotNull final LivingEntityWrapper lmEntity, @NotNull final Player player){ + if (lmEntity.getLivingEntity() == null || !lmEntity.getLivingEntity().isValid()) return; final double maxDistance = Math.pow(128, 2); // square the distance we are using Location#distanceSquared. This is because it is faster than Location#distance since it does not need to sqrt which is taxing on the CPU. final Location location = player.getLocation(); @@ -778,14 +780,13 @@ private void checkLevelledEntity(@NotNull final LivingEntityWrapper lmEntity, @N } else if (lmEntity.isMobTamed() && main.rulesManager.getRule_MobTamedStatus(lmEntity) == MobTamedStatus.NOT_TAMED) { // mob is tamed with a level but the rules don't allow it, remove the level main.levelInterface.removeLevel(lmEntity); - } else { - if (!main.helperSettings.getBoolean(main.settingsCfg, "use-customname-for-mob-nametags", false) && - location.getWorld() != null && - location.getWorld().equals(lmEntity.getWorld()) && - lmEntity.getLocation().distanceSquared(location) <= maxDistance) { - //if within distance, update nametag. - main.nametagQueueManager_.addToQueue(new QueueItem(lmEntity, main.levelManager.getNametag(lmEntity, false), Collections.singletonList(player))); - } + } else if (lmEntity.getLivingEntity().isValid() && + !main.helperSettings.getBoolean(main.settingsCfg, "use-customname-for-mob-nametags", false) && + location.getWorld() != null && + location.getWorld().equals(lmEntity.getWorld()) && + lmEntity.getLocation().distanceSquared(location) <= maxDistance) { + //if within distance, update nametag. + main.nametagQueueManager_.addToQueue(new QueueItem(lmEntity, main.levelManager.getNametag(lmEntity, false), Collections.singletonList(player))); } } diff --git a/src/main/java/me/lokka30/levelledmobs/managers/NametagQueueManager.java b/src/main/java/me/lokka30/levelledmobs/managers/NametagQueueManager.java index 901e1826d..380b53118 100644 --- a/src/main/java/me/lokka30/levelledmobs/managers/NametagQueueManager.java +++ b/src/main/java/me/lokka30/levelledmobs/managers/NametagQueueManager.java @@ -12,6 +12,7 @@ import me.lokka30.levelledmobs.LevelledMobs; import me.lokka30.levelledmobs.misc.*; import me.lokka30.levelledmobs.rules.NametagVisibilityEnum; +import org.bukkit.Bukkit; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Tameable; @@ -68,6 +69,7 @@ public void stop(){ } public void addToQueue(final @NotNull QueueItem item) { + if (Bukkit.getOnlinePlayers().size() == 0) return; if (item.lmEntity.getLivingEntity() == null || main.rulesManager.getRule_CreatureNametagVisbility(item.lmEntity).contains(NametagVisibilityEnum.DISABLED)) return; diff --git a/src/main/java/me/lokka30/levelledmobs/misc/LivingEntityWrapper.java b/src/main/java/me/lokka30/levelledmobs/misc/LivingEntityWrapper.java index 72dd8651d..8cb6c5277 100644 --- a/src/main/java/me/lokka30/levelledmobs/misc/LivingEntityWrapper.java +++ b/src/main/java/me/lokka30/levelledmobs/misc/LivingEntityWrapper.java @@ -164,7 +164,6 @@ private void buildCache(){ main.levelInterface.getLevelOfMob(livingEntity) : null; this.spawnedWGRegions = ExternalCompatibilityManager.getWGRegionsAtLocation(this); - this.nametagCooldownTime = main.rulesManager.getRule_nametagVisibleTime(this); this.hasCache = true; // the lines below must remain after hasCache = true to prevent stack overflow @@ -173,6 +172,7 @@ private void buildCache(){ this.applicableRules = applicableRulesResult.allApplicableRules; checkChanceRules(applicableRulesResult); this.fineTuningAttributes = main.rulesManager.getFineTuningAttributes(this); + this.nametagCooldownTime = main.rulesManager.getRule_nametagVisibleTime(this); this.isBuildingCache = false; } catch (InterruptedException e) { Utils.logger.warning("exception in buildCache: " + e.getMessage()); @@ -205,11 +205,22 @@ private void checkChanceRules(final @NotNull ApplicableRulesResult result){ sbDenied.append(ruleInfo.getRuleName()); } - synchronized (this.livingEntity.getPersistentDataContainer()){ - if (sbAllowed.length() > 0) - this.livingEntity.getPersistentDataContainer().set(main.namespaced_keys.chanceRule_Allowed, PersistentDataType.STRING, sbAllowed.toString()); - if (sbDenied.length() > 0) - this.livingEntity.getPersistentDataContainer().set(main.namespaced_keys.chanceRule_Denied, PersistentDataType.STRING, sbDenied.toString()); + for (int i = 0; i < 2; i++) { + try { + synchronized (this.livingEntity.getPersistentDataContainer()) { + if (sbAllowed.length() > 0) + this.livingEntity.getPersistentDataContainer().set(main.namespaced_keys.chanceRule_Allowed, PersistentDataType.STRING, sbAllowed.toString()); + if (sbDenied.length() > 0) + this.livingEntity.getPersistentDataContainer().set(main.namespaced_keys.chanceRule_Denied, PersistentDataType.STRING, sbDenied.toString()); + break; + } + } catch (java.util.ConcurrentModificationException ignored) { + try { + Thread.sleep(10); + } catch (InterruptedException ignored2) { + break; + } + } } } @@ -469,12 +480,22 @@ public boolean getShouldShowLM_Nametag(){ } } - public void setSpawnedTimeOfDay(final int ticks){ - synchronized (livingEntity.getPersistentDataContainer()) { - if (getPDC().has(main.namespaced_keys.spawnedTimeOfDay, PersistentDataType.INTEGER)) - return; - - getPDC().set(main.namespaced_keys.spawnedTimeOfDay, PersistentDataType.INTEGER, ticks); + public void setSpawnedTimeOfDay(final int ticks) { + for (int i = 0; i < 2; i++) { + try { + synchronized (livingEntity.getPersistentDataContainer()) { + if (getPDC().has(main.namespaced_keys.spawnedTimeOfDay, PersistentDataType.INTEGER)) + return; + + getPDC().set(main.namespaced_keys.spawnedTimeOfDay, PersistentDataType.INTEGER, ticks); + } + } catch(java.util.ConcurrentModificationException ignored){ + try { + Thread.sleep(10); + } catch (InterruptedException ignored2) { + break; + } + } } this.spawnedTimeOfDay = ticks; From 13642db536feeefe8aa4eea522c2b44c6ee803ae Mon Sep 17 00:00:00 2001 From: stumper66 Date: Mon, 1 Nov 2021 10:35:06 -0500 Subject: [PATCH 02/10] 3.2.4 b549 * removed debug message regarding "vehicles" * reworded message when running /lm rules force_all * fixed melee_only ranged nametags still showing after running /lm rules force_all and entities that were previously levelled are no longer levelled --- pom.xml | 2 +- .../commands/subcommands/RulesSubcommand.java | 3 ++- .../levelledmobs/listeners/EntitySpawnListener.java | 4 +++- .../lokka30/levelledmobs/managers/LevelManager.java | 11 +++++------ .../levelledmobs/managers/NametagQueueManager.java | 2 +- .../levelledmobs/misc/LivingEntityWrapper.java | 2 ++ 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index ba834bc9a..71aad8fe2 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ me.lokka30 LevelledMobs - 3.2.4 b547 + 3.2.4 b549 jar LevelledMobs diff --git a/src/main/java/me/lokka30/levelledmobs/commands/subcommands/RulesSubcommand.java b/src/main/java/me/lokka30/levelledmobs/commands/subcommands/RulesSubcommand.java index 9c9575f39..ec2ab6064 100644 --- a/src/main/java/me/lokka30/levelledmobs/commands/subcommands/RulesSubcommand.java +++ b/src/main/java/me/lokka30/levelledmobs/commands/subcommands/RulesSubcommand.java @@ -138,13 +138,14 @@ private void forceRelevel(final CommandSender sender, final String label, @NotNu entityCount++; final LivingEntityWrapper lmEntity = LivingEntityWrapper.getInstance((LivingEntity) entity, main); lmEntity.reEvaluateLevel = true; + lmEntity.wasPreviouslyLevelled = lmEntity.isLevelled(); main._mobsQueueManager.addToQueue(new QueueItem(lmEntity, null)); lmEntity.free(); } } sender.sendMessage(MessageUtils.colorizeAll(String.format( - "%s Checked &b%s&7 mobs in &b%s&7 world(s)", + "%s Rules Reprocessed for &b%s&7 mobs in &b%s&7 world(s)", label, entityCount, worldCount))); } diff --git a/src/main/java/me/lokka30/levelledmobs/listeners/EntitySpawnListener.java b/src/main/java/me/lokka30/levelledmobs/listeners/EntitySpawnListener.java index 09b722aef..6d14e7c0a 100644 --- a/src/main/java/me/lokka30/levelledmobs/listeners/EntitySpawnListener.java +++ b/src/main/java/me/lokka30/levelledmobs/listeners/EntitySpawnListener.java @@ -266,13 +266,15 @@ else if (main.configUtils.playerLevellingEnabled){ // Check if the mob is already levelled - if so, remove their level if (lmEntity.isLevelled()) main.levelInterface.removeLevel(lmEntity); - else if (lmEntity.isBabyMob()) { // add a tag so we can potentially level the mob when/if it ages synchronized (lmEntity.getLivingEntity().getPersistentDataContainer()) { lmEntity.getPDC().set(main.namespaced_keys.wasBabyMobKey, PersistentDataType.INTEGER, 1); } } + + if (lmEntity.wasPreviouslyLevelled) + main.levelManager.updateNametag(lmEntity); } } diff --git a/src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java b/src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java index 4f65ab90b..3d525f5b2 100644 --- a/src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java +++ b/src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java @@ -435,7 +435,7 @@ public int getLevelledExpDrops(@NotNull final LivingEntityWrapper lmEntity, fina @Nullable public String getNametag(final LivingEntityWrapper lmEntity, final boolean isDeathNametag) { - final String nametag = isDeathNametag ? main.rulesManager.getRule_Nametag_CreatureDeath(lmEntity) : main.rulesManager.getRule_Nametag(lmEntity); + String nametag = isDeathNametag ? main.rulesManager.getRule_Nametag_CreatureDeath(lmEntity) : main.rulesManager.getRule_Nametag(lmEntity); if ("disabled".equalsIgnoreCase(nametag) || "none".equalsIgnoreCase(nametag)) return null; final boolean useCustomNameForNametags = main.helperSettings.getBoolean(main.settingsCfg, "use-customname-for-mob-nametags"); @@ -446,12 +446,15 @@ public String getNametag(final LivingEntityWrapper lmEntity, final boolean isDea else return lmEntity.getLivingEntity().getCustomName(); // CustomName can be null, that is meant to be the case. } + if (!lmEntity.isLevelled()) + nametag = ""; return updateNametag(lmEntity, nametag, useCustomNameForNametags); } @NotNull public String updateNametag(final LivingEntityWrapper lmEntity, @NotNull String nametag, final boolean useCustomNameForNametags) { + if ("".equals(nametag)) return nametag; final String overridenName = main.rulesManager.getRule_EntityOverriddenName(lmEntity, useCustomNameForNametags); String displayName = overridenName == null ? @@ -1054,12 +1057,8 @@ public void applyLevelToMob(@NotNull final LivingEntityWrapper lmEntity, int lev && lmEntity.getLivingEntity().getVehicle() instanceof LivingEntity){ // entity is a passenger. grab the level from the "vehicle" entity final LivingEntityWrapper vehicle = LivingEntityWrapper.getInstance((LivingEntity) lmEntity.getLivingEntity().getVehicle(), main); - if (vehicle.isLevelled()) { - Utils.logger.info(lmEntity.getNameIfBaby() + " got level " + vehicle.getMobLevel() + " from vehicle " + vehicle.getNameIfBaby()); + if (vehicle.isLevelled()) level = vehicle.getMobLevel(); - } - else - Utils.logger.info(lmEntity.getNameIfBaby() + " vehicle was unlevelled: " + vehicle.getNameIfBaby()); vehicle.free(); } diff --git a/src/main/java/me/lokka30/levelledmobs/managers/NametagQueueManager.java b/src/main/java/me/lokka30/levelledmobs/managers/NametagQueueManager.java index 380b53118..0d9cf4146 100644 --- a/src/main/java/me/lokka30/levelledmobs/managers/NametagQueueManager.java +++ b/src/main/java/me/lokka30/levelledmobs/managers/NametagQueueManager.java @@ -90,7 +90,7 @@ private void main() throws InterruptedException{ final int nametagTimerResetTime = item.lmEntity.getNametagCooldownTime(); - if (nametagTimerResetTime > 0) { + if (nametagTimerResetTime > 0 && !"".equals(item.nametag)) { synchronized (NametagTimerChecker.nametagTimer_Lock) { final Map> nametagCooldownQueue = main.nametagTimerChecker.getNametagCooldownQueue(); diff --git a/src/main/java/me/lokka30/levelledmobs/misc/LivingEntityWrapper.java b/src/main/java/me/lokka30/levelledmobs/misc/LivingEntityWrapper.java index 8cb6c5277..6d37b1920 100644 --- a/src/main/java/me/lokka30/levelledmobs/misc/LivingEntityWrapper.java +++ b/src/main/java/me/lokka30/levelledmobs/misc/LivingEntityWrapper.java @@ -75,6 +75,7 @@ public LivingEntityWrapper(final @NotNull LivingEntity livingEntity, final @NotN private LevelledMobSpawnReason spawnReason; public EntityDamageEvent.DamageCause deathCause; public boolean reEvaluateLevel; + public boolean wasPreviouslyLevelled; public Player playerForPermissionsCheck; public CommandSender summonedSender; public String nbtData; @@ -136,6 +137,7 @@ public void clearEntityData(){ this.spawnedWGRegions = null; this.fineTuningAttributes = null; this.reEvaluateLevel = false; + this.wasPreviouslyLevelled = false; this.groupsAreBuilt = false; this.playerForLevelling = null; this.prevChanceRuleResults = null; From 43e8b0101748e78a11fb3fff72990e1c29fa6cac Mon Sep 17 00:00:00 2001 From: stumper66 Date: Tue, 2 Nov 2021 13:44:00 -0500 Subject: [PATCH 03/10] 3.2.4 b551 * added PAPI support to anywhere that uses the standard placeholders * running /lm rules force_all also runs a reload --- pom.xml | 2 +- .../levelledmobs/commands/subcommands/RulesSubcommand.java | 2 ++ .../java/me/lokka30/levelledmobs/managers/LevelManager.java | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 71aad8fe2..d59119631 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ me.lokka30 LevelledMobs - 3.2.4 b549 + 3.2.4 b551 jar LevelledMobs diff --git a/src/main/java/me/lokka30/levelledmobs/commands/subcommands/RulesSubcommand.java b/src/main/java/me/lokka30/levelledmobs/commands/subcommands/RulesSubcommand.java index ec2ab6064..e46b91b79 100644 --- a/src/main/java/me/lokka30/levelledmobs/commands/subcommands/RulesSubcommand.java +++ b/src/main/java/me/lokka30/levelledmobs/commands/subcommands/RulesSubcommand.java @@ -125,6 +125,8 @@ private void forceRelevel(final CommandSender sender, final String label, @NotNu int worldCount = 0; int entityCount = 0; + main.reloadLM(sender); + for (final World world : Bukkit.getWorlds()) { worldCount++; for (final Entity entity : world.getEntities()) { diff --git a/src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java b/src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java index 3d525f5b2..7ae49c086 100644 --- a/src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java +++ b/src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java @@ -573,6 +573,9 @@ public String replaceStringPlaceholders(final String nametag, @NotNull final Liv result = result.replace("%y%", lmEntity.getLivingEntity().getLocation().getBlockY() + ""); result = result.replace("%z%", lmEntity.getLivingEntity().getLocation().getBlockZ() + ""); + if (result.contains("%") && ExternalCompatibilityManager.hasPAPI_Installed()) + result = ExternalCompatibilityManager.getPAPI_Placeholder(null, result); + result = MessageUtils.colorizeAll(result); return result; From b031efacb8c0c1154abb52fd69623b8d6c1c24d8 Mon Sep 17 00:00:00 2001 From: stumper66 Date: Wed, 3 Nov 2021 09:46:56 -0500 Subject: [PATCH 04/10] 3.2.4 b552 * fixed rule mythicmobs-internal-names not working with MythicMobs 4.12 --- pom.xml | 2 +- .../levelledmobs/managers/ExternalCompatibilityManager.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index d59119631..399e5aae7 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ me.lokka30 LevelledMobs - 3.2.4 b551 + 3.2.4 b552 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 2edb9a5cf..96b51e0cf 100644 --- a/src/main/java/me/lokka30/levelledmobs/managers/ExternalCompatibilityManager.java +++ b/src/main/java/me/lokka30/levelledmobs/managers/ExternalCompatibilityManager.java @@ -153,7 +153,7 @@ public static String getMythicMobInternalName(@NotNull final LivingEntityWrapper final Plugin p = Bukkit.getPluginManager().getPlugin("MythicMobs"); if (p == null) return ""; - if (!p.getDescription().getVersion().startsWith("4")) { + if (!p.getDescription().getVersion().startsWith("4.12")) { // MM version 5 must use this method for internal name detection final NamespacedKey mmKey = new NamespacedKey(p, "type"); synchronized (lmEntity.getLivingEntity().getPersistentDataContainer()) { From 32effdb0dc0a7ea3bc17f78e0742a5284d55dcfa Mon Sep 17 00:00:00 2001 From: stumper66 Date: Wed, 3 Nov 2021 09:53:27 -0500 Subject: [PATCH 05/10] Update ExternalCompatibilityManager.java --- .../levelledmobs/managers/ExternalCompatibilityManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/lokka30/levelledmobs/managers/ExternalCompatibilityManager.java b/src/main/java/me/lokka30/levelledmobs/managers/ExternalCompatibilityManager.java index 96b51e0cf..a8ed9f665 100644 --- a/src/main/java/me/lokka30/levelledmobs/managers/ExternalCompatibilityManager.java +++ b/src/main/java/me/lokka30/levelledmobs/managers/ExternalCompatibilityManager.java @@ -129,7 +129,7 @@ public static boolean isMythicMob(@NotNull final LivingEntityWrapper lmEntity) { final Plugin p = Bukkit.getPluginManager().getPlugin("MythicMobs"); if (p == null) return false; - if (!p.getDescription().getVersion().startsWith("4.12")) { + if (!p.getDescription().getVersion().startsWith("4.12") && !p.getDescription().getVersion().startsWith("5.")) { final NamespacedKey mmKey = new NamespacedKey(p, "type"); synchronized (lmEntity.getLivingEntity().getPersistentDataContainer()) { return lmEntity.getPDC().has(mmKey, PersistentDataType.STRING); @@ -153,7 +153,7 @@ public static String getMythicMobInternalName(@NotNull final LivingEntityWrapper final Plugin p = Bukkit.getPluginManager().getPlugin("MythicMobs"); if (p == null) return ""; - if (!p.getDescription().getVersion().startsWith("4.12")) { + if (!p.getDescription().getVersion().startsWith("4.12") && !p.getDescription().getVersion().startsWith("5.")) { // MM version 5 must use this method for internal name detection final NamespacedKey mmKey = new NamespacedKey(p, "type"); synchronized (lmEntity.getLivingEntity().getPersistentDataContainer()) { From f20da7e1cd1dd9ea4f2f20012fde216459e85074 Mon Sep 17 00:00:00 2001 From: stumper66 Date: Wed, 3 Nov 2021 19:33:52 -0500 Subject: [PATCH 06/10] 3.2.4 b554 * fix for potential exception when using player levelling --- pom.xml | 2 +- .../levelledmobs/listeners/EntitySpawnListener.java | 10 ++++++++-- .../me/lokka30/levelledmobs/managers/LevelManager.java | 4 ---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 399e5aae7..8afc478a6 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ me.lokka30 LevelledMobs - 3.2.4 b552 + 3.2.4 b554 jar LevelledMobs diff --git a/src/main/java/me/lokka30/levelledmobs/listeners/EntitySpawnListener.java b/src/main/java/me/lokka30/levelledmobs/listeners/EntitySpawnListener.java index 6d14e7c0a..9bd7ea0eb 100644 --- a/src/main/java/me/lokka30/levelledmobs/listeners/EntitySpawnListener.java +++ b/src/main/java/me/lokka30/levelledmobs/listeners/EntitySpawnListener.java @@ -254,8 +254,14 @@ else if (main.configUtils.playerLevellingEnabled){ final HashSet additionalLevelInfo = new HashSet<>(Collections.singletonList(additionalInfo)); final LevellableState levellableState = getLevellableState(lmEntity, event); if (levellableState == LevellableState.ALLOWED) { - if (lmEntity.reEvaluateLevel && main.configUtils.playerLevellingEnabled) - updateMobForPlayerLevelling(lmEntity); + if (lmEntity.reEvaluateLevel && main.configUtils.playerLevellingEnabled) { + final Object syncObj = new Object(); + final BukkitRunnable runnable = new BukkitRunnable() { + @Override + public void run() { updateMobForPlayerLevelling(lmEntity); } + }; + runnable.runTask(main); + } main.levelInterface.applyLevelToMob(lmEntity, main.levelInterface.generateLevel(lmEntity), false, false, additionalLevelInfo); diff --git a/src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java b/src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java index 7ae49c086..b1b283250 100644 --- a/src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java +++ b/src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java @@ -1154,10 +1154,6 @@ else if (lmEntity.getLivingEntity() instanceof Horse) lmEntity.inUseCount.getAndIncrement(); applyAttribs.runTask(main); -// final List nametagVisibilityEnums = main.rulesManager.getRule_CreatureNametagVisbility(lmEntity); -// if (nametagVisibilityEnums.contains(NametagVisibilityEnum.TARGETED)) -// getPlayersNearMob(lmEntity); - if (!skipLM_Nametag) main.levelManager.updateNametag_WithDelay(lmEntity); main.levelManager.applyLevelledEquipment(lmEntity, lmEntity.getMobLevel()); From ab6f32f8613f81ab5b7b7926f656055daded691e Mon Sep 17 00:00:00 2001 From: stumper66 Date: Thu, 4 Nov 2021 02:17:43 -0500 Subject: [PATCH 07/10] 3.2.4 b555 * EliteMobs is once again compatible starting with version 7.3.9 --- pom.xml | 2 +- .../ExternalCompatibilityManager.java | 33 +++++++++---------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/pom.xml b/pom.xml index 8afc478a6..c923ae969 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ me.lokka30 LevelledMobs - 3.2.4 b554 + 3.2.4 b555 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 a8ed9f665..fc5177918 100644 --- a/src/main/java/me/lokka30/levelledmobs/managers/ExternalCompatibilityManager.java +++ b/src/main/java/me/lokka30/levelledmobs/managers/ExternalCompatibilityManager.java @@ -179,7 +179,7 @@ public static String getMythicMobInternalName(@NotNull final LivingEntityWrapper return ""; } - public static LevellableState checkAllExternalCompats(final LivingEntityWrapper lmEntity, final LevelledMobs main){ + public static LevellableState checkAllExternalCompats(final LivingEntityWrapper lmEntity, final @NotNull LevelledMobs main){ final Map compatRules = main.rulesManager.getRule_ExternalCompatibility(lmEntity); LevellableState result = LevellableState.ALLOWED; @@ -280,26 +280,23 @@ public static boolean isMobOfMythicMobs(final LivingEntityWrapper lmEntity) { * @param lmEntity mob to check * @return if EliteMobs compatibility enabled and entity is from EliteMobs */ - public static boolean isMobOfEliteMobs(final LivingEntityWrapper lmEntity) { - final boolean isExternalType1 = - lmEntity.getLivingEntity().hasMetadata("Elitemob"); - final boolean isExternalType2 = - lmEntity.getLivingEntity().hasMetadata("Elitemobs_NPC"); - final boolean isExternalType3 = - lmEntity.getLivingEntity().hasMetadata("Supermob"); - - if (isExternalType1) lmEntity.setMobExternalType(ExternalCompatibility.ELITE_MOBS); - else if (isExternalType2) lmEntity.setMobExternalType(ExternalCompatibility.ELITE_MOBS_NPCS); - else if (isExternalType3) lmEntity.setMobExternalType(ExternalCompatibility.ELITE_MOBS_SUPER_MOBS); - - return (isExternalType1 || isExternalType2 || isExternalType3); + public static boolean isMobOfEliteMobs(final @NotNull LivingEntityWrapper lmEntity) { + final Plugin p = Bukkit.getPluginManager().getPlugin("EliteMobs"); + if (p != null){ + if (lmEntity.getPDC().has(new NamespacedKey(p, "EliteMobsCullable"), PersistentDataType.STRING)){ + lmEntity.setMobExternalType(ExternalCompatibility.ELITE_MOBS); + return true; + } + } + + return false; } /** * @param lmEntity mob to check * @return if InfernalMobs compatibility enabled and entity is from InfernalMobs */ - public static boolean isMobOfInfernalMobs(final LivingEntityWrapper lmEntity) { + public static boolean isMobOfInfernalMobs(final @NotNull LivingEntityWrapper lmEntity) { final boolean isExternalType = lmEntity.getLivingEntity().hasMetadata("infernalMetadata"); if (isExternalType) lmEntity.setMobExternalType(ExternalCompatibility.INFERNAL_MOBS); @@ -311,7 +308,7 @@ public static boolean isMobOfInfernalMobs(final LivingEntityWrapper lmEntity) { * @param lmEntity mob to check * @return if Citizens compatibility enabled and entity is from Citizens */ - public static boolean isMobOfCitizens(final LivingEntityWrapper lmEntity) { + public static boolean isMobOfCitizens(final @NotNull LivingEntityWrapper lmEntity) { final boolean isExternalType = isMobOfCitizens(lmEntity.getLivingEntity()); if (isExternalType) lmEntity.setMobExternalType(ExternalCompatibility.CITIZENS); @@ -319,7 +316,7 @@ public static boolean isMobOfCitizens(final LivingEntityWrapper lmEntity) { return isExternalType; } - public static boolean isMobOfCitizens(final LivingEntity livingEntity) { + public static boolean isMobOfCitizens(final @NotNull LivingEntity livingEntity) { return livingEntity.hasMetadata("NPC"); } @@ -327,7 +324,7 @@ public static boolean isMobOfCitizens(final LivingEntity livingEntity) { * @param lmEntity mob to check * @return if Shopkeepers compatibility enabled and entity is from Shopkeepers */ - public static boolean isMobOfShopkeepers(final LivingEntityWrapper lmEntity) { + public static boolean isMobOfShopkeepers(final @NotNull LivingEntityWrapper lmEntity) { final boolean isExternalType = lmEntity.getLivingEntity().hasMetadata("shopkeeper"); if (isExternalType) lmEntity.setMobExternalType(ExternalCompatibility.SHOPKEEPERS); From 8dad67b43b9db13f80d47afa95b8cd4448417c3c Mon Sep 17 00:00:00 2001 From: stumper66 Date: Thu, 4 Nov 2021 02:22:54 -0500 Subject: [PATCH 08/10] Update ExternalCompatibilityManager.java --- .../managers/ExternalCompatibilityManager.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/lokka30/levelledmobs/managers/ExternalCompatibilityManager.java b/src/main/java/me/lokka30/levelledmobs/managers/ExternalCompatibilityManager.java index fc5177918..c185f43d1 100644 --- a/src/main/java/me/lokka30/levelledmobs/managers/ExternalCompatibilityManager.java +++ b/src/main/java/me/lokka30/levelledmobs/managers/ExternalCompatibilityManager.java @@ -283,7 +283,12 @@ public static boolean isMobOfMythicMobs(final LivingEntityWrapper lmEntity) { public static boolean isMobOfEliteMobs(final @NotNull LivingEntityWrapper lmEntity) { final Plugin p = Bukkit.getPluginManager().getPlugin("EliteMobs"); if (p != null){ - if (lmEntity.getPDC().has(new NamespacedKey(p, "EliteMobsCullable"), PersistentDataType.STRING)){ + boolean isEliteMob; + synchronized (lmEntity.getLivingEntity().getPersistentDataContainer()) { + isEliteMob = lmEntity.getPDC().has(new NamespacedKey(p, "EliteMobsCullable"), PersistentDataType.STRING); + } + + if (isEliteMob){ lmEntity.setMobExternalType(ExternalCompatibility.ELITE_MOBS); return true; } From 35ad54d97f32694a8673b1b8a815f3a2b23ec058 Mon Sep 17 00:00:00 2001 From: stumper66 Date: Thu, 4 Nov 2021 16:23:45 -0500 Subject: [PATCH 09/10] 3.2.4 b556 * fixed for potential exception relating to nametagVisibilityEnum --- pom.xml | 2 +- .../me/lokka30/levelledmobs/misc/LivingEntityWrapper.java | 5 +++-- .../java/me/lokka30/levelledmobs/rules/RulesManager.java | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index c923ae969..cf4aa8bbe 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ me.lokka30 LevelledMobs - 3.2.4 b555 + 3.2.4 b556 jar LevelledMobs diff --git a/src/main/java/me/lokka30/levelledmobs/misc/LivingEntityWrapper.java b/src/main/java/me/lokka30/levelledmobs/misc/LivingEntityWrapper.java index 6d37b1920..a38999b12 100644 --- a/src/main/java/me/lokka30/levelledmobs/misc/LivingEntityWrapper.java +++ b/src/main/java/me/lokka30/levelledmobs/misc/LivingEntityWrapper.java @@ -67,7 +67,7 @@ public LivingEntityWrapper(final @NotNull LivingEntity livingEntity, final @NotN private Integer mobLevel; private final static Object lockObj = new Object(); @NotNull - private List applicableRules; + private final List applicableRules; private List spawnedWGRegions; @NotNull private final List mobExternalTypes; @@ -171,7 +171,8 @@ private void buildCache(){ // the lines below must remain after hasCache = true to prevent stack overflow cachePrevChanceResults(); final ApplicableRulesResult applicableRulesResult = main.rulesManager.getApplicableRules(this); - this.applicableRules = applicableRulesResult.allApplicableRules; + this.applicableRules.clear(); + this.applicableRules.addAll(applicableRulesResult.allApplicableRules); checkChanceRules(applicableRulesResult); this.fineTuningAttributes = main.rulesManager.getFineTuningAttributes(this); this.nametagCooldownTime = main.rulesManager.getRule_nametagVisibleTime(this); diff --git a/src/main/java/me/lokka30/levelledmobs/rules/RulesManager.java b/src/main/java/me/lokka30/levelledmobs/rules/RulesManager.java index 16d8528e2..59576aaae 100644 --- a/src/main/java/me/lokka30/levelledmobs/rules/RulesManager.java +++ b/src/main/java/me/lokka30/levelledmobs/rules/RulesManager.java @@ -358,6 +358,7 @@ public List getRule_CreatureNametagVisbility(@NotNull fin List result = null; for (final RuleInfo ruleInfo : lmEntity.getApplicableRules()){ + if (ruleInfo == null) continue; if (ruleInfo.nametagVisibilityEnum != null) result = ruleInfo.nametagVisibilityEnum; } From 1950080a43cc3a6c1bb4b813e9e986439fde35e1 Mon Sep 17 00:00:00 2001 From: stumper66 Date: Thu, 4 Nov 2021 21:43:42 -0500 Subject: [PATCH 10/10] 3.2.4 b557 * fixed player levelling mostly broken since 3.2.4 dev builds --- pom.xml | 2 +- .../levelledmobs/commands/subcommands/RulesSubcommand.java | 1 + .../me/lokka30/levelledmobs/listeners/EntitySpawnListener.java | 2 +- .../java/me/lokka30/levelledmobs/misc/LivingEntityWrapper.java | 2 ++ 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index cf4aa8bbe..7dc310673 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ me.lokka30 LevelledMobs - 3.2.4 b556 + 3.2.4 b557 jar LevelledMobs diff --git a/src/main/java/me/lokka30/levelledmobs/commands/subcommands/RulesSubcommand.java b/src/main/java/me/lokka30/levelledmobs/commands/subcommands/RulesSubcommand.java index e46b91b79..3dbba39d4 100644 --- a/src/main/java/me/lokka30/levelledmobs/commands/subcommands/RulesSubcommand.java +++ b/src/main/java/me/lokka30/levelledmobs/commands/subcommands/RulesSubcommand.java @@ -140,6 +140,7 @@ private void forceRelevel(final CommandSender sender, final String label, @NotNu entityCount++; final LivingEntityWrapper lmEntity = LivingEntityWrapper.getInstance((LivingEntity) entity, main); lmEntity.reEvaluateLevel = true; + lmEntity.isRulesForceAll = true; lmEntity.wasPreviouslyLevelled = lmEntity.isLevelled(); main._mobsQueueManager.addToQueue(new QueueItem(lmEntity, null)); lmEntity.free(); diff --git a/src/main/java/me/lokka30/levelledmobs/listeners/EntitySpawnListener.java b/src/main/java/me/lokka30/levelledmobs/listeners/EntitySpawnListener.java index 9bd7ea0eb..00522ec3c 100644 --- a/src/main/java/me/lokka30/levelledmobs/listeners/EntitySpawnListener.java +++ b/src/main/java/me/lokka30/levelledmobs/listeners/EntitySpawnListener.java @@ -243,7 +243,7 @@ public void preprocessMob(final @NotNull LivingEntityWrapper lmEntity, @NotNull if (!lmEntity.reEvaluateLevel) lmEntity.setSpawnReason(spawnReason); - else if (main.configUtils.playerLevellingEnabled){ + else if (main.configUtils.playerLevellingEnabled && lmEntity.isRulesForceAll){ synchronized (lmEntity.getLivingEntity().getPersistentDataContainer()){ if (lmEntity.getPDC().has(main.namespaced_keys.playerLevelling_Id, PersistentDataType.STRING)) lmEntity.getPDC().remove(main.namespaced_keys.playerLevelling_Id); diff --git a/src/main/java/me/lokka30/levelledmobs/misc/LivingEntityWrapper.java b/src/main/java/me/lokka30/levelledmobs/misc/LivingEntityWrapper.java index a38999b12..d4e3ee4bb 100644 --- a/src/main/java/me/lokka30/levelledmobs/misc/LivingEntityWrapper.java +++ b/src/main/java/me/lokka30/levelledmobs/misc/LivingEntityWrapper.java @@ -76,6 +76,7 @@ public LivingEntityWrapper(final @NotNull LivingEntity livingEntity, final @NotN public EntityDamageEvent.DamageCause deathCause; public boolean reEvaluateLevel; public boolean wasPreviouslyLevelled; + public boolean isRulesForceAll; public Player playerForPermissionsCheck; public CommandSender summonedSender; public String nbtData; @@ -137,6 +138,7 @@ public void clearEntityData(){ this.spawnedWGRegions = null; this.fineTuningAttributes = null; this.reEvaluateLevel = false; + this.isRulesForceAll = false; this.wasPreviouslyLevelled = false; this.groupsAreBuilt = false; this.playerForLevelling = null;