Skip to content

Commit

Permalink
Merge pull request #412 from lokka30/3.7-dev
Browse files Browse the repository at this point in the history
v3.7.2 b695
  • Loading branch information
lokka30 authored Sep 15, 2022
2 parents 3dd05e7 + 9ad751b commit cf7af45
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 41 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.lokka30</groupId>
<artifactId>LevelledMobs</artifactId>
<version>3.7.1 b694</version>
<version>3.7.2 b695</version>
<packaging>jar</packaging>
<name>LevelledMobs</name>
<description>The Ultimate RPG Mob Levelling Plugin</description>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
52 changes: 25 additions & 27 deletions src/main/java/me/lokka30/levelledmobs/managers/LevelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/me/lokka30/levelledmobs/nms/NMSHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit cf7af45

Please sign in to comment.