hollow-cube/1_20-advancement-packet-fix

(cherry picked from commit 1f87f26b4f)
This commit is contained in:
mworzala 2023-08-05 14:07:34 -04:00 committed by Matt Worzala
parent c657be553f
commit 4ece2aa378
5 changed files with 48 additions and 12 deletions

View File

@ -58,7 +58,7 @@ public class Main {
commandManager.register(new RedirectTestCommand()); commandManager.register(new RedirectTestCommand());
commandManager.register(new DebugGridCommand()); commandManager.register(new DebugGridCommand());
commandManager.register(new DisplayCommand()); commandManager.register(new DisplayCommand());
commandManager.register(new NotificationCommand());
commandManager.setUnknownCommandCallback((sender, command) -> sender.sendMessage(Component.text("Unknown command", NamedTextColor.RED))); commandManager.setUnknownCommandCallback((sender, command) -> sender.sendMessage(Component.text("Unknown command", NamedTextColor.RED)));

View File

@ -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);
});
}
}

View File

@ -38,22 +38,30 @@ public class Advancement {
// Packet // Packet
private AdvancementsPacket.Criteria criteria; 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, public Advancement(@NotNull Component title, Component description,
@NotNull ItemStack icon, @NotNull FrameType frameType, @NotNull ItemStack icon, @NotNull FrameType frameType,
float x, float y) { 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.title = title;
this.description = description; this.description = description;
this.icon = icon; this.icon = icon;
this.frameType = frameType; this.frameType = frameType;
this.x = x; this.x = x;
this.y = y; this.y = y;
} this.sendTelemetryData = 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);
} }
/** /**
@ -301,7 +309,8 @@ public class Advancement {
final String parentIdentifier = parent != null ? parent.getIdentifier() : null; final String parentIdentifier = parent != null ? parent.getIdentifier() : null;
AdvancementsPacket.Advancement adv = new AdvancementsPacket.Advancement(parentIdentifier, toDisplayData(), AdvancementsPacket.Advancement adv = new AdvancementsPacket.Advancement(parentIdentifier, toDisplayData(),
List.of(criteria.criterionIdentifier()), 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); return new AdvancementsPacket.AdvancementMapping(getIdentifier(), adv);
} }

View File

@ -66,7 +66,8 @@ public final class NotificationCenter {
final var advancement = new AdvancementsPacket.Advancement(null, displayData, final var advancement = new AdvancementsPacket.Advancement(null, displayData,
List.of(criteria.criterionIdentifier()), 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 mapping = new AdvancementsPacket.AdvancementMapping(IDENTIFIER, advancement);
final var progressMapping = new AdvancementsPacket.ProgressMapping(IDENTIFIER, final var progressMapping = new AdvancementsPacket.ProgressMapping(IDENTIFIER,

View File

@ -100,7 +100,8 @@ public record AdvancementsPacket(boolean reset, @NotNull List<AdvancementMapping
public record Advancement(@Nullable String parentIdentifier, @Nullable DisplayData displayData, public record Advancement(@Nullable String parentIdentifier, @Nullable DisplayData displayData,
@NotNull List<String> criteria, @NotNull List<String> criteria,
@NotNull List<Requirement> requirements) implements NetworkBuffer.Writer, ComponentHolder<Advancement> { @NotNull List<Requirement> requirements,
boolean sendTelemetryData) implements NetworkBuffer.Writer, ComponentHolder<Advancement> {
public Advancement { public Advancement {
criteria = List.copyOf(criteria); criteria = List.copyOf(criteria);
requirements = List.copyOf(requirements); requirements = List.copyOf(requirements);
@ -110,7 +111,8 @@ public record AdvancementsPacket(boolean reset, @NotNull List<AdvancementMapping
this(reader.read(BOOLEAN) ? reader.read(STRING) : null, this(reader.read(BOOLEAN) ? reader.read(STRING) : null,
reader.read(BOOLEAN) ? new DisplayData(reader) : null, reader.read(BOOLEAN) ? new DisplayData(reader) : null,
reader.readCollection(STRING), reader.readCollection(STRING),
reader.readCollection(Requirement::new)); reader.readCollection(Requirement::new),
reader.read(BOOLEAN));
} }
@Override @Override
@ -119,6 +121,7 @@ public record AdvancementsPacket(boolean reset, @NotNull List<AdvancementMapping
writer.writeOptional(displayData); writer.writeOptional(displayData);
writer.writeCollection(STRING, criteria); writer.writeCollection(STRING, criteria);
writer.writeCollection(requirements); writer.writeCollection(requirements);
writer.write(BOOLEAN, sendTelemetryData);
} }
@Override @Override
@ -128,7 +131,7 @@ public record AdvancementsPacket(boolean reset, @NotNull List<AdvancementMapping
@Override @Override
public @NotNull Advancement copyWithOperator(@NotNull UnaryOperator<Component> operator) { public @NotNull Advancement copyWithOperator(@NotNull UnaryOperator<Component> 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);
} }
} }