ProtocolLib
ProtocolLib copied to clipboard
Add several scoreboard type wrappers
Added wrappers for these NMS types (Mojang mapped names):
- DisplaySlot (added in 1.20.2)
- ObjectiveCriteria$RenderType
- ChatFormatting
- ClientboundSetPlayerTeamPacket$Parameters
- Style
- NumberFormat (sum type)
I also fixed a compile error. ~~Marked as draft for now as I haven't fully tested it yet.~~
Closes #2617
I have manually tested everything with the hacky code below on 1.8.9, 1.12.2, 1.13, 1.16.5, 1.17, 1.20.2 and 1.20.4. Everything appears to be working correctly.
public void testProtocolLib() {
ProtocolManager pm = ProtocolLibrary.getProtocolManager();
if (new MinecraftVersion(1, 20, 2).atOrAbove()) {
getLogger().info("Testing DisplaySlot (1.20.2+)");
pm.createPacket(PacketType.Play.Server.SCOREBOARD_DISPLAY_OBJECTIVE)
.getDisplaySlots()
.write(0, EnumWrappers.DisplaySlot.LIST);
}
// expect parameters to be supported on 1.17+
Preconditions.checkState(WrappedTeamParameters.isSupported() == MinecraftVersion.CAVES_CLIFFS_1.atOrAbove());
if (MinecraftVersion.CAVES_CLIFFS_1.atOrAbove()) {
getLogger().info("Testing WrappedTeamParameters (1.17+)");
WrappedChatComponent c = WrappedChatComponent.fromText("test");
WrappedTeamParameters p = WrappedTeamParameters.newBuilder()
.displayName(c)
.prefix(c)
.suffix(c)
.nametagVisibility("never")
.collisionRule("always")
.color(EnumWrappers.ChatFormatting.OBFUSCATED)
.options(1)
.build();
Preconditions.checkState(p.getDisplayName().getHandle() == c.getHandle());
Preconditions.checkState(p.getPrefix().getHandle() == c.getHandle());
Preconditions.checkState(p.getSuffix().getHandle() == c.getHandle());
Preconditions.checkState(p.getNametagVisibility().equals("never"));
Preconditions.checkState(p.getCollisionRule().equals("always"));
Preconditions.checkState(p.getColor() == EnumWrappers.ChatFormatting.OBFUSCATED);
Preconditions.checkState(p.getOptions() == 1);
}
getLogger().info("Testing ChatFormatting");
Object colorHandle = EnumWrappers.getChatFormattingConverter().getGeneric(EnumWrappers.ChatFormatting.DARK_AQUA);
Preconditions.checkState(EnumWrappers.ChatFormatting.DARK_AQUA == EnumWrappers.getChatFormattingConverter().getSpecific(colorHandle));
Preconditions.checkState(WrappedNumberFormat.isSupported() == MinecraftVersion.v1_20_4.atOrAbove());
getLogger().info("Testing RenderType");
pm.createPacket(PacketType.Play.Server.SCOREBOARD_OBJECTIVE)
.getRenderTypes()
.write(0, EnumWrappers.RenderType.HEARTS);
{
getLogger().info("Testing WrappedComponentStyle");
JsonObject style = (JsonObject) new JsonParser().parse("{\"color\":\"green\",\"bold\":true}");
WrappedComponentStyle wrappedStyle = WrappedComponentStyle.fromJson(style);
Preconditions.checkState(wrappedStyle.getJson().equals(style));
}
getLogger().info("All tests passed!");
}
Also FYI @dmulloy2 the tests don't currently run because of a version mismatch between spigot-api and spigot. org.spigotmc:spigot:1.20.4-R0.1-SNAPSHOT in the https://repo.dmulloy2.net/ repo needs to be updated to the latest version.
@dmulloy2 pls let me know if you are interested in this PR so I can know if I should update it for 1.20.6
@vytskalt this looks great! Would love if you could update it for 1.20.6. Seems like it's failing to compile because those new methods already exist in serialized offline player