FancyInnovations / FancyInnovations/FancyPlugins

Bug: FancyNPCs using legacy colors for team names causing warnings in other plugins

Open
#290 1 comment 0 reactions 0 assignees View on GitHub
Priority: Medium Status: Pending Type: Bug
Dominant language
Java
Stars
88
Forks
109
PR merge metrics
No merged PRs in 30d

Description

### In which plugin has the error occurred?

FancyNpcs

### What happened?

When creating an NPC via the plugin API, Nexo (and likely other plugins that intercept scoreboard packets), Adventure API throws an exception caused by legacy colors.
My suggested fix is to simply migrate to modern formatting, because there is practically no reason to still use legacy.

*Nexo's developer refused to make modifications to their code.

Snippet of the API usage:
```java
@Override
public String preview(Player player) {
Location loc = player.getEyeLocation();
Vector direction = loc.getDirection().normalize().multiply(2.5);

Location locationAhead = loc.add(direction);
locationAhead.setY(player.getY());
locationAhead.setPitch(0);
locationAhead.setYaw(player.getYaw() + 180);
NpcData data = new NpcData(player.getName() + "_preview", player.getUniqueId(), locationAhead);
data.setMirrorSkin(true);
data.setDisplayName("");
data.setVisibility(NpcVisibility.MANUAL);
data.setVisibilityDistance(6);

Npc npc = FancyNpcsPlugin.get().getNpcAdapter().apply(data);
npc.setSaveToFile(false);
FancyNpcsPlugin.get().getNpcManager().registerNpc(npc);

npc.create();
Bukkit.getScheduler().runTaskAsynchronously(Cosmetics.get(), () -> npc.spawn(player));

player.playSound(player, Sound.ENTITY_PUFFER_FISH_BLOW_UP, 0.7f, 1f);
player.closeInventory();

Bukkit.getScheduler().runTaskLater(Cosmetics.get(), () -> {
FancyNpcsPlugin.get().getNpcManager().removeNpc(npc);
npc.removeForAll();

if (player.isOnline()) {
player.playSound(player, Sound.ENTITY_ILLUSIONER_MIRROR_MOVE, 1, 1.1f);

Location particleLoc = locationAhead.clone().add(0, 1, 0);
player.spawnParticle(Particle.POOF, particleLoc, 10, 0.35, 0.8, 0.35, 0.1);
}
Bukkit.getScheduler().runTaskLater(Cosmetics.get(), () -> {
if (player.isOnline()) Cosmetics.get().cosmeticMenus.get(CosmeticType.HAT).open(player);
}, 20);
}, 100);
return "";
}
}
```

### In which software has the error occurred?

Paper

### Plugin version

2.11.0

### Server version

1.21.11 PaperMC

### Relevant log output

