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:
Riley Park
2021-01-29 17:21:55 +01:00
parent 8888031206
commit 15081a5912
70 changed files with 3298 additions and 160 deletions
@@ -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);