Skip to content

Commit

Permalink
Configurable unknown command message
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreeam-qwq committed Aug 7, 2024
1 parent b5e6aa5 commit f316aff
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 2 deletions.
80 changes: 80 additions & 0 deletions patches/server/0080-Configurable-unknown-command-message.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
Date: Wed, 7 Aug 2024 18:54:01 +0800
Subject: [PATCH] Configurable unknown command message


diff --git a/src/main/java/net/minecraft/commands/Commands.java b/src/main/java/net/minecraft/commands/Commands.java
index 94bb40c9932b0b7dd9fb8af680b63d139ae18e3a..f5446158a83d5ccd79988ab71f2c4df220b39167 100644
--- a/src/main/java/net/minecraft/commands/Commands.java
+++ b/src/main/java/net/minecraft/commands/Commands.java
@@ -388,7 +388,14 @@ public class Commands {
// Paper start - Add UnknownCommandEvent
final net.kyori.adventure.text.TextComponent.Builder builder = net.kyori.adventure.text.Component.text();
// commandlistenerwrapper.sendFailure(ComponentUtils.fromMessage(commandsyntaxexception.getRawMessage()));
+ // Leaf start - Configurable unknown command message
+ if (!"default".equals(org.dreeam.leaf.config.modules.misc.UnknownCommandMessage.unknownCommandMessage)) {
+ net.kyori.adventure.text.Component message = net.kyori.adventure.text.minimessage.MiniMessage.miniMessage().deserialize(org.dreeam.leaf.config.modules.misc.UnknownCommandMessage.unknownCommandMessage);
+ builder.append(message);
+ } else {
builder.color(net.kyori.adventure.text.format.NamedTextColor.RED).append(io.papermc.paper.brigadier.PaperBrigadier.componentFromMessage(commandsyntaxexception.getRawMessage()));
+ }
+ // Leaf end - Configurable unknown command message
// Paper end - Add UnknownCommandEvent
if (commandsyntaxexception.getInput() != null && commandsyntaxexception.getCursor() >= 0) {
int i = Math.min(commandsyntaxexception.getInput().length(), commandsyntaxexception.getCursor());
@@ -414,7 +421,7 @@ public class Commands {
.append(net.kyori.adventure.text.Component.newline())
.append(io.papermc.paper.adventure.PaperAdventure.asAdventure(ichatmutablecomponent));
}
- org.bukkit.event.command.UnknownCommandEvent event = new org.bukkit.event.command.UnknownCommandEvent(commandlistenerwrapper.getBukkitSender(), s, org.spigotmc.SpigotConfig.unknownCommandMessage.isEmpty() ? null : builder.build());
+ org.bukkit.event.command.UnknownCommandEvent event = new org.bukkit.event.command.UnknownCommandEvent(commandlistenerwrapper.getBukkitSender(), s, builder.build()); // Leaf - Configurable unknown command message
org.bukkit.Bukkit.getServer().getPluginManager().callEvent(event);
if (event.message() != null) {
commandlistenerwrapper.sendFailure(io.papermc.paper.adventure.PaperAdventure.asVanilla(event.message()), false);
diff --git a/src/main/java/org/dreeam/leaf/config/modules/misc/UnknownCommandMessage.java b/src/main/java/org/dreeam/leaf/config/modules/misc/UnknownCommandMessage.java
new file mode 100644
index 0000000000000000000000000000000000000000..cfa68915552899ce6ec0b202e1d6cf8a1ca0a777
--- /dev/null
+++ b/src/main/java/org/dreeam/leaf/config/modules/misc/UnknownCommandMessage.java
@@ -0,0 +1,20 @@
+package org.dreeam.leaf.config.modules.misc;
+
+import org.dreeam.leaf.config.ConfigModules;
+import org.dreeam.leaf.config.EnumConfigCategory;
+
+public class UnknownCommandMessage extends ConfigModules {
+
+ public String getBasePath() {
+ return EnumConfigCategory.MISC.getBaseKeyName() + ".message";
+ }
+
+ public static String unknownCommandMessage = "<red><lang:command.unknown.command>";
+
+ @Override
+ public void onLoaded() {
+ unknownCommandMessage = config.getString(getBasePath() + ".unknown-command", unknownCommandMessage, """
+ Unknown command message, using MiniMessage format, set to "default" to use vanilla message.
+ """);
+ }
+}
diff --git a/src/main/java/org/spigotmc/SpigotConfig.java b/src/main/java/org/spigotmc/SpigotConfig.java
index 4dbb109d0526afee99b9190fc256585121aac9b5..3de9968bc87b3dc024e423b382eb611135bf1b2c 100644
--- a/src/main/java/org/spigotmc/SpigotConfig.java
+++ b/src/main/java/org/spigotmc/SpigotConfig.java
@@ -191,7 +191,6 @@ public class SpigotConfig
}

public static String whitelistMessage;
- public static String unknownCommandMessage;
public static String serverFullMessage;
public static String outdatedClientMessage = "Outdated client! Please use {0}";
public static String outdatedServerMessage = "Outdated server! I\'m still on {0}";
@@ -208,7 +207,6 @@ public class SpigotConfig
}

SpigotConfig.whitelistMessage = SpigotConfig.transform( SpigotConfig.getString( "messages.whitelist", "You are not whitelisted on this server!" ) );
- SpigotConfig.unknownCommandMessage = SpigotConfig.transform( SpigotConfig.getString( "messages.unknown-command", "Unknown command. Type \"/help\" for help." ) );
SpigotConfig.serverFullMessage = SpigotConfig.transform( SpigotConfig.getString( "messages.server-full", "The server is full!" ) );
SpigotConfig.outdatedClientMessage = SpigotConfig.transform( SpigotConfig.getString( "messages.outdated-client", SpigotConfig.outdatedClientMessage ) );
SpigotConfig.outdatedServerMessage = SpigotConfig.transform( SpigotConfig.getString( "messages.outdated-server", SpigotConfig.outdatedServerMessage ) );
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Subject: [PATCH] Fix-MC-119417
Related MC issue: https://bugs.mojang.com/browse/MC-119417

diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index 2f4096cb2bf93f880d01283df8d10bf996e72bb9..723f03aedc66cfc0e7d6f5b2a1c541f9055601b6 100644
index 0782cdddcb7e79260dd8c3b75760aaab95a378de..9941f0659b98ddb385172f7fb7d00ff3f723dff3 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -2257,6 +2257,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player imple
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Remove stream and remove double Mth.floor() convert
before 1700ms, after 370ms, in massive stacked minecart test

diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 0a40cff1da82157487d209e63628387092d0d334..bdf7fbe1e7e18996e387df3b186a6f4db7352769 100644
index 164c126a61f550c09a7e114bf8947bde1c5a3aa8..e8332ab62a6759563bbfd76b8f8a7193297a3d31 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -1337,9 +1337,12 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
Expand Down

0 comments on commit f316aff

Please sign in to comment.