Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add several scoreboard type wrappers #2819

Closed
wants to merge 0 commits into from
Closed

Add several scoreboard type wrappers #2819

wants to merge 0 commits into from

Conversation

vytskalt
Copy link
Contributor

@vytskalt vytskalt commented Feb 26, 2024

Added wrappers for these NMS types (Mojang mapped names):

I also fixed a compile error. Marked as draft for now as I haven't fully tested it yet.

Closes #2617

@vytskalt vytskalt changed the title Add several objective type wrappers Add several scoreboard type wrappers Feb 27, 2024
@vytskalt vytskalt marked this pull request as ready for review March 2, 2024 19:00
@vytskalt
Copy link
Contributor Author

vytskalt commented Mar 2, 2024

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!");
}

@vytskalt
Copy link
Contributor Author

vytskalt commented Mar 3, 2024

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.

@vytskalt vytskalt mentioned this pull request Mar 5, 2024
1 task
@vytskalt
Copy link
Contributor Author

@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

@dmulloy2
Copy link
Owner

dmulloy2 commented Jun 5, 2024

@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

@@ -291,6 +291,18 @@ public void setWhitelisted(boolean whitelisted) {
this.whitelisted = whitelisted;
}

@Nullable
@Override
public Location getRespawnLocation() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no longer necessary

@dmulloy2 dmulloy2 closed this Jun 7, 2024
dmulloy2 pushed a commit that referenced this pull request Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Another 1.20.2 Issue
2 participants