mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-21 16:09:19 +00:00
111 lines
7.3 KiB
Diff
111 lines
7.3 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
|
|
Date: Sun, 2 Jun 2024 01:21:36 +0800
|
|
Subject: [PATCH] Configurable connection message
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
index 230eef32faed2c7744447e23f5608790c1d491a8..180b50c9c23c6934d3e99500a25635df32f7169c 100644
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
@@ -26,6 +26,7 @@ import java.util.UUID;
|
|
import java.util.function.Function;
|
|
import java.util.function.Predicate;
|
|
import javax.annotation.Nullable;
|
|
+import net.kyori.adventure.text.TextReplacementConfig;
|
|
import net.minecraft.ChatFormatting;
|
|
import net.minecraft.FileUtil;
|
|
import net.minecraft.commands.CommandSourceStack;
|
|
@@ -354,7 +355,7 @@ public abstract class PlayerList {
|
|
// Ensure that player inventory is populated with its viewer
|
|
player.containerMenu.transferTo(player.containerMenu, bukkitPlayer);
|
|
|
|
- PlayerJoinEvent playerJoinEvent = new PlayerJoinEvent(bukkitPlayer, io.papermc.paper.adventure.PaperAdventure.asAdventure(ichatmutablecomponent)); // Paper - Adventure
|
|
+ PlayerJoinEvent playerJoinEvent = new PlayerJoinEvent(bukkitPlayer, getJoinMsg(io.papermc.paper.adventure.PaperAdventure.asAdventure(ichatmutablecomponent), bukkitPlayer)); // Paper - Adventure // Leaf - Configurable connection message - join message
|
|
this.cserver.getPluginManager().callEvent(playerJoinEvent);
|
|
|
|
if (!player.connection.isAcceptingMessages()) {
|
|
@@ -367,7 +368,7 @@ public abstract class PlayerList {
|
|
|
|
final net.kyori.adventure.text.Component jm = playerJoinEvent.joinMessage();
|
|
|
|
- if (jm != null && !jm.equals(net.kyori.adventure.text.Component.empty())) { // Paper - Adventure
|
|
+ if (org.dreeam.leaf.config.modules.misc.ConnectionMessage.joinEnabled && jm != null && !jm.equals(net.kyori.adventure.text.Component.empty())) { // Paper - Adventure // Leaf - Configurable connection message - join message
|
|
joinMessage = io.papermc.paper.adventure.PaperAdventure.asVanilla(jm); // Paper - Adventure
|
|
this.server.getPlayerList().broadcastSystemMessage(joinMessage, false); // Paper - Adventure
|
|
}
|
|
@@ -625,7 +626,7 @@ public abstract class PlayerList {
|
|
entityplayer.closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason.DISCONNECT); // Paper - Inventory close reason
|
|
}
|
|
|
|
- PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(entityplayer.getBukkitEntity(), net.kyori.adventure.text.Component.translatable("multiplayer.player.left", net.kyori.adventure.text.format.NamedTextColor.YELLOW, io.papermc.paper.configuration.GlobalConfiguration.get().messages.useDisplayNameInQuitMessage ? entityplayer.getBukkitEntity().displayName() : io.papermc.paper.adventure.PaperAdventure.asAdventure(entityplayer.getDisplayName())), entityplayer.quitReason); // Paper - Adventure & Add API for quit reason
|
|
+ PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(entityplayer.getBukkitEntity(), getQuitMsg(net.kyori.adventure.text.Component.translatable("multiplayer.player.left", net.kyori.adventure.text.format.NamedTextColor.YELLOW, io.papermc.paper.configuration.GlobalConfiguration.get().messages.useDisplayNameInQuitMessage ? entityplayer.getBukkitEntity().displayName() : io.papermc.paper.adventure.PaperAdventure.asAdventure(entityplayer.getDisplayName())), entityplayer.getBukkitEntity()), entityplayer.quitReason); // Paper - Adventure & Add API for quit reason // Leaf - Configurable connection message - quit message
|
|
this.cserver.getPluginManager().callEvent(playerQuitEvent);
|
|
entityplayer.getBukkitEntity().disconnect(playerQuitEvent.getQuitMessage());
|
|
|
|
@@ -1645,4 +1646,29 @@ public abstract class PlayerList {
|
|
public boolean isAllowCommandsForAllPlayers() {
|
|
return this.allowCommandsForAllPlayers;
|
|
}
|
|
+
|
|
+ // Leaf start - Configurable connection message - join message
|
|
+ private net.kyori.adventure.text.Component getJoinMsg(net.kyori.adventure.text.Component defaultJoinMsg, Player player) {
|
|
+ if (org.dreeam.leaf.config.modules.misc.ConnectionMessage.joinEnabled) {
|
|
+ return org.dreeam.leaf.config.modules.misc.ConnectionMessage.joinMessage.equals("default")
|
|
+ ? defaultJoinMsg
|
|
+ : net.kyori.adventure.text.minimessage.MiniMessage.miniMessage().deserialize(org.dreeam.leaf.config.modules.misc.ConnectionMessage.joinMessage)
|
|
+ .replaceText(TextReplacementConfig.builder().matchLiteral("%player_name%").replacement(player.getName()).build())
|
|
+ .replaceText(TextReplacementConfig.builder().matchLiteral("%player_displayname%").replacement(player.displayName()).build());
|
|
+ }
|
|
+
|
|
+ return net.kyori.adventure.text.Component.empty();
|
|
+ }
|
|
+ private net.kyori.adventure.text.Component getQuitMsg(net.kyori.adventure.text.Component defaultQuitMsg, Player player) {
|
|
+ if (org.dreeam.leaf.config.modules.misc.ConnectionMessage.quitEnabled) {
|
|
+ return org.dreeam.leaf.config.modules.misc.ConnectionMessage.quitMessage.equals("default")
|
|
+ ? defaultQuitMsg
|
|
+ : net.kyori.adventure.text.minimessage.MiniMessage.miniMessage().deserialize(org.dreeam.leaf.config.modules.misc.ConnectionMessage.quitMessage)
|
|
+ .replaceText(TextReplacementConfig.builder().matchLiteral("%player_name%").replacement(player.getName()).build())
|
|
+ .replaceText(TextReplacementConfig.builder().matchLiteral("%player_displayname%").replacement(player.displayName()).build());
|
|
+ }
|
|
+
|
|
+ return net.kyori.adventure.text.Component.empty();
|
|
+ }
|
|
+ // Leaf end - Configurable connection message - join message
|
|
}
|
|
diff --git a/src/main/java/org/dreeam/leaf/config/modules/misc/ConnectionMessage.java b/src/main/java/org/dreeam/leaf/config/modules/misc/ConnectionMessage.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..66097fa632bfd2079d2deab211e76fd45f2e01bd
|
|
--- /dev/null
|
|
+++ b/src/main/java/org/dreeam/leaf/config/modules/misc/ConnectionMessage.java
|
|
@@ -0,0 +1,29 @@
|
|
+package org.dreeam.leaf.config.modules.misc;
|
|
+
|
|
+import com.electronwill.nightconfig.core.file.CommentedFileConfig;
|
|
+import org.dreeam.leaf.config.ConfigInfo;
|
|
+import org.dreeam.leaf.config.EnumConfigCategory;
|
|
+import org.dreeam.leaf.config.IConfigModule;
|
|
+
|
|
+public class ConnectionMessage implements IConfigModule {
|
|
+
|
|
+ @Override
|
|
+ public EnumConfigCategory getCategory() {
|
|
+ return EnumConfigCategory.MISC;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public String getBaseName() {
|
|
+ return "connection_message";
|
|
+ }
|
|
+
|
|
+ @ConfigInfo(baseName = "join.enabled")
|
|
+ public static boolean joinEnabled = true;
|
|
+ @ConfigInfo(baseName = "join.message", comments = "Join message of player, using MiniMessage format, set to 'default' to use vanilla join message.")
|
|
+ public static String joinMessage = "default";
|
|
+
|
|
+ @ConfigInfo(baseName = "quit.enabled")
|
|
+ public static boolean quitEnabled = true;
|
|
+ @ConfigInfo(baseName = "quit.message", comments = "Quit message of player, using MiniMessage format set to 'default' to use vanilla quit message.")
|
|
+ public static String quitMessage = "default";
|
|
+}
|