Paper/patches/api/0164-Make-the-default-permission-message-configurable.patch

85 lines
3.5 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Shane Freeder <theboyetronic@gmail.com>
Date: Sun, 18 Nov 2018 19:44:54 +0000
Subject: [PATCH] Make the default permission message configurable
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
index 1c416a48d2a069a0167bc0be6fa1d65d14f35816..62ecce029f38bd6a3e07981887916bb54e0c62f9 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/Bukkit.java
+++ b/src/main/java/org/bukkit/Bukkit.java
@@ -2180,6 +2180,28 @@ public final class Bukkit {
2021-06-11 14:02:28 +02:00
return server.suggestPlayerNamesWhenNullTabCompletions();
}
+ /**
2022-06-10 01:19:38 +02:00
+ * Gets the default no permission message used on the server
2021-06-11 14:02:28 +02:00
+ *
2022-06-10 01:19:38 +02:00
+ * @return the default message
+ * @deprecated use {@link #permissionMessage()}
2021-06-11 14:02:28 +02:00
+ */
+ @NotNull
2022-06-10 01:19:38 +02:00
+ @Deprecated
2021-06-11 14:02:28 +02:00
+ public static String getPermissionMessage() {
+ return server.getPermissionMessage();
+ }
2022-06-10 01:19:38 +02:00
+
+ /**
+ * Gets the default no permission message used on the server
+ *
+ * @return the default message
+ */
+ @NotNull
+ public static net.kyori.adventure.text.Component permissionMessage() {
+ return server.permissionMessage();
+ }
2021-06-11 14:02:28 +02:00
+
/**
* Creates a PlayerProfile for the specified uuid, with name as null.
*
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
index 1a4559c88ece08e4a0c27e808f69693fb89fc474..85a0de6277aff8a81c8e58b3b29b98d99b6b1fb9 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
@@ -1894,6 +1894,23 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
2021-06-11 14:02:28 +02:00
*/
boolean suggestPlayerNamesWhenNullTabCompletions();
+ /**
2022-06-09 23:11:43 +02:00
+ * Gets the default no permission message used on the server
2021-06-11 14:02:28 +02:00
+ *
2022-06-09 23:11:43 +02:00
+ * @return the default message
+ * @deprecated use {@link #permissionMessage()}
2021-06-11 14:02:28 +02:00
+ */
+ @NotNull
2022-06-09 23:11:43 +02:00
+ @Deprecated
2021-06-11 14:02:28 +02:00
+ String getPermissionMessage();
2022-06-09 23:11:43 +02:00
+
+ /**
+ * Gets the default no permission message used on the server
+ *
+ * @return the default message
+ */
+ @NotNull net.kyori.adventure.text.Component permissionMessage();
2021-06-11 14:02:28 +02:00
+
/**
* Creates a PlayerProfile for the specified uuid, with name as null.
*
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/command/Command.java b/src/main/java/org/bukkit/command/Command.java
index a26df5f6341d22ecd5e71da59b8f091848e627ad..608b541aef01f33891a492fff5b8400496832c3a 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/command/Command.java
+++ b/src/main/java/org/bukkit/command/Command.java
@@ -184,10 +184,9 @@ public abstract class Command {
return true;
2021-06-11 14:02:28 +02:00
}
- if (permissionMessage == null) {
2021-06-11 14:02:28 +02:00
- target.sendMessage(ChatColor.RED + "I'm sorry, but you do not have permission to perform this command. Please contact the server administrators if you believe that this is a mistake.");
// Paper start - use components for permissionMessage
- } else if (!permissionMessage.equals(net.kyori.adventure.text.Component.empty())) {
+ net.kyori.adventure.text.Component permissionMessage = this.permissionMessage != null ? this.permissionMessage : Bukkit.permissionMessage();
+ if (!permissionMessage.equals(net.kyori.adventure.text.Component.empty())) {
target.sendMessage(permissionMessage.replaceText(net.kyori.adventure.text.TextReplacementConfig.builder().matchLiteral("<permission>").replacement(permission).build()));
// Paper end
}