```shell
[14:52:33 WARN]: net.kyori.adventure.text.LegacyFormattingDetected: Legacy formatting codes have been detected in a component - this is unsupported behaviour. Please refer to the Adventure documentation (https://docs.papermc.io/adventure/) for more information. Component: TextComponentImpl{content="npc-�f�3�4�f�4�8�n�6", style=StyleImpl{obfuscated=not_set, bold=not_set, strikethrough=not_set, underlined=not_set, italic=not_set, color=null, shadowColor=null, clickEvent=null, hoverEvent=null, insertion=null, font=null}, children=[]}
[14:52:33 WARN]: at net.kyori.adventure.text.TextComponentImpl.warnWhenLegacyFormattingDetected(TextComponentImpl.java:84)
[14:52:33 WARN]: at net.kyori.adventure.text.TextComponentImpl.(TextComponentImpl.java:74)
[14:52:33 WARN]: at net.kyori.adventure.text.TextComponentImpl.create(TextComponentImpl.java:55)
[14:52:33 WARN]: at net.kyori.adventure.text.TextComponentImpl.create0(TextComponentImpl.java:60)
[14:52:33 WARN]: at net.kyori.adventure.text.TextComponentImpl.style(TextComponentImpl.java:107)
[14:52:33 WARN]: at net.kyori.adventure.text.TextComponentImpl.style(TextComponentImpl.java:39)
[14:52:33 WARN]: at net.kyori.adventure.text.Component.hoverEvent(Component.java:2567)
[14:52:33 WARN]: at net.kyori.adventure.text.ScopedComponent.hoverEvent(ScopedComponent.java:213)
[14:52:33 WARN]: at nexo-1.25.1.jar//com.nexomc.nexo.nms.v1_21_R10.packets.transformers.ComponentTransformer.transformKyori(ComponentTransformer.kt:73)
[14:52:33 WARN]: at nexo-1.25.1.jar//com.nexomc.nexo.nms.v1_21_R10.packets.transformers.ComponentTransformer.transform(ComponentTransformer.kt:37)
[14:52:33 WARN]: at nexo-1.25.1.jar//com.nexomc.nexo.nms.v1_21_R10.packets.transformers.ComponentTransformer.transform(ComponentTransformer.kt:33)
[14:52:33 WARN]: at nexo-1.25.1.jar//com.nexomc.nexo.nms.v1_21_R10.packets.transformers.ComponentTransformer.transform(ComponentTransformer.kt:30)
[14:52:33 WARN]: at nexo-1.25.1.jar//com.nexomc.nexo.nms.commons.packets.NexoCommonsHandler.transform(NexoCommonsHandler.kt:355)
[14:52:33 WARN]: at nexo-1.25.1.jar//com.nexomc.nexo.nms.v1_21_R10.packets.NexoChannelHandler._init_$lambda$1(NexoChannelHandler.kt:97)
[14:52:33 WARN]: at nexo-1.25.1.jar//com.nexomc.nexo.nms.v1_21_R10.packets.NexoChannelHandler$special$$inlined$registerTransformer$1.invoke(NexoCommonsHandler.kt:119)
[14:52:33 WARN]: at nexo-1.25.1.jar//com.nexomc.nexo.nms.v1_21_R10.packets.NexoChannelHandler$special$$inlined$registerTransformer$1.invoke(NexoCommonsHandler.kt:118)
[14:52:33 WARN]: at nexo-1.25.1.jar//com.nexomc.nexo.nms.commons.packets.NexoCommonsHandler.transformPacket(NexoCommonsHandler.kt:138)
[14:52:33 WARN]: at nexo-1.25.1.jar//com.nexomc.nexo.nms.commons.packets.NexoCommonsHandler._init_$lambda$0(NexoCommonsHandler.kt:161)
[14:52:33 WARN]: at nexo-1.25.1.jar//com.nexomc.nexo.nms.commons.packets.NexoCommonsHandler$special$$inlined$registerTransformer$default$1.invoke(NexoCommonsHandler.kt:119)
[14:52:33 WARN]: at nexo-1.25.1.jar//com.nexomc.nexo.nms.commons.packets.NexoCommonsHandler$special$$inlined$registerTransformer$default$1.invoke(NexoCommonsHandler.kt:118)
[14:52:33 WARN]: at nexo-1.25.1.jar//com.nexomc.nexo.nms.commons.packets.NexoCommonsHandler.transformPacket(NexoCommonsHandler.kt:138)
[14:52:33 WARN]: at nexo-1.25.1.jar//com.nexomc.nexo.nms.commons.packets.NexoCommonsHandler.write(NexoCommonsHandler.kt:96)
[14:52:33 WARN]: at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:825)
[14:52:33 WARN]: at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:804)
[14:52:33 WARN]: at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:1041)
[14:52:33 WARN]: at io.netty.channel.Channel.writeAndFlush(Channel.java:262)
[14:52:33 WARN]: at net.minecraft.network.Connection.doSendPacket(Connection.java:469)
[14:52:33 WARN]: at net.minecraft.network.Connection.lambda$sendPacket$10(Connection.java:451)
```

Contributor guide

Open the contributing guide

Research direction

Start by tracing where FancyNpcs creates or formats NPC team names, using the reported API example and the Paper 1.21.11 setup with Nexo enabled. Reproduce the warning and identify the legacy color formatting involved; done means the NPC is created without Adventure legacy-formatting warnings while retaining the intended team-name appearance.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
game-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.