Adventure
Co-authored-by: zml <zml@stellardrift.ca> Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com> Co-authored-by: Yannick Lamprecht <yannicklamprecht@live.de>
This commit is contained in:
@@ -32,7 +32,7 @@ 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 org.spigotmc.CustomTimingsHandler timings; // Spigot
|
||||
|
||||
protected Command(@NotNull String name) {
|
||||
@@ -186,10 +186,10 @@ 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;
|
||||
@@ -327,7 +327,7 @@ public abstract class Command {
|
||||
@Deprecated(since = "1.20.4")
|
||||
@Nullable
|
||||
public String getPermissionMessage() {
|
||||
return permissionMessage;
|
||||
return net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serializeOrNull(permissionMessage); // Paper
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -398,7 +398,7 @@ public abstract class Command {
|
||||
@Deprecated(since = "1.20.4")
|
||||
@NotNull
|
||||
public Command setPermissionMessage(@Nullable String permissionMessage) {
|
||||
this.permissionMessage = permissionMessage;
|
||||
this.permissionMessage = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserializeOrNull(permissionMessage); // Paper
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -413,13 +413,61 @@ public abstract class Command {
|
||||
this.usageMessage = (usage == null) ? "" : usage;
|
||||
return this;
|
||||
}
|
||||
// Paper start
|
||||
/**
|
||||
* Gets the permission message.
|
||||
*
|
||||
* @return the permission message
|
||||
* @deprecated permission messages have not worked for player-executed
|
||||
* commands since 1.13 as clients without permission to execute a command
|
||||
* are unaware of its existence and therefore will not send an unknown
|
||||
* command execution to the server. This message will only ever be shown to
|
||||
* consoles or when this command is executed with
|
||||
* {@link Bukkit#dispatchCommand(CommandSender, String)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public net.kyori.adventure.text.@Nullable Component permissionMessage() {
|
||||
return this.permissionMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the permission message.
|
||||
*
|
||||
* @param permissionMessage the permission message
|
||||
* @deprecated permission messages have not worked for player-executed
|
||||
* commands since 1.13 as clients without permission to execute a command
|
||||
* are unaware of its existence and therefore will not send an unknown
|
||||
* command execution to the server. This message will only ever be shown to
|
||||
* consoles or when this command is executed with
|
||||
* {@link Bukkit#dispatchCommand(CommandSender, String)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public void permissionMessage(net.kyori.adventure.text.@Nullable Component permissionMessage) {
|
||||
this.permissionMessage = permissionMessage;
|
||||
}
|
||||
// Paper end
|
||||
|
||||
public static void broadcastCommandMessage(@NotNull CommandSender source, @NotNull String message) {
|
||||
broadcastCommandMessage(source, message, true);
|
||||
}
|
||||
|
||||
public static void broadcastCommandMessage(@NotNull CommandSender source, @NotNull String message, boolean sendToSource) {
|
||||
String result = source.getName() + ": " + message;
|
||||
// Paper start
|
||||
broadcastCommandMessage(source, net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(message), sendToSource);
|
||||
}
|
||||
|
||||
public static void broadcastCommandMessage(@NotNull CommandSender source, net.kyori.adventure.text.@NotNull Component message) {
|
||||
broadcastCommandMessage(source, message, true);
|
||||
}
|
||||
|
||||
public static void broadcastCommandMessage(@NotNull CommandSender source, net.kyori.adventure.text.@NotNull Component message, boolean sendToSource) {
|
||||
net.kyori.adventure.text.TextComponent.Builder result = net.kyori.adventure.text.Component.text()
|
||||
.color(net.kyori.adventure.text.format.NamedTextColor.WHITE)
|
||||
.decoration(net.kyori.adventure.text.format.TextDecoration.ITALIC, false)
|
||||
.append(source.name())
|
||||
.append(net.kyori.adventure.text.Component.text(": "))
|
||||
.append(message);
|
||||
// Paper end
|
||||
|
||||
if (source instanceof BlockCommandSender) {
|
||||
BlockCommandSender blockCommandSender = (BlockCommandSender) source;
|
||||
@@ -438,7 +486,12 @@ public abstract class Command {
|
||||
}
|
||||
|
||||
Set<Permissible> users = Bukkit.getPluginManager().getPermissionSubscriptions(Server.BROADCAST_CHANNEL_ADMINISTRATIVE);
|
||||
String colored = ChatColor.GRAY + "" + ChatColor.ITALIC + "[" + result + ChatColor.GRAY + ChatColor.ITALIC + "]";
|
||||
// Paper start
|
||||
net.kyori.adventure.text.TextComponent.Builder colored = net.kyori.adventure.text.Component.text()
|
||||
.color(net.kyori.adventure.text.format.NamedTextColor.GRAY)
|
||||
.decorate(net.kyori.adventure.text.format.TextDecoration.ITALIC)
|
||||
.append(net.kyori.adventure.text.Component.text("["), result, net.kyori.adventure.text.Component.text("]"));
|
||||
// Paper end
|
||||
|
||||
if (sendToSource && !(source instanceof ConsoleCommandSender)) {
|
||||
source.sendMessage(message);
|
||||
|
||||
@@ -6,20 +6,28 @@ import org.bukkit.permissions.Permissible;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface CommandSender extends Permissible {
|
||||
public interface CommandSender extends net.kyori.adventure.audience.Audience, Permissible { // Paper
|
||||
|
||||
/**
|
||||
* Sends this sender a message
|
||||
*
|
||||
* @param message Message to be displayed
|
||||
* @see #sendMessage(net.kyori.adventure.text.Component)
|
||||
* @see #sendPlainMessage(String)
|
||||
* @see #sendRichMessage(String)
|
||||
*/
|
||||
@org.jetbrains.annotations.ApiStatus.Obsolete // Paper
|
||||
public void sendMessage(@NotNull String message);
|
||||
|
||||
/**
|
||||
* Sends this sender multiple messages
|
||||
*
|
||||
* @param messages An array of messages to be displayed
|
||||
* @see #sendMessage(net.kyori.adventure.text.Component)
|
||||
* @see #sendPlainMessage(String)
|
||||
* @see #sendRichMessage(String)
|
||||
*/
|
||||
@org.jetbrains.annotations.ApiStatus.Obsolete // Paper
|
||||
public void sendMessage(@NotNull String... messages);
|
||||
|
||||
/**
|
||||
@@ -27,7 +35,10 @@ public interface CommandSender extends Permissible {
|
||||
*
|
||||
* @param message Message to be displayed
|
||||
* @param sender The sender of this message
|
||||
* @see #sendMessage(net.kyori.adventure.identity.Identified, net.kyori.adventure.text.Component)
|
||||
* @deprecated sender UUID is ignored
|
||||
*/
|
||||
@Deprecated // Paper
|
||||
public void sendMessage(@Nullable UUID sender, @NotNull String message);
|
||||
|
||||
/**
|
||||
@@ -35,7 +46,10 @@ public interface CommandSender extends Permissible {
|
||||
*
|
||||
* @param messages An array of messages to be displayed
|
||||
* @param sender The sender of this message
|
||||
* @see #sendMessage(net.kyori.adventure.identity.Identified, net.kyori.adventure.text.Component)
|
||||
* @deprecated sender UUID is ignored
|
||||
*/
|
||||
@Deprecated // Paper
|
||||
public void sendMessage(@Nullable UUID sender, @NotNull String... messages);
|
||||
|
||||
/**
|
||||
@@ -61,7 +75,9 @@ public interface CommandSender extends Permissible {
|
||||
* Sends this sender a chat component.
|
||||
*
|
||||
* @param component the components to send
|
||||
* @deprecated use {@code sendMessage} methods that accept {@link net.kyori.adventure.text.Component}
|
||||
*/
|
||||
@Deprecated // Paper
|
||||
public void sendMessage(@NotNull net.md_5.bungee.api.chat.BaseComponent component) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
@@ -70,7 +86,9 @@ public interface CommandSender extends Permissible {
|
||||
* Sends an array of components as a single message to the sender.
|
||||
*
|
||||
* @param components the components to send
|
||||
* @deprecated use {@code sendMessage} methods that accept {@link net.kyori.adventure.text.Component}
|
||||
*/
|
||||
@Deprecated // Paper
|
||||
public void sendMessage(@NotNull net.md_5.bungee.api.chat.BaseComponent... components) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
@@ -80,7 +98,9 @@ public interface CommandSender extends Permissible {
|
||||
*
|
||||
* @param component the components to send
|
||||
* @param sender the sender of the message
|
||||
* @deprecated use {@code sendMessage} methods that accept {@link net.kyori.adventure.text.Component}
|
||||
*/
|
||||
@Deprecated // Paper
|
||||
public void sendMessage(@Nullable UUID sender, @NotNull net.md_5.bungee.api.chat.BaseComponent component) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
@@ -90,7 +110,9 @@ public interface CommandSender extends Permissible {
|
||||
*
|
||||
* @param components the components to send
|
||||
* @param sender the sender of the message
|
||||
* @deprecated use {@code sendMessage} methods that accept {@link net.kyori.adventure.text.Component}
|
||||
*/
|
||||
@Deprecated // Paper
|
||||
public void sendMessage(@Nullable UUID sender, @NotNull net.md_5.bungee.api.chat.BaseComponent... components) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
@@ -99,4 +121,52 @@ public interface CommandSender extends Permissible {
|
||||
@NotNull
|
||||
Spigot spigot();
|
||||
// Spigot end
|
||||
|
||||
// Paper start
|
||||
/**
|
||||
* Gets the name of this command sender
|
||||
*
|
||||
* @return Name of the sender
|
||||
*/
|
||||
public net.kyori.adventure.text.@NotNull Component name();
|
||||
|
||||
@Override
|
||||
default void sendMessage(final net.kyori.adventure.identity.@NotNull Identity identity, final net.kyori.adventure.text.@NotNull Component message, final net.kyori.adventure.audience.@NotNull MessageType type) {
|
||||
this.sendMessage(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message with the MiniMessage format to the command sender.
|
||||
* <p>
|
||||
* See <a href="https://docs.advntr.dev/minimessage/">MiniMessage docs</a>
|
||||
* for more information on the format.
|
||||
*
|
||||
* @param message MiniMessage content
|
||||
*/
|
||||
default void sendRichMessage(final @NotNull String message) {
|
||||
this.sendMessage(net.kyori.adventure.text.minimessage.MiniMessage.miniMessage().deserialize(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message with the MiniMessage format to the command sender.
|
||||
* <p>
|
||||
* See <a href="https://docs.advntr.dev/minimessage/">MiniMessage docs</a> and <a href="https://docs.advntr.dev/minimessage/dynamic-replacements">MiniMessage Placeholders docs</a>
|
||||
* for more information on the format.
|
||||
*
|
||||
* @param message MiniMessage content
|
||||
* @param resolvers resolvers to use
|
||||
*/
|
||||
default void sendRichMessage(final @NotNull String message, final net.kyori.adventure.text.minimessage.tag.resolver.@NotNull TagResolver... resolvers) {
|
||||
this.sendMessage(net.kyori.adventure.text.minimessage.MiniMessage.miniMessage().deserialize(message, resolvers));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a plain message to the command sender.
|
||||
*
|
||||
* @param message plain message
|
||||
*/
|
||||
default void sendPlainMessage(final @NotNull String message) {
|
||||
this.sendMessage(net.kyori.adventure.text.Component.text(message));
|
||||
}
|
||||
// Paper end
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ public class PluginCommandYamlParser {
|
||||
}
|
||||
|
||||
if (permissionMessage != null) {
|
||||
newCmd.setPermissionMessage(permissionMessage.toString());
|
||||
newCmd.permissionMessage(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(permissionMessage.toString())); // Paper
|
||||
}
|
||||
|
||||
pluginCmds.add(newCmd);
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.bukkit.command;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface ProxiedCommandSender extends CommandSender {
|
||||
public interface ProxiedCommandSender extends CommandSender, net.kyori.adventure.audience.ForwardingAudience.Single { // Paper
|
||||
|
||||
/**
|
||||
* Returns the CommandSender which triggered this proxied command
|
||||
@@ -21,4 +21,16 @@ public interface ProxiedCommandSender extends CommandSender {
|
||||
@NotNull
|
||||
CommandSender getCallee();
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
default void sendMessage(final net.kyori.adventure.identity.@NotNull Identity source, final net.kyori.adventure.text.@NotNull Component message, final net.kyori.adventure.audience.@NotNull MessageType type) {
|
||||
net.kyori.adventure.audience.ForwardingAudience.Single.super.sendMessage(source, message, type);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
default net.kyori.adventure.audience.Audience audience() {
|
||||
return this.getCaller();
|
||||
}
|
||||
// Paper end
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user