Brigadier based command API
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
This commit is contained in:
@@ -520,4 +520,9 @@ public abstract class Command {
|
||||
public String toString() {
|
||||
return getClass().getName() + '(' + name + ')';
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@org.jetbrains.annotations.ApiStatus.Internal
|
||||
public boolean canBeOverriden() { return false; }
|
||||
// Paper end
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ public class FormattedCommandAlias extends Command {
|
||||
index = formatString.indexOf('$', index);
|
||||
}
|
||||
|
||||
return formatString;
|
||||
return formatString.trim(); // Paper - Causes an extra space at the end, breaks with brig commands
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -23,10 +23,14 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class SimpleCommandMap implements CommandMap {
|
||||
protected final Map<String, Command> knownCommands = new HashMap<String, Command>();
|
||||
protected final Map<String, Command> knownCommands; // Paper
|
||||
private final Server server;
|
||||
|
||||
public SimpleCommandMap(@NotNull final Server server) {
|
||||
// Paper start
|
||||
@org.jetbrains.annotations.ApiStatus.Internal
|
||||
public SimpleCommandMap(@NotNull final Server server, Map<String, Command> backing) {
|
||||
this.knownCommands = backing;
|
||||
// Paper end
|
||||
this.server = server;
|
||||
setDefaultCommands();
|
||||
}
|
||||
@@ -103,7 +107,10 @@ public class SimpleCommandMap implements CommandMap {
|
||||
*/
|
||||
private synchronized boolean register(@NotNull String label, @NotNull Command command, boolean isAlias, @NotNull String fallbackPrefix) {
|
||||
knownCommands.put(fallbackPrefix + ":" + label, command);
|
||||
if ((command instanceof BukkitCommand || isAlias) && knownCommands.containsKey(label)) {
|
||||
// Paper start
|
||||
Command known = knownCommands.get(label);
|
||||
if ((command instanceof BukkitCommand || isAlias) && (known != null && !known.canBeOverriden())) {
|
||||
// Paper end
|
||||
// Request is for an alias/fallback command and it conflicts with
|
||||
// a existing command or previous alias ignore it
|
||||
// Note: This will mean it gets removed from the commands list of active aliases
|
||||
@@ -115,7 +122,9 @@ public class SimpleCommandMap implements CommandMap {
|
||||
// If the command exists but is an alias we overwrite it, otherwise we return
|
||||
Command conflict = knownCommands.get(label);
|
||||
if (conflict != null && conflict.getLabel().equals(label)) {
|
||||
if (!conflict.canBeOverriden()) { // Paper
|
||||
return false;
|
||||
} // Paper
|
||||
}
|
||||
|
||||
if (!isAlias) {
|
||||
|
||||
@@ -18,6 +18,9 @@ public class ReloadCommand extends BukkitCommand {
|
||||
this.setAliases(Arrays.asList("rl"));
|
||||
}
|
||||
|
||||
@org.jetbrains.annotations.ApiStatus.Internal // Paper
|
||||
public static final String RELOADING_DISABLED_MESSAGE = "A lifecycle event handler has been registered which makes reloading plugins not possible"; // Paper
|
||||
|
||||
@Override
|
||||
public boolean execute(@NotNull CommandSender sender, @NotNull String currentAlias, @NotNull String[] args) { // Paper
|
||||
if (!testPermission(sender)) return true;
|
||||
@@ -51,7 +54,16 @@ public class ReloadCommand extends BukkitCommand {
|
||||
|
||||
Command.broadcastCommandMessage(sender, ChatColor.RED + "Please note that this command is not supported and may cause issues when using some plugins.");
|
||||
Command.broadcastCommandMessage(sender, ChatColor.RED + "If you encounter any issues please use the /stop command to restart your server.");
|
||||
Bukkit.reload();
|
||||
// Paper start - lifecycle events
|
||||
try {
|
||||
Bukkit.reload();
|
||||
} catch (final IllegalStateException ex) {
|
||||
if (ex.getMessage().equals(RELOADING_DISABLED_MESSAGE)) {
|
||||
Command.broadcastCommandMessage(sender, ChatColor.RED + RELOADING_DISABLED_MESSAGE);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// Paper end - lifecycle events
|
||||
Command.broadcastCommandMessage(sender, ChatColor.GREEN + "Reload complete.");
|
||||
|
||||
return true;
|
||||
|
||||
@@ -18,6 +18,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
* themselves. Plugins wishing to remove commands from tab completion are
|
||||
* advised to ensure the client does not have permission for the relevant
|
||||
* commands, or use {@link PlayerCommandSendEvent}.
|
||||
* @apiNote Only called for bukkit API commands {@link org.bukkit.command.Command} and
|
||||
* {@link org.bukkit.command.CommandExecutor} and not for brigadier commands ({@link io.papermc.paper.command.brigadier.Commands}).
|
||||
*/
|
||||
public class TabCompleteEvent extends Event implements Cancellable {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user