mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 23:38:25 +01:00
Add Adventure message to PlayerAdvancementDoneEvent (#5030)
* Add Adventure message to PlayerAdvancementDoneEvent * Add obfuscation helpers * Renumber patches
This commit is contained in:
parent
0248c23203
commit
693926c32d
2 changed files with 160 additions and 0 deletions
|
@ -0,0 +1,71 @@
|
|||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Alvinn8 <42838560+Alvinn8@users.noreply.github.com>
|
||||
Date: Fri, 8 Jan 2021 20:29:58 +0100
|
||||
Subject: [PATCH] Add Adventure message to PlayerAdvancementDoneEvent
|
||||
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/event/player/PlayerAdvancementDoneEvent.java b/src/main/java/org/bukkit/event/player/PlayerAdvancementDoneEvent.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/event/player/PlayerAdvancementDoneEvent.java
|
||||
+++ b/src/main/java/org/bukkit/event/player/PlayerAdvancementDoneEvent.java
|
||||
@@ -0,0 +0,0 @@ import org.bukkit.advancement.Advancement;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
+// Paper start
|
||||
+import org.jetbrains.annotations.Nullable;
|
||||
+import net.kyori.adventure.text.Component;
|
||||
+// Paper end
|
||||
|
||||
/**
|
||||
* Called when a player has completed all criteria in an advancement.
|
||||
@@ -0,0 +0,0 @@ public class PlayerAdvancementDoneEvent extends PlayerEvent {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
//
|
||||
private final Advancement advancement;
|
||||
+ private Component message; // Paper - Add Adventure message
|
||||
|
||||
public PlayerAdvancementDoneEvent(@NotNull Player who, @NotNull Advancement advancement) {
|
||||
+ // Paper start - Add Adventure message
|
||||
+ this(who, advancement, null);
|
||||
+ }
|
||||
+ public PlayerAdvancementDoneEvent(@NotNull Player who, @NotNull Advancement advancement, @Nullable Component message) {
|
||||
+ // Paper end
|
||||
super(who);
|
||||
this.advancement = advancement;
|
||||
+ this.message = message; // Paper - Add Adventure message
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -0,0 +0,0 @@ public class PlayerAdvancementDoneEvent extends PlayerEvent {
|
||||
return advancement;
|
||||
}
|
||||
|
||||
+ // Paper start - Add Adventure message
|
||||
+ /**
|
||||
+ * Gets the message to send to all online players.
|
||||
+ * <p>
|
||||
+ * Will be null if the advancement does not announce to chat, for example if
|
||||
+ * it is a recipe unlock or a root advancement.
|
||||
+ *
|
||||
+ * @return The announcement message, or null
|
||||
+ */
|
||||
+ @Nullable
|
||||
+ public Component message() {
|
||||
+ return this.message;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Sets the message to send to all online players.
|
||||
+ * <p>
|
||||
+ * If set to null the message will not be sent.
|
||||
+ *
|
||||
+ * @param message The new message
|
||||
+ */
|
||||
+ public void message(@Nullable Component message) {
|
||||
+ this.message = message;
|
||||
+ }
|
||||
+ // Paper end
|
||||
@NotNull
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
|
@ -0,0 +1,89 @@
|
|||
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
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue