From 03ef3e23747af15f518a169f03b19de267b473db Mon Sep 17 00:00:00 2001 From: mworzala Date: Sun, 7 Jan 2024 15:25:09 -0500 Subject: [PATCH] fix: update advancement packet to 1.20.4 --- .../main/java/net/minestom/demo/PlayerInit.java | 12 ++++++++++++ .../minestom/server/advancements/Advancement.java | 1 - .../notifications/NotificationCenter.java | 1 - .../packet/server/play/AdvancementsPacket.java | 14 ++++---------- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/demo/src/main/java/net/minestom/demo/PlayerInit.java b/demo/src/main/java/net/minestom/demo/PlayerInit.java index e7ccfe269..437cec570 100644 --- a/demo/src/main/java/net/minestom/demo/PlayerInit.java +++ b/demo/src/main/java/net/minestom/demo/PlayerInit.java @@ -4,6 +4,9 @@ import net.kyori.adventure.resource.ResourcePackInfo; import net.kyori.adventure.resource.ResourcePackRequest; import net.kyori.adventure.text.Component; import net.minestom.server.MinecraftServer; +import net.minestom.server.advancements.FrameType; +import net.minestom.server.advancements.notifications.Notification; +import net.minestom.server.advancements.notifications.NotificationCenter; import net.minestom.server.adventure.MinestomAdventure; import net.minestom.server.adventure.audience.Audiences; import net.minestom.server.coordinate.Pos; @@ -115,6 +118,15 @@ public class PlayerInit { }) .build(); player.getInventory().addItemStack(bundle); + + if (event.isFirstSpawn()) { + Notification notification = new Notification( + Component.text("Welcome!"), + FrameType.TASK, + Material.IRON_SWORD + ); + NotificationCenter.send(notification, event.getPlayer()); + } }) .addListener(PlayerPacketOutEvent.class, event -> { //System.out.println("out " + event.getPacket().getClass().getSimpleName()); diff --git a/src/main/java/net/minestom/server/advancements/Advancement.java b/src/main/java/net/minestom/server/advancements/Advancement.java index a31979a33..a8f462339 100644 --- a/src/main/java/net/minestom/server/advancements/Advancement.java +++ b/src/main/java/net/minestom/server/advancements/Advancement.java @@ -308,7 +308,6 @@ public class Advancement { final Advancement parent = getParent(); final String parentIdentifier = parent != null ? parent.getIdentifier() : null; AdvancementsPacket.Advancement adv = new AdvancementsPacket.Advancement(parentIdentifier, toDisplayData(), - List.of(criteria.criterionIdentifier()), List.of(new AdvancementsPacket.Requirement(List.of(criteria.criterionIdentifier()))), sendTelemetryData); return new AdvancementsPacket.AdvancementMapping(getIdentifier(), adv); diff --git a/src/main/java/net/minestom/server/advancements/notifications/NotificationCenter.java b/src/main/java/net/minestom/server/advancements/notifications/NotificationCenter.java index 11344aa3c..5c5326b3c 100644 --- a/src/main/java/net/minestom/server/advancements/notifications/NotificationCenter.java +++ b/src/main/java/net/minestom/server/advancements/notifications/NotificationCenter.java @@ -65,7 +65,6 @@ public final class NotificationCenter { new AdvancementsPacket.CriterionProgress(System.currentTimeMillis())); final var advancement = new AdvancementsPacket.Advancement(null, displayData, - List.of(criteria.criterionIdentifier()), List.of(new AdvancementsPacket.Requirement(List.of(criteria.criterionIdentifier()))), false); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/AdvancementsPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/AdvancementsPacket.java index 65952997b..5c91289b0 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/AdvancementsPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/AdvancementsPacket.java @@ -104,27 +104,21 @@ public record AdvancementsPacket(boolean reset, @NotNull List criteria, @NotNull List requirements, boolean sendTelemetryData) implements NetworkBuffer.Writer, ComponentHolder { public Advancement { - criteria = List.copyOf(criteria); requirements = List.copyOf(requirements); } public Advancement(@NotNull NetworkBuffer reader) { - this(reader.read(BOOLEAN) ? reader.read(STRING) : null, - reader.read(BOOLEAN) ? new DisplayData(reader) : null, - reader.readCollection(STRING), - reader.readCollection(Requirement::new), - reader.read(BOOLEAN)); + this(reader.readOptional(STRING), reader.readOptional(DisplayData::new), + reader.readCollection(Requirement::new), reader.read(BOOLEAN)); } @Override public void write(@NotNull NetworkBuffer writer) { writer.writeOptional(STRING, parentIdentifier); writer.writeOptional(displayData); - writer.writeCollection(STRING, criteria); writer.writeCollection(requirements); writer.write(BOOLEAN, sendTelemetryData); } @@ -136,7 +130,7 @@ public record AdvancementsPacket(boolean reset, @NotNull List operator) { - return this.displayData == null ? this : new Advancement(this.parentIdentifier, this.displayData.copyWithOperator(operator), this.criteria, this.requirements, this.sendTelemetryData); + return this.displayData == null ? this : new Advancement(this.parentIdentifier, this.displayData.copyWithOperator(operator), this.requirements, this.sendTelemetryData); } } @@ -190,7 +184,7 @@ public record AdvancementsPacket(boolean reset, @NotNull List