From 9ad751b415f7e16eccd42ac3a68944165ceb3db5 Mon Sep 17 00:00:00 2001 From: Penal Buffalo Date: Wed, 14 Sep 2022 15:35:32 -0500 Subject: [PATCH] v3.7.2 b695 * fixed player death messages on Paper servers being out of order --- pom.xml | 2 +- .../subcommands/SummonMobOptions.java | 1 - .../listeners/paper/PlayerDeathListener.java | 24 +++++---- .../levelledmobs/managers/LevelManager.java | 52 +++++++++---------- .../lokka30/levelledmobs/nms/NMSHandler.java | 1 - 5 files changed, 39 insertions(+), 41 deletions(-) diff --git a/pom.xml b/pom.xml index c9369a164..044724fa3 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.lokka30 LevelledMobs - 3.7.1 b694 + 3.7.2 b695 jar LevelledMobs The Ultimate RPG Mob Levelling Plugin diff --git a/src/main/java/me/lokka30/levelledmobs/commands/subcommands/SummonMobOptions.java b/src/main/java/me/lokka30/levelledmobs/commands/subcommands/SummonMobOptions.java index 1a0234920..c93aae787 100644 --- a/src/main/java/me/lokka30/levelledmobs/commands/subcommands/SummonMobOptions.java +++ b/src/main/java/me/lokka30/levelledmobs/commands/subcommands/SummonMobOptions.java @@ -1,6 +1,5 @@ package me.lokka30.levelledmobs.commands.subcommands; -import me.lokka30.levelledmobs.misc.LivingEntityPlaceholder; import me.lokka30.levelledmobs.misc.LivingEntityPlaceholder; import me.lokka30.levelledmobs.misc.RequestedLevel; import org.bukkit.command.CommandSender; 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 ad7ccd82a..f92422ef0 100644 --- a/src/main/java/me/lokka30/levelledmobs/listeners/paper/PlayerDeathListener.java +++ b/src/main/java/me/lokka30/levelledmobs/listeners/paper/PlayerDeathListener.java @@ -6,7 +6,6 @@ import me.lokka30.levelledmobs.util.Utils; 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.HoverEvent; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; @@ -118,28 +117,31 @@ private void updateDeathMessage(final @NotNull PlayerDeathEvent event, final @No if (mobKey == null) return; final String mobName = nametagResult.getNametagNonNull(); - final Component playerName = event.getPlayer().displayName(); Component newCom; if (nametagResult.hadCustomDeathMessage){ newCom = Component.empty(); } else { - // this component holds the component of the mob name and will show the translated name on clients + final int displayNameIndex = mobName.indexOf("{DisplayName}"); + final Component leftComp = displayNameIndex > 0 ? + LegacyComponentSerializer.legacyAmpersand().deserialize(mobName.substring(0, displayNameIndex)) : + Component.empty(); + final Component rightComp = mobName.length() > displayNameIndex + 13 ? + LegacyComponentSerializer.legacyAmpersand().deserialize(mobName.substring(displayNameIndex + 13)) : + Component.empty(); + final Component mobNameComponent = nametagResult.overriddenName == null ? Component.translatable(mobKey) : LegacyComponentSerializer.legacyAmpersand().deserialize(nametagResult.overriddenName); - newCom = Component.translatable(tc.key(), Component.text(playerKilled), mobNameComponent); + newCom = Component.translatable(tc.key(), + Component.text(playerKilled), + leftComp.append(mobNameComponent) + ).append(rightComp); } - // replace placeholders and set the new death message - event.deathMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(mobName) - .replaceText(TextReplacementConfig.builder() - .matchLiteral("%player%").replacement(playerName).build()) - .replaceText(TextReplacementConfig.builder() - .matchLiteral("{DisplayName}").replacement(newCom).build()) - ); + event.deathMessage(newCom); } @Nullable private String extractPlayerName(final @NotNull TranslatableComponent tc) { diff --git a/src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java b/src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java index 1bbf309fe..3d37d5dd1 100644 --- a/src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java +++ b/src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java @@ -723,33 +723,6 @@ public int getLevelledExpDrops(@NotNull final LivingEntityWrapper lmEntity, fina return updateNametag(lmEntity, nametag, useCustomNameForNametags, preserveMobName, hadCustomDeathMessage); } - private void checkLockedNametag(final @NotNull LivingEntityWrapper lmEntity) { - synchronized (lmEntity.getPDC()) { - Integer doLockSettings; - if (lmEntity.getPDC() - .has(main.namespacedKeys.lockSettings, PersistentDataType.INTEGER)) { - doLockSettings = lmEntity.getPDC() - .get(main.namespacedKeys.lockSettings, PersistentDataType.INTEGER); - if (doLockSettings == null || doLockSettings != 1) { - return; - } - } else { - return; - } - - if (lmEntity.getPDC() - .has(main.namespacedKeys.lockedNametag, PersistentDataType.STRING)) { - lmEntity.lockedNametag = lmEntity.getPDC() - .get(main.namespacedKeys.lockedNametag, PersistentDataType.STRING); - } - if (lmEntity.getPDC() - .has(main.namespacedKeys.lockedNameOverride, PersistentDataType.STRING)) { - lmEntity.lockedOverrideName = lmEntity.getPDC() - .get(main.namespacedKeys.lockedNameOverride, PersistentDataType.STRING); - } - } - } - @NotNull public NametagResult updateNametag(final @NotNull LivingEntityWrapper lmEntity, @NotNull String nametag, final boolean useCustomNameForNametags) { return updateNametag(lmEntity, nametag, useCustomNameForNametags, false, false); @@ -804,7 +777,32 @@ else if (!hasOverridenName) return result; } + private void checkLockedNametag(final @NotNull LivingEntityWrapper lmEntity) { + synchronized (lmEntity.getPDC()) { + Integer doLockSettings; + if (lmEntity.getPDC() + .has(main.namespacedKeys.lockSettings, PersistentDataType.INTEGER)) { + doLockSettings = lmEntity.getPDC() + .get(main.namespacedKeys.lockSettings, PersistentDataType.INTEGER); + if (doLockSettings == null || doLockSettings != 1) { + return; + } + } else { + return; + } + if (lmEntity.getPDC() + .has(main.namespacedKeys.lockedNametag, PersistentDataType.STRING)) { + lmEntity.lockedNametag = lmEntity.getPDC() + .get(main.namespacedKeys.lockedNametag, PersistentDataType.STRING); + } + if (lmEntity.getPDC() + .has(main.namespacedKeys.lockedNameOverride, PersistentDataType.STRING)) { + lmEntity.lockedOverrideName = lmEntity.getPDC() + .get(main.namespacedKeys.lockedNameOverride, PersistentDataType.STRING); + } + } + } public @NotNull String replaceStringPlaceholders(final @NotNull String nametag, @NotNull final LivingEntityWrapper lmEntity, final boolean usePAPI) { diff --git a/src/main/java/me/lokka30/levelledmobs/nms/NMSHandler.java b/src/main/java/me/lokka30/levelledmobs/nms/NMSHandler.java index f0709b743..5f1423335 100644 --- a/src/main/java/me/lokka30/levelledmobs/nms/NMSHandler.java +++ b/src/main/java/me/lokka30/levelledmobs/nms/NMSHandler.java @@ -5,7 +5,6 @@ import me.lokka30.levelledmobs.LevelledMobs; import me.lokka30.levelledmobs.managers.ExternalCompatibilityManager; import me.lokka30.levelledmobs.util.Utils; -import me.lokka30.microlib.messaging.MessageUtils; import me.lokka30.microlib.other.VersionUtils; import org.bukkit.Bukkit; import org.jetbrains.annotations.NotNull;