Skip to content

Commit

Permalink
Merge branch '3.8-dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
lokka30 committed Oct 27, 2022
2 parents c87939b + e405887 commit 74859d9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 39 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.8.1 b718</version>
<version>3.8.2 b721</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
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -112,15 +115,21 @@ public void onTransform(@NotNull final EntityTransformEvent event) {
}

private void checkForSlimeSplit(final @NotNull LivingEntity livingEntity, final @NotNull List<Entity> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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}");
Expand All @@ -149,15 +149,15 @@ 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);
}
else {
// 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);
Expand All @@ -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.ShowEntity> 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 74859d9

Please sign in to comment.