From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Alvinn8 <42838560+Alvinn8@users.noreply.github.com> Date: Fri, 8 Jan 2021 20:31:13 +0100 Subject: [PATCH] Add Adventure message to PlayerAdvancementDoneEvent diff --git a/src/main/java/net/minecraft/advancements/Advancement.java b/src/main/java/net/minecraft/advancements/Advancement.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/advancements/Advancement.java +++ b/src/main/java/net/minecraft/advancements/Advancement.java @@ -0,0 +0,0 @@ public class Advancement { return this.parent; } + public final @Nullable AdvancementDisplay getAdvancementDisplay() { return this.c(); } // Paper - OBFHELPER @Nullable public AdvancementDisplay c() { return this.display; @@ -0,0 +0,0 @@ public class Advancement { return this.requirements; } + public final IChatBaseComponent getChatComponent() { return this.j(); } // Paper - OBFHELPER public IChatBaseComponent j() { return this.chatComponent; } diff --git a/src/main/java/net/minecraft/advancements/AdvancementDisplay.java b/src/main/java/net/minecraft/advancements/AdvancementDisplay.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/advancements/AdvancementDisplay.java +++ b/src/main/java/net/minecraft/advancements/AdvancementDisplay.java @@ -0,0 +0,0 @@ public class AdvancementDisplay { return this.b; } + public final AdvancementFrameType getFrameType() { return this.e(); } // Paper - OBFHELPER public AdvancementFrameType e() { return this.e; } + public final boolean shouldAnnounceToChat() { return this.i(); } // Paper - OBFHELPER public boolean i() { return this.g; } diff --git a/src/main/java/net/minecraft/advancements/AdvancementFrameType.java b/src/main/java/net/minecraft/advancements/AdvancementFrameType.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/advancements/AdvancementFrameType.java +++ b/src/main/java/net/minecraft/advancements/AdvancementFrameType.java @@ -0,0 +0,0 @@ public enum AdvancementFrameType { this.g = new ChatMessage("advancements.toast." + s); } + public final String getId() { return this.a(); } // Paper - OBFHELPER public String a() { return this.d; } diff --git a/src/main/java/net/minecraft/server/AdvancementDataPlayer.java b/src/main/java/net/minecraft/server/AdvancementDataPlayer.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/server/AdvancementDataPlayer.java +++ b/src/main/java/net/minecraft/server/AdvancementDataPlayer.java @@ -0,0 +0,0 @@ import net.minecraft.util.datafix.DataFixTypes; import net.minecraft.world.level.GameRules; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import io.papermc.paper.adventure.PaperAdventure; // Paper public class AdvancementDataPlayer { @@ -0,0 +0,0 @@ public class AdvancementDataPlayer { this.j.add(advancement); flag = true; if (!flag1 && advancementprogress.isDone()) { - this.player.world.getServer().getPluginManager().callEvent(new org.bukkit.event.player.PlayerAdvancementDoneEvent(this.player.getBukkitEntity(), advancement.bukkit)); // CraftBukkit + // Paper start - Add Adventure message to PlayerAdvancementDoneEvent + boolean announceToChat = advancement.getAdvancementDisplay() != null && advancement.getAdvancementDisplay().shouldAnnounceToChat(); + net.kyori.adventure.text.Component message = announceToChat ? PaperAdventure.asAdventure(new ChatMessage("chat.type.advancement." + advancement.getAdvancementDisplay().getFrameType().getId(), this.player.getScoreboardDisplayName(), advancement.getChatComponent())) : null; + org.bukkit.event.player.PlayerAdvancementDoneEvent event = new org.bukkit.event.player.PlayerAdvancementDoneEvent(this.player.getBukkitEntity(), advancement.bukkit, message); + this.player.world.getServer().getPluginManager().callEvent(event); + message = event.message(); + // Paper end advancement.d().a(this.player); - if (advancement.c() != null && advancement.c().i() && this.player.world.getGameRules().getBoolean(GameRules.ANNOUNCE_ADVANCEMENTS)) { - this.e.sendMessage(new ChatMessage("chat.type.advancement." + advancement.c().e().a(), new Object[]{this.player.getScoreboardDisplayName(), advancement.j()}), ChatMessageType.SYSTEM, SystemUtils.b); + // Paper start - Add Adventure message to PlayerAdvancementDoneEvent + if (message != null && this.player.world.getGameRules().getBoolean(GameRules.ANNOUNCE_ADVANCEMENTS)) { + this.e.sendMessage(PaperAdventure.asVanilla(message), ChatMessageType.SYSTEM, SystemUtils.getNullUUID()); + // Paper end } } }