mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-13 10:21:13 +01:00
a207d14a0e
Signed-off-by: Mariell Hoversholm <proximyst@proximyst.com>
41 lines
2.2 KiB
Diff
41 lines
2.2 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
Date: Sun, 5 Jul 2020 00:33:54 -0700
|
|
Subject: [PATCH] added PlayerNameEntityEvent
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/item/NameTagItem.java b/src/main/java/net/minecraft/world/item/NameTagItem.java
|
|
index 5e38077c3de0a40f3cfd856bf2e48f7061e39a9d..5c575798c20f15d28350f767ecf15bfc042ebc8c 100644
|
|
--- a/src/main/java/net/minecraft/world/item/NameTagItem.java
|
|
+++ b/src/main/java/net/minecraft/world/item/NameTagItem.java
|
|
@@ -1,5 +1,10 @@
|
|
package net.minecraft.world.item;
|
|
|
|
+// Paper start
|
|
+import io.papermc.paper.adventure.PaperAdventure;
|
|
+import io.papermc.paper.event.player.PlayerNameEntityEvent;
|
|
+// Paper end
|
|
+import net.minecraft.server.level.ServerPlayer;
|
|
import net.minecraft.world.InteractionHand;
|
|
import net.minecraft.world.InteractionResult;
|
|
import net.minecraft.world.entity.LivingEntity;
|
|
@@ -16,11 +21,15 @@ public class NameTagItem extends Item {
|
|
public InteractionResult interactLivingEntity(ItemStack stack, Player user, LivingEntity entity, InteractionHand hand) {
|
|
if (stack.hasCustomHoverName() && !(entity instanceof Player)) {
|
|
if (!user.level.isClientSide && entity.isAlive()) {
|
|
- entity.setCustomName(stack.getHoverName());
|
|
- if (entity instanceof Mob) {
|
|
- ((Mob) entity).setPersistenceRequired();
|
|
+ // Paper start
|
|
+ PlayerNameEntityEvent event = new PlayerNameEntityEvent(((ServerPlayer) user).getBukkitEntity(), entity.getBukkitLivingEntity(), PaperAdventure.asAdventure(stack.getHoverName()), true);
|
|
+ if (!event.callEvent()) return InteractionResult.PASS;
|
|
+ LivingEntity newEntityLiving = ((org.bukkit.craftbukkit.entity.CraftLivingEntity) event.getEntity()).getHandle();
|
|
+ newEntityLiving.setCustomName(event.getName() != null ? PaperAdventure.asVanilla(event.getName()) : null);
|
|
+ if (event.isPersistent() && newEntityLiving instanceof Mob) {
|
|
+ ((Mob) newEntityLiving).setPersistenceRequired();
|
|
}
|
|
-
|
|
+ // Paper end
|
|
stack.shrink(1);
|
|
}
|
|
|