Fix custom name components in 1.8.8-1.12.2,

This commit is contained in:
fullwall 2022-12-22 23:17:28 +08:00
parent 45d7a072a1
commit 4c958b5e7c
17 changed files with 52 additions and 29 deletions

View File

@ -54,6 +54,7 @@ import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.ChunkUnloadEvent; import org.bukkit.event.world.ChunkUnloadEvent;
import org.bukkit.event.world.WorldLoadEvent; import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.event.world.WorldUnloadEvent; import org.bukkit.event.world.WorldUnloadEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginDescriptionFile;
@ -107,6 +108,7 @@ import net.citizensnpcs.trait.Controllable;
import net.citizensnpcs.trait.CurrentLocation; import net.citizensnpcs.trait.CurrentLocation;
import net.citizensnpcs.trait.ScoreboardTrait; import net.citizensnpcs.trait.ScoreboardTrait;
import net.citizensnpcs.trait.ShopTrait; import net.citizensnpcs.trait.ShopTrait;
import net.citizensnpcs.trait.SitTrait;
import net.citizensnpcs.util.ChunkCoord; import net.citizensnpcs.util.ChunkCoord;
import net.citizensnpcs.util.Messages; import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.NMS; import net.citizensnpcs.util.NMS;
@ -481,6 +483,9 @@ public class EventListen implements Listener {
} }
Player player = event.getPlayer(); Player player = event.getPlayer();
NPCRightClickEvent rightClickEvent = new NPCRightClickEvent(npc, player); NPCRightClickEvent rightClickEvent = new NPCRightClickEvent(npc, player);
if (event.getHand() == EquipmentSlot.HAND && event.getPlayer().getItemInHand().getType() == Material.NAME_TAG) {
rightClickEvent.setCancelled(npc.isProtected());
}
Bukkit.getPluginManager().callEvent(rightClickEvent); Bukkit.getPluginManager().callEvent(rightClickEvent);
if (rightClickEvent.isCancelled()) { if (rightClickEvent.isCancelled()) {
event.setCancelled(true); event.setCancelled(true);
@ -548,9 +553,14 @@ public class EventListen implements Listener {
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void onPlayerTeleport(final PlayerTeleportEvent event) { public void onPlayerTeleport(final PlayerTeleportEvent event) {
NPC npc = CitizensAPI.getNPCRegistry().getNPC(event.getPlayer());
if (event.getCause() == TeleportCause.PLUGIN && npc != null) {
if (npc.hasTrait(SitTrait.class)) {
npc.getOrAddTrait(SitTrait.class).setSitting(event.getTo());
}
}
if (event.getCause() == TeleportCause.PLUGIN && !event.getPlayer().hasMetadata("citizens-force-teleporting") if (event.getCause() == TeleportCause.PLUGIN && !event.getPlayer().hasMetadata("citizens-force-teleporting")
&& CitizensAPI.getNPCRegistry().getNPC(event.getPlayer()) != null && npc != null && Setting.PLAYER_TELEPORT_DELAY.asInt() > 0) {
&& Setting.PLAYER_TELEPORT_DELAY.asInt() > 0) {
event.setCancelled(true); event.setCancelled(true);
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() { Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), new Runnable() {
@Override @Override
@ -667,7 +677,6 @@ public class EventListen implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onWorldUnload(WorldUnloadEvent event) { public void onWorldUnload(WorldUnloadEvent event) {
System.out.println(event.getWorld());
for (NPC npc : getAllNPCs()) { for (NPC npc : getAllNPCs()) {
if (npc == null || !npc.isSpawned() || !npc.getEntity().getWorld().equals(event.getWorld())) if (npc == null || !npc.isSpawned() || !npc.getEntity().getWorld().equals(event.getWorld()))
continue; continue;

View File

@ -1,5 +1,6 @@
package net.citizensnpcs; package net.citizensnpcs;
import java.util.List;
import java.util.Set; import java.util.Set;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
@ -16,7 +17,10 @@ import com.comphenix.protocol.reflect.FieldAccessException;
import com.comphenix.protocol.reflect.StructureModifier; import com.comphenix.protocol.reflect.StructureModifier;
import com.comphenix.protocol.utility.MinecraftReflection; import com.comphenix.protocol.utility.MinecraftReflection;
import com.comphenix.protocol.wrappers.EnumWrappers; import com.comphenix.protocol.wrappers.EnumWrappers;
import com.comphenix.protocol.wrappers.PlayerInfoData;
import com.google.common.collect.Lists;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.Messaging; import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.npc.ai.NPCHolder; import net.citizensnpcs.npc.ai.NPCHolder;
@ -34,7 +38,21 @@ public class ProtocolLibListener {
flagsClass = MinecraftReflection.getMinecraftClass("EnumPlayerTeleportFlags", flagsClass = MinecraftReflection.getMinecraftClass("EnumPlayerTeleportFlags",
"PacketPlayOutPosition$EnumPlayerTeleportFlags", "PacketPlayOutPosition$EnumPlayerTeleportFlags",
"network.protocol.game.PacketPlayOutPosition$EnumPlayerTeleportFlags"); "network.protocol.game.PacketPlayOutPosition$EnumPlayerTeleportFlags");
manager.addPacketListener(new PacketAdapter(plugin, ListenerPriority.MONITOR, Server.PLAYER_INFO) {
@Override
public void onPacketSending(PacketEvent event) {
List<PlayerInfoData> list = event.getPacket().getPlayerInfoDataLists().readSafely(0);
if (list == null)
return;
for (PlayerInfoData data : Lists.newArrayList(list)) {
if (data == null)
continue;
NPC npc = CitizensAPI.getNPCRegistry().getByUniqueId(data.getProfile().getUUID());
if (npc == null)
continue;
}
}
});
manager.addPacketListener( manager.addPacketListener(
new PacketAdapter(plugin, ListenerPriority.MONITOR, Server.ENTITY_HEAD_ROTATION, Server.ENTITY_LOOK) { new PacketAdapter(plugin, ListenerPriority.MONITOR, Server.ENTITY_HEAD_ROTATION, Server.ENTITY_LOOK) {
@Override @Override

View File

@ -517,8 +517,8 @@ public class CitizensNPC extends AbstractNPC {
@Override @Override
public void updateCustomName() { public void updateCustomName() {
if (minecraftComponentCache != null) { if (nameComponentCache != null) {
NMS.setCustomName(getEntity(), minecraftComponentCache); NMS.setCustomName(getEntity(), nameComponentCache, nameStringComponentCache);
} else { } else {
super.updateCustomName(); super.updateCustomName();
} }

View File

@ -542,8 +542,8 @@ public class NMS {
BRIDGE.setCamelPose(entity, pose); BRIDGE.setCamelPose(entity, pose);
} }
public static void setCustomName(Entity entity, Object component) { public static void setCustomName(Entity entity, Object component, String string) {
BRIDGE.setCustomName(entity, component); BRIDGE.setCustomName(entity, component, string);
} }
public static void setDestination(org.bukkit.entity.Entity entity, double x, double y, double z, float speed) { public static void setDestination(org.bukkit.entity.Entity entity, double x, double y, double z, float speed) {

View File

@ -161,7 +161,7 @@ public interface NMSBridge {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
public void setCustomName(Entity entity, Object component); public void setCustomName(Entity entity, Object component, String string);
public void setDestination(Entity entity, double x, double y, double z, float speed); public void setDestination(Entity entity, double x, double y, double z, float speed);

View File

@ -269,7 +269,7 @@ public class Util {
} }
public static String listValuesPretty(Enum<?>[] values) { public static String listValuesPretty(Enum<?>[] values) {
return "<e>" + Joiner.on("<a>, <e>").join(values).toLowerCase(); return "<yellow>" + Joiner.on("<green>, <yellow>").join(values).toLowerCase();
} }
public static boolean locationWithinRange(Location current, Location target, double range) { public static boolean locationWithinRange(Location current, Location target, double range) {

View File

@ -213,7 +213,6 @@ import net.minecraft.server.v1_10_R1.EntityTrackerEntry;
import net.minecraft.server.v1_10_R1.EntityTypes; import net.minecraft.server.v1_10_R1.EntityTypes;
import net.minecraft.server.v1_10_R1.EntityWither; import net.minecraft.server.v1_10_R1.EntityWither;
import net.minecraft.server.v1_10_R1.GenericAttributes; import net.minecraft.server.v1_10_R1.GenericAttributes;
import net.minecraft.server.v1_10_R1.IChatBaseComponent;
import net.minecraft.server.v1_10_R1.IInventory; import net.minecraft.server.v1_10_R1.IInventory;
import net.minecraft.server.v1_10_R1.MathHelper; import net.minecraft.server.v1_10_R1.MathHelper;
import net.minecraft.server.v1_10_R1.MinecraftKey; import net.minecraft.server.v1_10_R1.MinecraftKey;
@ -1044,8 +1043,8 @@ public class NMSImpl implements NMSBridge {
} }
@Override @Override
public void setCustomName(org.bukkit.entity.Entity entity, Object component) { public void setCustomName(org.bukkit.entity.Entity entity, Object component, String string) {
getHandle(entity).setCustomName(((IChatBaseComponent) component).getText()); getHandle(entity).setCustomName(string);
} }
@Override @Override

View File

@ -233,7 +233,6 @@ import net.minecraft.server.v1_11_R1.EntityTypes;
import net.minecraft.server.v1_11_R1.EntityWither; import net.minecraft.server.v1_11_R1.EntityWither;
import net.minecraft.server.v1_11_R1.EnumMoveType; import net.minecraft.server.v1_11_R1.EnumMoveType;
import net.minecraft.server.v1_11_R1.GenericAttributes; import net.minecraft.server.v1_11_R1.GenericAttributes;
import net.minecraft.server.v1_11_R1.IChatBaseComponent;
import net.minecraft.server.v1_11_R1.IInventory; import net.minecraft.server.v1_11_R1.IInventory;
import net.minecraft.server.v1_11_R1.MathHelper; import net.minecraft.server.v1_11_R1.MathHelper;
import net.minecraft.server.v1_11_R1.MinecraftKey; import net.minecraft.server.v1_11_R1.MinecraftKey;
@ -1103,8 +1102,8 @@ public class NMSImpl implements NMSBridge {
} }
@Override @Override
public void setCustomName(org.bukkit.entity.Entity entity, Object component) { public void setCustomName(org.bukkit.entity.Entity entity, Object component, String string) {
getHandle(entity).setCustomName(((IChatBaseComponent) component).getText()); getHandle(entity).setCustomName(string);
} }
@Override @Override

View File

@ -237,7 +237,6 @@ import net.minecraft.server.v1_12_R1.EntityTypes;
import net.minecraft.server.v1_12_R1.EntityWither; import net.minecraft.server.v1_12_R1.EntityWither;
import net.minecraft.server.v1_12_R1.EnumMoveType; import net.minecraft.server.v1_12_R1.EnumMoveType;
import net.minecraft.server.v1_12_R1.GenericAttributes; import net.minecraft.server.v1_12_R1.GenericAttributes;
import net.minecraft.server.v1_12_R1.IChatBaseComponent;
import net.minecraft.server.v1_12_R1.IInventory; import net.minecraft.server.v1_12_R1.IInventory;
import net.minecraft.server.v1_12_R1.MathHelper; import net.minecraft.server.v1_12_R1.MathHelper;
import net.minecraft.server.v1_12_R1.MinecraftKey; import net.minecraft.server.v1_12_R1.MinecraftKey;
@ -1113,8 +1112,8 @@ public class NMSImpl implements NMSBridge {
} }
@Override @Override
public void setCustomName(org.bukkit.entity.Entity entity, Object component) { public void setCustomName(org.bukkit.entity.Entity entity, Object component, String string) {
getHandle(entity).setCustomName(((IChatBaseComponent) component).getText()); getHandle(entity).setCustomName(string);
} }
@Override @Override

View File

@ -1149,7 +1149,7 @@ public class NMSImpl implements NMSBridge {
} }
@Override @Override
public void setCustomName(org.bukkit.entity.Entity entity, Object component) { public void setCustomName(org.bukkit.entity.Entity entity, Object component, String string) {
getHandle(entity).setCustomName((IChatBaseComponent) component); getHandle(entity).setCustomName((IChatBaseComponent) component);
} }

View File

@ -1204,7 +1204,7 @@ public class NMSImpl implements NMSBridge {
} }
@Override @Override
public void setCustomName(org.bukkit.entity.Entity entity, Object component) { public void setCustomName(org.bukkit.entity.Entity entity, Object component, String string) {
getHandle(entity).setCustomName((IChatBaseComponent) component); getHandle(entity).setCustomName((IChatBaseComponent) component);
} }

View File

@ -1222,7 +1222,7 @@ public class NMSImpl implements NMSBridge {
} }
@Override @Override
public void setCustomName(org.bukkit.entity.Entity entity, Object component) { public void setCustomName(org.bukkit.entity.Entity entity, Object component, String string) {
getHandle(entity).setCustomName((IChatBaseComponent) component); getHandle(entity).setCustomName((IChatBaseComponent) component);
} }

View File

@ -1252,7 +1252,7 @@ public class NMSImpl implements NMSBridge {
} }
@Override @Override
public void setCustomName(org.bukkit.entity.Entity entity, Object component) { public void setCustomName(org.bukkit.entity.Entity entity, Object component, String string) {
getHandle(entity).setCustomName((IChatBaseComponent) component); getHandle(entity).setCustomName((IChatBaseComponent) component);
} }

View File

@ -1248,7 +1248,7 @@ public class NMSImpl implements NMSBridge {
} }
@Override @Override
public void setCustomName(org.bukkit.entity.Entity entity, Object component) { public void setCustomName(org.bukkit.entity.Entity entity, Object component, String string) {
getHandle(entity).setCustomName((Component) component); getHandle(entity).setCustomName((Component) component);
} }

View File

@ -1255,7 +1255,7 @@ public class NMSImpl implements NMSBridge {
} }
@Override @Override
public void setCustomName(org.bukkit.entity.Entity entity, Object component) { public void setCustomName(org.bukkit.entity.Entity entity, Object component, String string) {
getHandle(entity).setCustomName((Component) component); getHandle(entity).setCustomName((Component) component);
} }

View File

@ -1343,7 +1343,7 @@ public class NMSImpl implements NMSBridge {
} }
@Override @Override
public void setCustomName(org.bukkit.entity.Entity entity, Object component) { public void setCustomName(org.bukkit.entity.Entity entity, Object component, String string) {
getHandle(entity).setCustomName((Component) component); getHandle(entity).setCustomName((Component) component);
} }

View File

@ -191,7 +191,6 @@ import net.minecraft.server.v1_8_R3.EntityTrackerEntry;
import net.minecraft.server.v1_8_R3.EntityTypes; import net.minecraft.server.v1_8_R3.EntityTypes;
import net.minecraft.server.v1_8_R3.EntityWither; import net.minecraft.server.v1_8_R3.EntityWither;
import net.minecraft.server.v1_8_R3.GenericAttributes; import net.minecraft.server.v1_8_R3.GenericAttributes;
import net.minecraft.server.v1_8_R3.IChatBaseComponent;
import net.minecraft.server.v1_8_R3.IInventory; import net.minecraft.server.v1_8_R3.IInventory;
import net.minecraft.server.v1_8_R3.MathHelper; import net.minecraft.server.v1_8_R3.MathHelper;
import net.minecraft.server.v1_8_R3.Navigation; import net.minecraft.server.v1_8_R3.Navigation;
@ -980,8 +979,8 @@ public class NMSImpl implements NMSBridge {
} }
@Override @Override
public void setCustomName(org.bukkit.entity.Entity entity, Object component) { public void setCustomName(org.bukkit.entity.Entity entity, Object component, String string) {
getHandle(entity).setCustomName(((IChatBaseComponent) component).getText()); getHandle(entity).setCustomName(string);
} }
@Override @Override