mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 23:38:25 +01:00
Support components in command permission msgs (#6676)
This commit is contained in:
parent
a0cb2fd31d
commit
faa6373f4a
2 changed files with 92 additions and 8 deletions
|
@ -1220,6 +1220,78 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
public void setLine(int index, @NotNull String line) throws IndexOutOfBoundsException;
|
||||
|
||||
/**
|
||||
diff --git a/src/main/java/org/bukkit/command/Command.java b/src/main/java/org/bukkit/command/Command.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/command/Command.java
|
||||
+++ b/src/main/java/org/bukkit/command/Command.java
|
||||
@@ -0,0 +0,0 @@ public abstract class Command {
|
||||
protected String description;
|
||||
protected String usageMessage;
|
||||
private String permission;
|
||||
- private String permissionMessage;
|
||||
+ private net.kyori.adventure.text.Component permissionMessage; // Paper
|
||||
public co.aikar.timings.Timing timings; // Paper
|
||||
@NotNull public String getTimingName() {return getName();} // Paper
|
||||
|
||||
@@ -0,0 +0,0 @@ public abstract class Command {
|
||||
|
||||
if (permissionMessage == null) {
|
||||
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.");
|
||||
- } else if (permissionMessage.length() != 0) {
|
||||
- for (String line : permissionMessage.replace("<permission>", permission).split("\n")) {
|
||||
- target.sendMessage(line);
|
||||
- }
|
||||
+ // Paper start - use components for permissionMessage
|
||||
+ } else 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
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -0,0 +0,0 @@ public abstract class Command {
|
||||
* command
|
||||
*
|
||||
* @return Permission check failed message
|
||||
+ * @deprecated use {@link #permissionMessage()}
|
||||
*/
|
||||
@Nullable
|
||||
+ @Deprecated // Paper
|
||||
public String getPermissionMessage() {
|
||||
- return permissionMessage;
|
||||
+ return io.papermc.paper.text.PaperComponents.legacySectionSerializer().serialize(permissionMessage); // Paper
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -0,0 +0,0 @@ public abstract class Command {
|
||||
* @param permissionMessage new permission message, null to indicate
|
||||
* default message, or an empty string to indicate no message
|
||||
* @return this command object, for chaining
|
||||
+ * @deprecated use {@link #permissionMessage(net.kyori.adventure.text.Component)}
|
||||
*/
|
||||
@NotNull
|
||||
+ @Deprecated // Paper
|
||||
public Command setPermissionMessage(@Nullable String permissionMessage) {
|
||||
- this.permissionMessage = permissionMessage;
|
||||
+ this.permissionMessage = io.papermc.paper.text.PaperComponents.legacySectionSerializer().deserializeOrNull(permissionMessage); // Paper
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -0,0 +0,0 @@ public abstract class Command {
|
||||
this.usageMessage = (usage == null) ? "" : usage;
|
||||
return this;
|
||||
}
|
||||
+ // Paper start
|
||||
+ public @Nullable net.kyori.adventure.text.Component permissionMessage() {
|
||||
+ return this.permissionMessage;
|
||||
+ }
|
||||
+
|
||||
+ public void permissionMessage(@Nullable net.kyori.adventure.text.Component permissionMessage) {
|
||||
+ this.permissionMessage = permissionMessage;
|
||||
+ }
|
||||
+ // Paper end
|
||||
|
||||
public static void broadcastCommandMessage(@NotNull CommandSender source, @NotNull String message) {
|
||||
broadcastCommandMessage(source, message, true);
|
||||
diff --git a/src/main/java/org/bukkit/command/CommandSender.java b/src/main/java/org/bukkit/command/CommandSender.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/command/CommandSender.java
|
||||
|
@ -1339,6 +1411,19 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
|
||||
@Override
|
||||
default boolean isOp() {
|
||||
diff --git a/src/main/java/org/bukkit/command/PluginCommandYamlParser.java b/src/main/java/org/bukkit/command/PluginCommandYamlParser.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/command/PluginCommandYamlParser.java
|
||||
+++ b/src/main/java/org/bukkit/command/PluginCommandYamlParser.java
|
||||
@@ -0,0 +0,0 @@ public class PluginCommandYamlParser {
|
||||
}
|
||||
|
||||
if (permissionMessage != null) {
|
||||
- newCmd.setPermissionMessage(permissionMessage.toString());
|
||||
+ newCmd.permissionMessage(io.papermc.paper.text.PaperComponents.legacySectionSerializer().deserialize(permissionMessage.toString())); // Paper
|
||||
}
|
||||
|
||||
pluginCmds.add(newCmd);
|
||||
diff --git a/src/main/java/org/bukkit/command/ProxiedCommandSender.java b/src/main/java/org/bukkit/command/ProxiedCommandSender.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/command/ProxiedCommandSender.java
|
||||
|
|
|
@ -52,11 +52,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
|
||||
- if (permissionMessage == null) {
|
||||
- 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.");
|
||||
- } else if (permissionMessage.length() != 0) {
|
||||
+ // Paper start
|
||||
+ String permissionMessage = this.permissionMessage != null ? this.permissionMessage : Bukkit.getPermissionMessage();
|
||||
+ if (!permissionMessage.isBlank()) {
|
||||
+ // Paper end
|
||||
for (String line : permissionMessage.replace("<permission>", permission).split("\n")) {
|
||||
target.sendMessage(line);
|
||||
}
|
||||
// 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 : io.papermc.paper.text.PaperComponents.legacySectionSerializer().deserialize(Bukkit.getPermissionMessage());
|
||||
+ 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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue