diff --git a/demo/src/main/java/net/minestom/demo/Main.java b/demo/src/main/java/net/minestom/demo/Main.java index 2ea4c1a76..b6a0aa9f7 100644 --- a/demo/src/main/java/net/minestom/demo/Main.java +++ b/demo/src/main/java/net/minestom/demo/Main.java @@ -58,7 +58,7 @@ public class Main { commandManager.register(new RedirectTestCommand()); commandManager.register(new DebugGridCommand()); commandManager.register(new DisplayCommand()); - + commandManager.register(new NotificationCommand()); commandManager.setUnknownCommandCallback((sender, command) -> sender.sendMessage(Component.text("Unknown command", NamedTextColor.RED))); diff --git a/demo/src/main/java/net/minestom/demo/commands/NotificationCommand.java b/demo/src/main/java/net/minestom/demo/commands/NotificationCommand.java new file mode 100644 index 000000000..d5fc7453e --- /dev/null +++ b/demo/src/main/java/net/minestom/demo/commands/NotificationCommand.java @@ -0,0 +1,23 @@ +package net.minestom.demo.commands; + +import net.kyori.adventure.text.Component; +import net.minestom.server.advancements.FrameType; +import net.minestom.server.advancements.notifications.Notification; +import net.minestom.server.advancements.notifications.NotificationCenter; +import net.minestom.server.command.builder.Command; +import net.minestom.server.entity.Player; +import net.minestom.server.item.Material; +import org.jetbrains.annotations.NotNull; + +public class NotificationCommand extends Command { + public NotificationCommand() { + super("notification"); + + setDefaultExecutor((sender, context) -> { + var player = (Player) sender; + + var notification = new Notification(Component.text("Hello World!"), FrameType.GOAL, Material.DIAMOND_AXE); + NotificationCenter.send(notification, player); + }); + } +} diff --git a/src/main/java/net/minestom/server/advancements/Advancement.java b/src/main/java/net/minestom/server/advancements/Advancement.java index 092d46cb4..a31979a33 100644 --- a/src/main/java/net/minestom/server/advancements/Advancement.java +++ b/src/main/java/net/minestom/server/advancements/Advancement.java @@ -38,22 +38,30 @@ public class Advancement { // Packet private AdvancementsPacket.Criteria criteria; + private boolean sendTelemetryData; + + public Advancement(@NotNull Component title, @NotNull Component description, + @NotNull Material icon, @NotNull FrameType frameType, + float x, float y) { + this(title, description, ItemStack.of(icon), frameType, x, y, false); + } public Advancement(@NotNull Component title, Component description, @NotNull ItemStack icon, @NotNull FrameType frameType, float x, float y) { + this(title, description, icon, frameType, x, y, false); + } + + public Advancement(@NotNull Component title, Component description, + @NotNull ItemStack icon, @NotNull FrameType frameType, + float x, float y, boolean sendTelemetryData) { this.title = title; this.description = description; this.icon = icon; this.frameType = frameType; this.x = x; this.y = y; - } - - public Advancement(@NotNull Component title, @NotNull Component description, - @NotNull Material icon, @NotNull FrameType frameType, - float x, float y) { - this(title, description, ItemStack.of(icon), frameType, x, y); + this.sendTelemetryData = sendTelemetryData; } /** @@ -301,7 +309,8 @@ public class Advancement { 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())))); + 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 c9d38536e..11344aa3c 100644 --- a/src/main/java/net/minestom/server/advancements/notifications/NotificationCenter.java +++ b/src/main/java/net/minestom/server/advancements/notifications/NotificationCenter.java @@ -66,7 +66,8 @@ public final class NotificationCenter { final var advancement = new AdvancementsPacket.Advancement(null, displayData, List.of(criteria.criterionIdentifier()), - List.of(new AdvancementsPacket.Requirement(List.of(criteria.criterionIdentifier())))); + List.of(new AdvancementsPacket.Requirement(List.of(criteria.criterionIdentifier()))), + false); final var mapping = new AdvancementsPacket.AdvancementMapping(IDENTIFIER, advancement); final var progressMapping = new AdvancementsPacket.ProgressMapping(IDENTIFIER, 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 64ae00571..9166ca97e 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 @@ -100,7 +100,8 @@ public record AdvancementsPacket(boolean reset, @NotNull List criteria, - @NotNull List requirements) implements NetworkBuffer.Writer, ComponentHolder { + @NotNull List requirements, + boolean sendTelemetryData) implements NetworkBuffer.Writer, ComponentHolder { public Advancement { criteria = List.copyOf(criteria); requirements = List.copyOf(requirements); @@ -110,7 +111,8 @@ 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); + return this.displayData == null ? this : new Advancement(this.parentIdentifier, this.displayData.copyWithOperator(operator), this.criteria, this.requirements, this.sendTelemetryData); } }