diff --git a/pom.xml b/pom.xml index 3d5b9acc2..a29c55494 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.lokka30 LevelledMobs - 3.8.1 b718 + 3.8.2 b721 jar LevelledMobs The Ultimate RPG Mob Levelling Plugin diff --git a/src/main/java/me/lokka30/levelledmobs/listeners/EntityTransformListener.java b/src/main/java/me/lokka30/levelledmobs/listeners/EntityTransformListener.java index b01111675..f3d479a44 100644 --- a/src/main/java/me/lokka30/levelledmobs/listeners/EntityTransformListener.java +++ b/src/main/java/me/lokka30/levelledmobs/listeners/EntityTransformListener.java @@ -20,7 +20,6 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.entity.EntityTransformEvent; import org.jetbrains.annotations.NotNull; @@ -91,6 +90,10 @@ public void onTransform(@NotNull final EntityTransformEvent event) { } if (useInheritance) { + if (lmEntity.getSpawnReason() == LevelledMobSpawnReason.LM_SPAWNER) { + transformedLmEntity.setSpawnReason(LevelledMobSpawnReason.SPAWNER); + } + main.levelInterface.applyLevelToMob( transformedLmEntity, level, @@ -112,15 +115,21 @@ public void onTransform(@NotNull final EntityTransformEvent event) { } private void checkForSlimeSplit(final @NotNull LivingEntity livingEntity, final @NotNull List transformedEntities){ - if (livingEntity.getEntitySpawnReason() == CreatureSpawnEvent.SpawnReason.DEFAULT) return; - final LevelledMobSpawnReason spawnReason = Utils.adaptVanillaSpawnReason(livingEntity.getEntitySpawnReason()); + final LivingEntityWrapper parent = LivingEntityWrapper.getInstance(livingEntity, main); + if (parent.getSpawnReason() == LevelledMobSpawnReason.DEFAULT || + parent.getSpawnReason() == LevelledMobSpawnReason.SLIME_SPLIT){ + parent.free(); + return; + } for (final Entity transformedEntity : transformedEntities) { if (!(transformedEntity instanceof final LivingEntity le)) continue; final LivingEntityWrapper lew = LivingEntityWrapper.getInstance(le, main); - lew.setSpawnReason(spawnReason); + lew.setSpawnReason(parent.getSpawnReason()); lew.free(); } + + parent.free(); } } 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 1bfb9e690..bcd382ff6 100644 --- a/src/main/java/me/lokka30/levelledmobs/listeners/paper/PlayerDeathListener.java +++ b/src/main/java/me/lokka30/levelledmobs/listeners/paper/PlayerDeathListener.java @@ -4,9 +4,11 @@ import me.lokka30.levelledmobs.misc.LivingEntityWrapper; import me.lokka30.levelledmobs.result.NametagResult; import me.lokka30.levelledmobs.util.Utils; +import net.kyori.adventure.key.Key; import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.TextReplacementConfig; import net.kyori.adventure.text.TranslatableComponent; +import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.bukkit.entity.Entity; @@ -100,11 +102,7 @@ public boolean onPlayerDeathEvent(final @NotNull PlayerDeathEvent event) { private void updateDeathMessage(final @NotNull PlayerDeathEvent event, final @NotNull NametagResult nametagResult) { if (!(event.deathMessage() instanceof final TranslatableComponent tc)) { - return; - } - - final String playerKilled = extractPlayerName(tc); - if (playerKilled == null) { + // This can happen if another plugin destructively changes the death message. return; } @@ -129,8 +127,10 @@ private void updateDeathMessage(final @NotNull PlayerDeathEvent event, final @No Component newCom; if (nametagResult.hadCustomDeathMessage){ - newCom = LegacyComponentSerializer.legacyAmpersand().deserialize( - mobName.replace("%player%", playerKilled)); + final TextReplacementConfig replacementConfig = TextReplacementConfig.builder().matchLiteral("%player%") + .replacement(buildPlayerComponent(event.getEntity())).build(); + newCom = LegacyComponentSerializer.legacyAmpersand().deserialize(mobName) + .replaceText(replacementConfig); } else { final int displayNameIndex = mobName.indexOf("{DisplayName}"); @@ -149,7 +149,7 @@ private void updateDeathMessage(final @NotNull PlayerDeathEvent event, final @No // mob wasn't using any weapon // 2 arguments, example: "death.attack.mob": "%1$s was slain by %2$s" newCom = Component.translatable(tc.key(), - Component.text(playerKilled), + buildPlayerComponent(event.getEntity()), leftComp.append(mobNameComponent) ).append(rightComp); } @@ -157,7 +157,7 @@ private void updateDeathMessage(final @NotNull PlayerDeathEvent event, final @No // mob had a weapon and it's details are stored in the itemComp component // 3 arguments, example: "death.attack.mob.item": "%1$s was slain by %2$s using %3$s" newCom = Component.translatable(tc.key(), - Component.text(playerKilled), + buildPlayerComponent(event.getEntity()), leftComp.append(mobNameComponent), itemComp ).append(rightComp); @@ -167,28 +167,14 @@ private void updateDeathMessage(final @NotNull PlayerDeathEvent event, final @No event.deathMessage(newCom); } - @Nullable private String extractPlayerName(final @NotNull TranslatableComponent tc) { - String playerKilled = null; - - for (final Component com : tc.args()) { - if (!(com instanceof final TextComponent tc2)) continue; - playerKilled = tc2.content(); - - if (playerKilled.isEmpty() && tc2.hoverEvent() == null) continue; - - // 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 final HoverEvent.ShowEntity se)) { - return null; - } - - if (se.name() instanceof final TextComponent tc3) { - playerKilled = tc3.content(); - } - } + private @NotNull Component buildPlayerComponent(final @NotNull Player player){ + final Component playerName = main.nametagQueueManager.nmsHandler.versionInfo.getMinecraftVersion() >= 1.18 ? + player.name() : Component.text(player.getName()); + final HoverEvent hoverEvent = HoverEvent.showEntity( + Key.key("minecraft"), player.getUniqueId(), playerName); + final ClickEvent clickEvent = ClickEvent.clickEvent(ClickEvent.Action.SUGGEST_COMMAND, + "/tell " + player.getName() + " "); - return playerKilled == null || playerKilled.isEmpty() ? - null : playerKilled; + return Component.text(player.getName()).clickEvent(clickEvent).hoverEvent(hoverEvent); } -} +} \ No newline at end of file diff --git a/src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java b/src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java index 5c4f7c532..4472244a2 100644 --- a/src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java +++ b/src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java @@ -1063,7 +1063,7 @@ private boolean checkIfReadyForRelevelling(final @NotNull LivingEntityWrapper lm return true; } - if (!lmEntity.getPDC().has(main.namespacedKeys.lastDamageTime)){ + if (!lmEntity.getPDC().has(main.namespacedKeys.lastDamageTime, PersistentDataType.LONG)){ return true; }