Check parsed name length

This commit is contained in:
fullwall 2022-12-26 00:20:21 +08:00
parent 27603afdf4
commit 36671daeae
2 changed files with 2 additions and 8 deletions

View File

@ -53,9 +53,6 @@ public class ProtocolLibListener {
manager.addPacketListener(new PacketAdapter(plugin, ListenerPriority.MONITOR, Server.PLAYER_INFO) {
@Override
public void onPacketSending(PacketEvent event) {
if (event.getPlayer().hasMetadata("NPC"))
return;
int version = VIA_ENABLED ? Via.getAPI().getPlayerVersion(event.getPlayer())
: manager.getProtocolVersion(event.getPlayer());
List<PlayerInfoData> list = event.getPacket().getPlayerInfoDataLists()
@ -97,9 +94,6 @@ public class ProtocolLibListener {
new PacketAdapter(plugin, ListenerPriority.MONITOR, Server.ENTITY_HEAD_ROTATION, Server.ENTITY_LOOK) {
@Override
public void onPacketSending(PacketEvent event) {
if (event.getPlayer().hasMetadata("NPC"))
return;
NPC npc = getNPCFromPacket(event);
if (npc == null)
return;

View File

@ -638,7 +638,7 @@ public class NPCCommands {
}
int nameLength = SpigotUtil.getMaxNameLength(type);
if (name.length() > nameLength && Placeholders.replace(name, sender, npc).length() > nameLength) {
if (Placeholders.replace(Messaging.parseComponents(name), sender, npc).length() > nameLength) {
Messaging.sendErrorTr(sender, Messages.NPC_NAME_TOO_LONG, nameLength);
name = name.substring(0, nameLength);
}
@ -2138,7 +2138,7 @@ public class NPCCommands {
String oldName = npc.getName();
String newName = args.getJoinedStrings(1);
int nameLength = SpigotUtil.getMaxNameLength(npc.getOrAddTrait(MobType.class).getType());
if (newName.length() > nameLength && Placeholders.replace(newName, sender, npc).length() > nameLength) {
if (Placeholders.replace(Messaging.parseComponents(newName), sender, npc).length() > nameLength) {
Messaging.sendErrorTr(sender, Messages.NPC_NAME_TOO_LONG, nameLength);
newName = newName.substring(0, nameLength);
}