From e92ebfbb3b39a1f223d7761af234b29a68bff43f Mon Sep 17 00:00:00 2001 From: EvModder Date: Sat, 22 Oct 2022 20:33:28 -0700 Subject: [PATCH 1/4] Preserve vanilla death message behavior (showing hover-selector for the killed player) -- This fixes compatibility issues with out plugins that expect to see the player UUID in the death message component --- .../listeners/paper/PlayerDeathListener.java | 37 +++---------------- 1 file changed, 5 insertions(+), 32 deletions(-) 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..46c75259b 100644 --- a/src/main/java/me/lokka30/levelledmobs/listeners/paper/PlayerDeathListener.java +++ b/src/main/java/me/lokka30/levelledmobs/listeners/paper/PlayerDeathListener.java @@ -100,13 +100,11 @@ 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)) { + // This can happen if another plugin destructively changes the death message. return; } - final String playerKilled = extractPlayerName(tc); - if (playerKilled == null) { - return; - } + final UUID playerKilled = event.getEntity().getUniqueId(); String mobKey = null; Component itemComp = null; @@ -149,7 +147,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), + Component.selector(playerKilled.toString()), leftComp.append(mobNameComponent) ).append(rightComp); } @@ -157,7 +155,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), + Component.selector(playerKilled.toString()), leftComp.append(mobNameComponent), itemComp ).append(rightComp); @@ -166,29 +164,4 @@ 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(); - } - } - - return playerKilled == null || playerKilled.isEmpty() ? - null : playerKilled; - } -} +} \ No newline at end of file From 3a76b182d24d96ababa9389bafca0d1566bac746 Mon Sep 17 00:00:00 2001 From: Penal Buffalo Date: Sun, 23 Oct 2022 11:29:27 -0500 Subject: [PATCH 2/4] v3.8.2 b719 * preserve vanilla death message behavior for better 3rd party plugin compatibility (Thanks EvModder for PR #419) --- pom.xml | 2 +- .../listeners/paper/PlayerDeathListener.java | 28 ++++++++++++++----- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 3d5b9acc2..78e731eef 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.lokka30 LevelledMobs - 3.8.1 b718 + 3.8.2 b719 jar LevelledMobs The Ultimate RPG Mob Levelling Plugin 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 46c75259b..b506f6960 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,13 @@ 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.key.Keyed; +import net.kyori.adventure.key.KeyedValue; 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; @@ -104,8 +108,6 @@ private void updateDeathMessage(final @NotNull PlayerDeathEvent event, final @No return; } - final UUID playerKilled = event.getEntity().getUniqueId(); - String mobKey = null; Component itemComp = null; for (final Component c : tc.args()){ @@ -127,8 +129,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}"); @@ -147,7 +151,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.selector(playerKilled.toString()), + buildPlayerComponent(event.getEntity()), leftComp.append(mobNameComponent) ).append(rightComp); } @@ -155,7 +159,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.selector(playerKilled.toString()), + buildPlayerComponent(event.getEntity()), leftComp.append(mobNameComponent), itemComp ).append(rightComp); @@ -164,4 +168,14 @@ private void updateDeathMessage(final @NotNull PlayerDeathEvent event, final @No event.deathMessage(newCom); } + + private @NotNull Component buildPlayerComponent(final @NotNull Player player){ + final Keyed playerKey = KeyedValue.keyedValue(Key.key("player"), player); + final HoverEvent hoverEvent = HoverEvent.showEntity( + playerKey, player.getUniqueId(), player.name()); + final ClickEvent clickEvent = ClickEvent.clickEvent(ClickEvent.Action.SUGGEST_COMMAND, + "/tell " + player.getName() + " "); + + return Component.text(player.getName()).clickEvent(clickEvent).hoverEvent(hoverEvent); + } } \ No newline at end of file From d4e99814d62095b1b597d57b807674bea52f7488 Mon Sep 17 00:00:00 2001 From: Penal Buffalo Date: Sun, 23 Oct 2022 17:41:14 -0500 Subject: [PATCH 3/4] v3.8.2 b720 * fix an issue affecting 1.16.5 servers when using player levelling --- pom.xml | 2 +- .../java/me/lokka30/levelledmobs/managers/LevelManager.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 78e731eef..7b2b023b6 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.lokka30 LevelledMobs - 3.8.2 b719 + 3.8.2 b720 jar LevelledMobs The Ultimate RPG Mob Levelling Plugin 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; } From e405887bb131ddfd21e8bb61a53bfce943e544a6 Mon Sep 17 00:00:00 2001 From: Penal Buffalo Date: Tue, 25 Oct 2022 22:07:01 -0500 Subject: [PATCH 4/4] v3.8.2 b721 * make b719 changes compatible with MC 1.16 and 1.17 * fix slime using spawn reason `SLIME_SPLIT` instead of `SPAWNER` when the grand parent was from a spawner --- pom.xml | 2 +- .../listeners/EntityTransformListener.java | 17 +++++++++++++---- .../listeners/paper/PlayerDeathListener.java | 7 +++---- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 7b2b023b6..a29c55494 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.lokka30 LevelledMobs - 3.8.2 b720 + 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 b506f6960..bcd382ff6 100644 --- a/src/main/java/me/lokka30/levelledmobs/listeners/paper/PlayerDeathListener.java +++ b/src/main/java/me/lokka30/levelledmobs/listeners/paper/PlayerDeathListener.java @@ -5,8 +5,6 @@ import me.lokka30.levelledmobs.result.NametagResult; import me.lokka30.levelledmobs.util.Utils; import net.kyori.adventure.key.Key; -import net.kyori.adventure.key.Keyed; -import net.kyori.adventure.key.KeyedValue; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextReplacementConfig; import net.kyori.adventure.text.TranslatableComponent; @@ -170,9 +168,10 @@ private void updateDeathMessage(final @NotNull PlayerDeathEvent event, final @No } private @NotNull Component buildPlayerComponent(final @NotNull Player player){ - final Keyed playerKey = KeyedValue.keyedValue(Key.key("player"), player); + final Component playerName = main.nametagQueueManager.nmsHandler.versionInfo.getMinecraftVersion() >= 1.18 ? + player.name() : Component.text(player.getName()); final HoverEvent hoverEvent = HoverEvent.showEntity( - playerKey, player.getUniqueId(), player.name()); + Key.key("minecraft"), player.getUniqueId(), playerName); final ClickEvent clickEvent = ClickEvent.clickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/tell " + player.getName() + " ");