mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2026-02-06 12:17:13 +01:00
@@ -1,42 +1,52 @@
|
||||
package me.clip.placeholderapi.commands;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class Command {
|
||||
private static final Options EMPTY_OPTIONS = new Options(null, 0);
|
||||
private static final Options EMPTY_OPTIONS = new Options(null, 0, null);
|
||||
|
||||
private final String match;
|
||||
private final String usage;
|
||||
private final int minimumArguments;
|
||||
/**
|
||||
* Commands should not have multiple permissions. This can lead to a lot of confusions.
|
||||
* This is also a lot more appropriate for maintainability, I saw a lot of commands regitered with wrong permissions.
|
||||
* We will use the main command name to parse our permission.
|
||||
*/
|
||||
private final String permission;
|
||||
private final Set<String> permissions;
|
||||
|
||||
protected Command(String match) {
|
||||
protected Command(@NotNull final String match) {
|
||||
this(match, EMPTY_OPTIONS);
|
||||
}
|
||||
|
||||
protected Command(String match, Options options) {
|
||||
protected Command(@NotNull final String match, @NotNull final Options options) {
|
||||
this.match = match;
|
||||
this.usage = options.usage == null ? "/papi " + match + " <required args> [optional args]" : options.usage;
|
||||
this.permission = "placeholderapi." + match.replace(' ', '.');
|
||||
this.permissions = options.permissions == null ? Collections.emptySet() : ImmutableSet.copyOf(options.permissions);
|
||||
this.minimumArguments = options.minimumArguments;
|
||||
}
|
||||
|
||||
protected static Options options(String usage, int minimumArguments) {
|
||||
return new Options(usage, minimumArguments);
|
||||
protected static Options usage(@NotNull final String usage, final int minimumArguments) {
|
||||
return new Options(usage, minimumArguments, null);
|
||||
}
|
||||
|
||||
protected static Options permissions(@NotNull final String... permissions) {
|
||||
return new Options(null, 0, permissions);
|
||||
}
|
||||
|
||||
protected static Options options(@NotNull final String usage, final int minimumArguments,
|
||||
@NotNull final String... permissions) {
|
||||
return new Options(usage, minimumArguments, permissions);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getMatch() {
|
||||
return match;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getUsage() {
|
||||
return usage;
|
||||
}
|
||||
@@ -45,23 +55,28 @@ public abstract class Command {
|
||||
return minimumArguments;
|
||||
}
|
||||
|
||||
public String getPermission() {
|
||||
return permission;
|
||||
@NotNull
|
||||
public Set<String> getPermissions() {
|
||||
return permissions;
|
||||
}
|
||||
|
||||
public abstract void execute(CommandSender sender, String[] args);
|
||||
public abstract void execute(@NotNull final CommandSender sender, @NotNull final String[] args);
|
||||
|
||||
public List<String> handleCompletion(CommandSender sender, String[] args) {
|
||||
@NotNull
|
||||
public List<String> handleCompletion(@NotNull final CommandSender sender, @NotNull final String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
private static class Options {
|
||||
private final String usage;
|
||||
private final int minimumArguments;
|
||||
private final String[] permissions;
|
||||
|
||||
private Options(String usage, int minimumArguments) {
|
||||
private Options(@Nullable final String usage, final int minimumArguments,
|
||||
@Nullable final String[] permissions) {
|
||||
this.usage = usage;
|
||||
this.minimumArguments = minimumArguments;
|
||||
this.permissions = permissions;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +1,25 @@
|
||||
package me.clip.placeholderapi.commands;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.commands.command.*;
|
||||
import me.clip.placeholderapi.commands.command.ecloud.EcloudInfoCommand;
|
||||
import me.clip.placeholderapi.commands.command.ecloud.EcloudListCommand;
|
||||
import me.clip.placeholderapi.commands.command.ecloud.*;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public final class CommandHandler implements CommandExecutor {
|
||||
private static final Command DEFAULT = new VersionCommand();
|
||||
|
||||
protected static final List<Command> COMMANDS = Lists.newArrayList(
|
||||
DEFAULT,
|
||||
new HelpCommand(),
|
||||
new InfoCommand(),
|
||||
new ListCommand(),
|
||||
new RegisterCommand(),
|
||||
new UnregisterCommand(),
|
||||
new ReloadCommand(),
|
||||
new BcParseCommand(),
|
||||
new ParseCommand(),
|
||||
new ParseRelCommand(),
|
||||
|
||||
new EcloudCommand(),
|
||||
private static final List<Command> COMMANDS = Lists.newArrayList(
|
||||
new EcloudClearCommand(),
|
||||
new EcloudDownloadCommand(),
|
||||
new EcloudInfoCommand(),
|
||||
@@ -36,57 +28,74 @@ public final class CommandHandler implements CommandExecutor {
|
||||
new EcloudRefreshCommand(),
|
||||
new EcloudStatusCommand(),
|
||||
new EcloudVersionInfoCommand(),
|
||||
new EcloudDisableCommand(),
|
||||
new EcloudEnableCommand()
|
||||
new EcloudCommand(),
|
||||
new BcParseCommand(),
|
||||
new ParseCommand(),
|
||||
new ParseRelCommand(),
|
||||
new DisableEcloudCommand(),
|
||||
new EnableCloudCommand(),
|
||||
new HelpCommand(),
|
||||
new InfoCommand(),
|
||||
new ListCommand(),
|
||||
new RegisterCommand(),
|
||||
new ReloadCommand(),
|
||||
DEFAULT,
|
||||
new UnregisterCommand()
|
||||
);
|
||||
|
||||
static {
|
||||
COMMANDS.sort((command1, command2) -> {
|
||||
int comparison = Integer.compare(command1.getMatch().length(), command2.getMatch().length());
|
||||
final int comparison = Integer.compare(command1.getMatch().length(), command2.getMatch().length());
|
||||
|
||||
if (comparison == 1) return -1;
|
||||
if (comparison == -1) return 1;
|
||||
return 0;
|
||||
});
|
||||
Objects.requireNonNull(PlaceholderAPIPlugin.getInstance().getCommand("placeholderapi"))
|
||||
.setTabCompleter(new CompletionHandler(COMMANDS));
|
||||
}
|
||||
|
||||
private static String[] splitArguments(String joinedArguments, String command) {
|
||||
joinedArguments = StringUtils.remove(joinedArguments, command).trim();
|
||||
String[] args = StringUtils.split(joinedArguments);
|
||||
return args.length == 1 && args[0].isEmpty() ? new String[0] : args;
|
||||
}
|
||||
private static final Pattern SPACE_PATTERN = Pattern.compile(" ");
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull org.bukkit.command.Command bukkitCommand, @NotNull String name, String[] args) {
|
||||
public boolean onCommand(@NotNull final CommandSender sender, @NotNull final org.bukkit.command.Command bukkitCommand,
|
||||
@NotNull final String name, @NotNull String[] args) {
|
||||
if (args.length == 0) {
|
||||
DEFAULT.execute(sender, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
String joined = String.join(" ", args).toLowerCase();
|
||||
Optional<Command> optional = COMMANDS.stream()
|
||||
final String joined = String.join(" ", args).toLowerCase();
|
||||
final Optional<Command> optional = COMMANDS.stream()
|
||||
.filter(command -> joined.startsWith(command.getMatch()))
|
||||
.findFirst();
|
||||
|
||||
if (!optional.isPresent()) {
|
||||
Msg.msg(sender, "&cUnknown command.");
|
||||
sender.sendMessage("Specified command is not valid.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Command command = optional.get();
|
||||
String permission = command.getPermission();
|
||||
if (!sender.hasPermission(permission)) {
|
||||
Msg.msg(sender, "&cYou do not have the permission to use this command.");
|
||||
final Command command = optional.get();
|
||||
|
||||
if (!command.getPermissions().isEmpty() && command.getPermissions().stream().noneMatch(sender::hasPermission)) {
|
||||
sender.sendMessage("You do not have the permission to execute specified command.");
|
||||
return true;
|
||||
}
|
||||
|
||||
args = splitArguments(joined, command.getMatch());
|
||||
|
||||
if (args.length < command.getMinimumArguments()) {
|
||||
Msg.msg(sender, command.getUsage());
|
||||
return true;
|
||||
}
|
||||
|
||||
command.execute(sender, args);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static String[] splitArguments(@NotNull final String joinedArguments, @NotNull final String command) {
|
||||
final String[] args = SPACE_PATTERN.split(joinedArguments.replace(command, "").trim());
|
||||
return args.length == 1 && args[0].isEmpty() ? new String[]{} : args;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,37 +1,32 @@
|
||||
package me.clip.placeholderapi.commands;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.Optional;
|
||||
|
||||
public final class CompletionHandler implements TabCompleter {
|
||||
private static String[] splitArguments(String[] args, String command) {
|
||||
int skip = StringUtils.split(command).length;
|
||||
return Arrays.stream(args).skip(skip).toArray(String[]::new);
|
||||
private final List<Command> commands;
|
||||
|
||||
CompletionHandler(@NotNull final List<Command> commands) {
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
// it makes me physically cringe trying to understand why bukkit uses a list instead of a set for this
|
||||
// It's because of the list order. Even if they wanted to change that, they couldn't for the sake of backward compatibility. ~Crypto
|
||||
@NotNull
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, org.bukkit.command.@NotNull Command bukkitCommand, @NotNull String name, String[] args) {
|
||||
String joined = String.join(" ", args).toLowerCase(Locale.ENGLISH);
|
||||
public List<String> onTabComplete(@NotNull final CommandSender sender, @NotNull final org.bukkit.command.Command bukkitCommand,
|
||||
@NotNull final String name, @NotNull final String[] args) {
|
||||
final String joined = String.join(" ", args).toLowerCase();
|
||||
final Optional<Command> optional = commands.stream()
|
||||
.filter(command -> joined.startsWith(command.getMatch()))
|
||||
.findAny();
|
||||
|
||||
if (args.length > 1) {
|
||||
return CommandHandler.COMMANDS.stream()
|
||||
.filter(command -> sender.hasPermission(command.getPermission()) && joined.startsWith(command.getMatch()))
|
||||
.findFirst()
|
||||
.map(command -> command.handleCompletion(sender, splitArguments(args, command.getMatch())))
|
||||
.orElse(Collections.emptyList());
|
||||
}
|
||||
return CommandHandler.COMMANDS.stream()
|
||||
.filter(command -> sender.hasPermission(command.getPermission()) && (args[0].isEmpty() || command.getMatch().startsWith(joined)))
|
||||
.map(Command::getMatch).collect(Collectors.toList());
|
||||
return optional
|
||||
.map(command -> command.handleCompletion(sender, CommandHandler.splitArguments(joined, command.getMatch())))
|
||||
.orElse(Collections.emptyList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,34 +8,40 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class BcParseCommand extends Command {
|
||||
public BcParseCommand() {
|
||||
super("bcparse", options("&cYou must specify a player.", 1));
|
||||
super("bcparse", options("&cYou must specify a player.", 1, "placeholderapi.parse"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
OfflinePlayer player;
|
||||
String input = args[0];
|
||||
public void execute(@NotNull final CommandSender sender, @NotNull final String[] args) {
|
||||
final OfflinePlayer player;
|
||||
final String input = args[0];
|
||||
|
||||
if (input.equalsIgnoreCase("me")) {
|
||||
if (sender instanceof Player) {
|
||||
player = (Player) sender;
|
||||
} else {
|
||||
Msg.msg(sender, "&cThis command must target a player when used by console");
|
||||
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
player = Bukkit.getPlayer(input);
|
||||
if (player == null) player = Bukkit.getOfflinePlayer(input);
|
||||
if (player == null || !player.hasPlayedBefore()) {
|
||||
Msg.msg(sender, "&cCould not find player&8: &f" + input);
|
||||
return;
|
||||
if (Bukkit.getPlayer(input) != null) {
|
||||
player = Bukkit.getPlayer(input);
|
||||
} else {
|
||||
player = Bukkit.getOfflinePlayer(input);
|
||||
}
|
||||
}
|
||||
|
||||
String parse = StringUtils.join(args, " ", 2, args.length);
|
||||
if (player == null || !player.hasPlayedBefore()) {
|
||||
Msg.msg(sender, "&cFailed to find player: &f" + input);
|
||||
return;
|
||||
}
|
||||
|
||||
final String parse = StringUtils.join(args, " ", 2, args.length);
|
||||
Msg.broadcast("&r" + PlaceholderAPI.setPlaceholders(player, parse));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,29 @@
|
||||
package me.clip.placeholderapi.commands.command.ecloud;
|
||||
package me.clip.placeholderapi.commands.command;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.commands.Command;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class EcloudDisableCommand extends Command {
|
||||
public EcloudDisableCommand() {
|
||||
super("ecloud disable");
|
||||
public final class DisableEcloudCommand extends Command {
|
||||
public DisableEcloudCommand() {
|
||||
super("disablecloud", permissions("placeholderapi.ecloud"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
PlaceholderAPIPlugin plugin = PlaceholderAPIPlugin.getInstance();
|
||||
public void execute(@NotNull final CommandSender sender, @NotNull final String[] args) {
|
||||
final PlaceholderAPIPlugin plugin = PlaceholderAPIPlugin.getInstance();
|
||||
if (plugin.getExpansionCloud() == null) {
|
||||
Msg.msg(sender, "&7The cloud is already disabled!");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.disableCloud();
|
||||
plugin.getPlaceholderAPIConfig().setCloudEnabled(false);
|
||||
Msg.msg(sender, "&aThe cloud has been disabled!");
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import me.clip.placeholderapi.commands.Command;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.util.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -21,18 +22,16 @@ public final class EcloudCommand extends Command {
|
||||
"placeholders",
|
||||
"refresh",
|
||||
"status",
|
||||
"versioninfo",
|
||||
"enable",
|
||||
"disable"
|
||||
"versioninfo"
|
||||
);
|
||||
|
||||
public EcloudCommand() {
|
||||
super("ecloud");
|
||||
super("ecloud", permissions("placeholderapi.ecloud"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
PlaceholderAPIPlugin plugin = PlaceholderAPIPlugin.getInstance();
|
||||
public void execute(@NotNull final CommandSender sender, @NotNull final String[] args) {
|
||||
final PlaceholderAPIPlugin plugin = PlaceholderAPIPlugin.getInstance();
|
||||
|
||||
if (args.length == 0) {
|
||||
Msg.msg(sender, "&bExpansion cloud commands",
|
||||
@@ -58,6 +57,7 @@ public final class EcloudCommand extends Command {
|
||||
|
||||
if (plugin.getExpansionCloud() == null) {
|
||||
Msg.msg(sender, "&7The expansion cloud is not enabled!");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -69,9 +69,9 @@ public final class EcloudCommand extends Command {
|
||||
sender.sendMessage("Specified command is not valid.");
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<String> handleCompletion(CommandSender sender, String[] args) {
|
||||
public List<String> handleCompletion(@NotNull final CommandSender sender, @NotNull final String[] args) {
|
||||
if (args.length == MAXIMUM_ARGUMENTS) {
|
||||
return StringUtil.copyPartialMatches(args[0], COMPLETIONS, new ArrayList<>(COMPLETIONS.size()));
|
||||
}
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
package me.clip.placeholderapi.commands.command.ecloud;
|
||||
package me.clip.placeholderapi.commands.command;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.commands.Command;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class EcloudEnableCommand extends Command {
|
||||
public EcloudEnableCommand() {
|
||||
super("ecloud enable");
|
||||
public final class EnableCloudCommand extends Command {
|
||||
public EnableCloudCommand() {
|
||||
super("enablecloud", permissions("placeholderapi.ecloud"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
PlaceholderAPIPlugin plugin = PlaceholderAPIPlugin.getInstance();
|
||||
public void execute(@NotNull final CommandSender sender, @NotNull final String[] args) {
|
||||
final PlaceholderAPIPlugin plugin = PlaceholderAPIPlugin.getInstance();
|
||||
if (plugin.getExpansionCloud() != null) {
|
||||
Msg.msg(sender, "&7The cloud is already enabled!");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -4,14 +4,15 @@ import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.commands.Command;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class HelpCommand extends Command {
|
||||
public HelpCommand() {
|
||||
super("help");
|
||||
super("help", permissions("placeholderapi.ecloud"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
public void execute(@NotNull final CommandSender sender, @NotNull final String[] args) {
|
||||
Msg.msg(sender, "PlaceholderAPI &aHelp &e(&f" + PlaceholderAPIPlugin.getInstance().getDescription().getVersion() + "&e)",
|
||||
"&b/papi",
|
||||
"&fView plugin info/version info",
|
||||
|
||||
@@ -7,6 +7,7 @@ import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.util.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -16,13 +17,13 @@ public final class InfoCommand extends Command {
|
||||
private static final int MINIMUM_ARGUMENTS = 1;
|
||||
|
||||
public InfoCommand() {
|
||||
super("info", options("&cIncorrect usage! &7/papi info <expansion>", MINIMUM_ARGUMENTS));
|
||||
super("info", options("&cIncorrect usage! &7/papi info <expansion>", MINIMUM_ARGUMENTS, "placeholderapi.info"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
String requestedExpansion = args[0];
|
||||
PlaceholderExpansion ex = PlaceholderAPIPlugin.getInstance().getExpansionManager().getRegisteredExpansion(requestedExpansion);
|
||||
public void execute(@NotNull final CommandSender sender, @NotNull final String[] args) {
|
||||
final String requestedExpansion = args[0];
|
||||
final PlaceholderExpansion ex = PlaceholderAPIPlugin.getInstance().getExpansionManager().getRegisteredExpansion(requestedExpansion);
|
||||
if (ex == null) {
|
||||
Msg.msg(sender, "&cThere is no expansion loaded with the identifier: &f" + requestedExpansion);
|
||||
|
||||
@@ -53,11 +54,11 @@ public final class InfoCommand extends Command {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<String> handleCompletion(CommandSender sender, String[] args) {
|
||||
public List<String> handleCompletion(@NotNull final CommandSender sender, @NotNull final String[] args) {
|
||||
if (args.length == MINIMUM_ARGUMENTS) {
|
||||
Set<String> completions = PlaceholderAPI.getRegisteredIdentifiers();
|
||||
final Set<String> completions = PlaceholderAPI.getRegisteredIdentifiers();
|
||||
|
||||
return StringUtil.copyPartialMatches(args[0], completions, new ArrayList<>(completions.size()));
|
||||
}
|
||||
|
||||
@@ -4,18 +4,19 @@ import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import me.clip.placeholderapi.commands.Command;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class ListCommand extends Command {
|
||||
public ListCommand() {
|
||||
super("list");
|
||||
super("list", permissions("placeholderapi.list"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
Set<String> registered = PlaceholderAPI.getRegisteredIdentifiers();
|
||||
public void execute(@NotNull final CommandSender sender, @NotNull final String[] args) {
|
||||
final Set<String> registered = PlaceholderAPI.getRegisteredIdentifiers();
|
||||
if (registered.isEmpty()) {
|
||||
Msg.msg(sender, "&7There are no placeholder hooks currently registered!");
|
||||
return;
|
||||
|
||||
@@ -7,53 +7,41 @@ import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class ParseCommand extends Command {
|
||||
public ParseCommand() {
|
||||
super("parse", options("&cYou must specify a player.", 1));
|
||||
super("parse", options("&cYou must specify a player.", 1, "placeholderapi.parse"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
OfflinePlayer player;
|
||||
String input = args[0];
|
||||
public void execute(@NotNull final CommandSender sender, @NotNull final String[] args) {
|
||||
final OfflinePlayer player;
|
||||
final String input = args[0];
|
||||
|
||||
if (input.equalsIgnoreCase("me")) {
|
||||
if (sender instanceof Player) {
|
||||
player = (Player) sender;
|
||||
} else {
|
||||
Msg.msg(sender, "&cThis command must target a player when used by console");
|
||||
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
player = Bukkit.getPlayer(input);
|
||||
if (player == null) player = Bukkit.getOfflinePlayer(input);
|
||||
if (player == null || !player.hasPlayedBefore()) {
|
||||
Msg.msg(sender, "&cCould not find player&8: &f" + input);
|
||||
return;
|
||||
if (Bukkit.getPlayer(input) != null) {
|
||||
player = Bukkit.getPlayer(input);
|
||||
} else {
|
||||
player = Bukkit.getOfflinePlayer(input);
|
||||
}
|
||||
}
|
||||
|
||||
String parse = StringUtils.join(args, " ", 1, args.length);
|
||||
if (player == null || !player.hasPlayedBefore()) {
|
||||
Msg.msg(sender, "&cFailed to find player: &f" + input);
|
||||
return;
|
||||
}
|
||||
|
||||
final String parse = StringUtils.join(args, " ", 1, args.length);
|
||||
Msg.msg(sender, "&r" + PlaceholderAPI.setPlaceholders(player, parse));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> handleCompletion(CommandSender sender, String[] args) {
|
||||
if (args.length == 1) {
|
||||
List<String> players = Bukkit.getOnlinePlayers().stream().map(HumanEntity::getName).collect(Collectors.toList());
|
||||
players.add("me");
|
||||
if (args[0].isEmpty()) return players;
|
||||
else return players.stream().filter(name -> name.startsWith(args[0])).collect(Collectors.toList());
|
||||
}
|
||||
if (args.length == 2) return Collections.singletonList("<message>");
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,27 +7,30 @@ import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class ParseRelCommand extends Command {
|
||||
public ParseRelCommand() {
|
||||
super("parserel", options("&cYou must specify at least two players.", 2));
|
||||
super("parserel", options("&cYou must specify at least two players.", 2, "placeholderapi.parse"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
Player one = Bukkit.getPlayer(args[0]);
|
||||
public void execute(@NotNull final CommandSender sender, @NotNull final String[] args) {
|
||||
final Player one = Bukkit.getPlayer(args[0]);
|
||||
if (one == null) {
|
||||
Msg.msg(sender, args[0] + " &cis not online!");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Player two = Bukkit.getPlayer(args[1]);
|
||||
final Player two = Bukkit.getPlayer(args[1]);
|
||||
if (two == null) {
|
||||
Msg.msg(sender, args[1] + " &cis not online!");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
String parse = StringUtils.join(args, " ", 1, args.length);
|
||||
final String parse = StringUtils.join(args, " ", 1, args.length);
|
||||
Msg.msg(sender, "&r" + PlaceholderAPI.setRelationalPlaceholders(one, two, parse));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,21 +4,22 @@ import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.commands.Command;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class RegisterCommand extends Command {
|
||||
public RegisterCommand() {
|
||||
super("register", options("&cAn expansion file name must be specified!", 1));
|
||||
super("register", options("&cAn expansion file name must be specified!", 1,"placeholderapi.register"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
String fileName = StringUtils.remove(args[0], ".jar");
|
||||
PlaceholderExpansion expansion = PlaceholderAPIPlugin.getInstance().getExpansionManager().registerExpansion(fileName);
|
||||
public void execute(@NotNull final CommandSender sender, @NotNull final String[] args) {
|
||||
final String fileName = args[0].replace(".jar", "");
|
||||
final PlaceholderExpansion expansion = PlaceholderAPIPlugin.getInstance().getExpansionManager().registerExpansion(fileName);
|
||||
|
||||
if (expansion == null) {
|
||||
Msg.msg(sender, "&cFailed to register expansion from " + fileName);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,14 +4,15 @@ import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.commands.Command;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class ReloadCommand extends Command {
|
||||
public ReloadCommand() {
|
||||
super("reload");
|
||||
super("reload", permissions("placeholderapi.reload"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
public void execute(@NotNull final CommandSender sender, @NotNull final String[] args) {
|
||||
Msg.msg(sender, "&fPlaceholder&7API &bconfiguration reloaded!");
|
||||
PlaceholderAPIPlugin.getInstance().reloadConf(sender);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.util.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -16,17 +17,18 @@ public final class UnregisterCommand extends Command {
|
||||
private static final int MINIMUM_ARGUMENTS = 1;
|
||||
|
||||
public UnregisterCommand() {
|
||||
super("unregister", options("&cAn expansion name must be specified!", MINIMUM_ARGUMENTS));
|
||||
super("unregister", options("&cAn expansion name must be specified!", MINIMUM_ARGUMENTS, "placeholderapi.register"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
String requestedExpansion = args[0];
|
||||
PlaceholderExpansion expansion = PlaceholderAPIPlugin.getInstance().getExpansionManager()
|
||||
public void execute(@NotNull final CommandSender sender, @NotNull final String[] args) {
|
||||
final String requestedExpansion = args[0];
|
||||
final PlaceholderExpansion expansion = PlaceholderAPIPlugin.getInstance().getExpansionManager()
|
||||
.getRegisteredExpansion(requestedExpansion);
|
||||
|
||||
if (expansion == null) {
|
||||
Msg.msg(sender, "&cFailed to find expansion: &f" + requestedExpansion);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -37,11 +39,12 @@ public final class UnregisterCommand extends Command {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<String> handleCompletion(CommandSender sender, String[] args) {
|
||||
public List<String> handleCompletion(@NotNull final CommandSender sender, @NotNull final String[] args) {
|
||||
if (args.length == MINIMUM_ARGUMENTS) {
|
||||
Set<String> completions = PlaceholderAPI.getRegisteredIdentifiers();
|
||||
final Set<String> completions = PlaceholderAPI.getRegisteredIdentifiers();
|
||||
|
||||
return StringUtil.copyPartialMatches(args[0], completions, new ArrayList<>(completions.size()));
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import me.clip.placeholderapi.util.Msg;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.util.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -33,8 +34,8 @@ public final class VersionCommand extends Command {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
PluginDescriptionFile description = PlaceholderAPIPlugin.getInstance().getDescription();
|
||||
public void execute(@NotNull final CommandSender sender, @NotNull final String[] args) {
|
||||
final PluginDescriptionFile description = PlaceholderAPIPlugin.getInstance().getDescription();
|
||||
|
||||
Msg.msg(sender, "PlaceholderAPI &7version &b&o" + description.getVersion(),
|
||||
"&fCreated by&7: &b" + description.getAuthors(),
|
||||
@@ -42,9 +43,9 @@ public final class VersionCommand extends Command {
|
||||
"&fEcloud commands: &b/papi ecloud");
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<String> handleCompletion(CommandSender sender, String[] args) {
|
||||
public List<String> handleCompletion(@NotNull final CommandSender sender, @NotNull final String[] args) {
|
||||
if (args.length == 1) {
|
||||
return StringUtil.copyPartialMatches(args[0], COMPLETIONS, new ArrayList<>(COMPLETIONS.size()));
|
||||
}
|
||||
|
||||
@@ -4,14 +4,15 @@ import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.commands.Command;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class EcloudClearCommand extends Command {
|
||||
public EcloudClearCommand() {
|
||||
super("ecloud clear");
|
||||
super("ecloud clear", permissions("placeholderapi.ecloud"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
public void execute(@NotNull final CommandSender sender, @NotNull final String[] args) {
|
||||
PlaceholderAPIPlugin.getInstance().getExpansionCloud().clean();
|
||||
Msg.msg(sender, "&aThe cache has been cleared!!");
|
||||
}
|
||||
|
||||
@@ -9,24 +9,25 @@ import me.clip.placeholderapi.expansion.cloud.ExpansionCloudManager;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class EcloudDownloadCommand extends Command {
|
||||
public EcloudDownloadCommand() {
|
||||
super("ecloud download", options("&cAn expansion name must be specified!", 1));
|
||||
super("ecloud download", options("&cAn expansion name must be specified!", 1, "placeholderapi.ecloud"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
PlaceholderAPIPlugin plugin = PlaceholderAPIPlugin.getInstance();
|
||||
String input = args[0];
|
||||
CloudExpansion expansion = plugin.getExpansionCloud().getCloudExpansion(input);
|
||||
public void execute(@NotNull final CommandSender sender, @NotNull final String[] args) {
|
||||
final PlaceholderAPIPlugin plugin = PlaceholderAPIPlugin.getInstance();
|
||||
final String input = args[0];
|
||||
final CloudExpansion expansion = plugin.getExpansionCloud().getCloudExpansion(input);
|
||||
|
||||
if (expansion == null) {
|
||||
Msg.msg(sender, "&cNo expansion found with the name: &f" + input);
|
||||
return;
|
||||
}
|
||||
|
||||
PlaceholderExpansion loaded = plugin.getExpansionManager().getRegisteredExpansion(input);
|
||||
final PlaceholderExpansion loaded = plugin.getExpansionManager().getRegisteredExpansion(input);
|
||||
if (loaded != null && loaded.isRegistered()) {
|
||||
PlaceholderAPI.unregisterPlaceholderHook(loaded.getIdentifier());
|
||||
}
|
||||
@@ -45,23 +46,10 @@ public final class EcloudDownloadCommand extends Command {
|
||||
}
|
||||
|
||||
Msg.msg(sender, "&aDownload starting for expansion: &f" + expansion.getName() + " &aversion: &f" + version);
|
||||
String player = ((sender instanceof Player) ? sender.getName() : null);
|
||||
ExpansionCloudManager cloud = plugin.getExpansionCloud();
|
||||
final String player = ((sender instanceof Player) ? sender.getName() : null);
|
||||
final ExpansionCloudManager cloud = plugin.getExpansionCloud();
|
||||
cloud.downloadExpansion(player, expansion, version);
|
||||
cloud.clean();
|
||||
cloud.fetch(plugin.getPlaceholderAPIConfig().cloudAllowUnverifiedExpansions());
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public List<String> handleCompletion(CommandSender sender, String[] args) {
|
||||
// List<String> downloads = new ArrayList<>();
|
||||
// if (!PlaceholderAPI.isRegistered("player")) downloads.add("player");
|
||||
//
|
||||
// for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
|
||||
// String identifier = plugin.getName();
|
||||
// if (!PlaceholderAPI.isRegistered(identifier)) downloads.add(identifier);
|
||||
// }
|
||||
//
|
||||
// return downloads;
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -7,18 +7,19 @@ import me.clip.placeholderapi.util.Msg;
|
||||
import me.rayzr522.jsonmessage.JSONMessage;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static me.clip.placeholderapi.util.Msg.color;
|
||||
|
||||
public final class EcloudInfoCommand extends Command {
|
||||
public EcloudInfoCommand() {
|
||||
super("ecloud info", options("&cAn expansion name must be specified!", 1));
|
||||
super("ecloud info", options("&cAn expansion name must be specified!", 1, "placeholderapi.ecloud"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
String input = args[0];
|
||||
CloudExpansion expansion = PlaceholderAPIPlugin.getInstance().getExpansionCloud().getCloudExpansion(input);
|
||||
public void execute(@NotNull final CommandSender sender, @NotNull final String[] args) {
|
||||
final String input = args[0];
|
||||
final CloudExpansion expansion = PlaceholderAPIPlugin.getInstance().getExpansionCloud().getCloudExpansion(input);
|
||||
|
||||
if (expansion == null) {
|
||||
Msg.msg(sender, "&cNo expansion found by the name: &f" + input);
|
||||
@@ -34,7 +35,7 @@ public final class EcloudInfoCommand extends Command {
|
||||
return;
|
||||
}
|
||||
|
||||
Player p = (Player) sender;
|
||||
final Player p = (Player) sender;
|
||||
|
||||
Msg.msg(sender, "&bExpansion&7: &f" + expansion.getName(),
|
||||
"&bAuthor: &f" + expansion.getAuthor(),
|
||||
@@ -42,7 +43,7 @@ public final class EcloudInfoCommand extends Command {
|
||||
);
|
||||
|
||||
// latest version
|
||||
JSONMessage latestVersion = JSONMessage
|
||||
final JSONMessage latestVersion = JSONMessage
|
||||
.create(color("&bLatest version: &f" + expansion.getLatestVersion()));
|
||||
latestVersion.tooltip(color("&bReleased: &f" + expansion.getTimeSinceLastUpdate()
|
||||
+ "\n&bUpdate information: &f" + expansion.getVersion().getReleaseNotes()
|
||||
@@ -50,7 +51,7 @@ public final class EcloudInfoCommand extends Command {
|
||||
latestVersion.send(p);
|
||||
|
||||
// versions
|
||||
JSONMessage versions = JSONMessage
|
||||
final JSONMessage versions = JSONMessage
|
||||
.create(color("&bVersions available: &f" + expansion.getVersions().size()));
|
||||
versions.tooltip(color(String.join("&b, &f", expansion.getAvailableVersions())));
|
||||
versions.suggestCommand(
|
||||
@@ -59,7 +60,7 @@ public final class EcloudInfoCommand extends Command {
|
||||
|
||||
// placeholders
|
||||
if (expansion.getPlaceholders() != null) {
|
||||
JSONMessage placeholders = JSONMessage
|
||||
final JSONMessage placeholders = JSONMessage
|
||||
.create(color("&bPlaceholders: &f" + expansion.getPlaceholders().size()));
|
||||
placeholders.tooltip(color(String.join("&b, &f", expansion.getPlaceholders())));
|
||||
placeholders.suggestCommand("/papi ecloud placeholders " + expansion.getName());
|
||||
|
||||
@@ -9,6 +9,7 @@ import me.rayzr522.jsonmessage.JSONMessage;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -24,12 +25,13 @@ public final class EcloudListCommand extends Command {
|
||||
);
|
||||
|
||||
public EcloudListCommand() {
|
||||
super("ecloud list", options("&cIncorrect usage! &7/papi ecloud list <all/author/installed> (page)", MINIMUM_ARGUMENTS));
|
||||
super("ecloud list", options("&cIncorrect usage! &7/papi ecloud list <all/author/installed> (page)",
|
||||
MINIMUM_ARGUMENTS, "placeholderapi.ecloud"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
PlaceholderAPIPlugin plugin = PlaceholderAPIPlugin.getInstance();
|
||||
public void execute(@NotNull final CommandSender sender, @NotNull final String[] args) {
|
||||
final PlaceholderAPIPlugin plugin = PlaceholderAPIPlugin.getInstance();
|
||||
int page = 1;
|
||||
|
||||
String author;
|
||||
@@ -101,7 +103,7 @@ public final class EcloudListCommand extends Command {
|
||||
Msg.msg(sender, "&6Gold = Expansions which need updated");
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
Map<String, CloudExpansion> expansions = new HashMap<>();
|
||||
final Map<String, CloudExpansion> expansions = new HashMap<>();
|
||||
|
||||
for (CloudExpansion exp : ex.values()) {
|
||||
if (exp == null || exp.getName() == null) {
|
||||
@@ -111,7 +113,7 @@ public final class EcloudListCommand extends Command {
|
||||
expansions.put(exp.getName(), exp);
|
||||
}
|
||||
|
||||
List<String> ce = expansions.keySet().stream().sorted().collect(Collectors.toList());
|
||||
final List<String> ce = expansions.keySet().stream().sorted().collect(Collectors.toList());
|
||||
|
||||
int i = (int) ex.keySet().toArray()[0];
|
||||
|
||||
@@ -120,7 +122,7 @@ public final class EcloudListCommand extends Command {
|
||||
continue;
|
||||
}
|
||||
|
||||
CloudExpansion expansion = expansions.get(name);
|
||||
final CloudExpansion expansion = expansions.get(name);
|
||||
|
||||
Msg.msg(sender,
|
||||
"&b" + i + "&7: " + (expansion.shouldUpdate() ? "&6"
|
||||
@@ -132,11 +134,11 @@ public final class EcloudListCommand extends Command {
|
||||
return;
|
||||
}
|
||||
|
||||
Player p = (Player) sender;
|
||||
final Player p = (Player) sender;
|
||||
|
||||
Map<String, CloudExpansion> expansions = new HashMap<>();
|
||||
final Map<String, CloudExpansion> expansions = new HashMap<>();
|
||||
|
||||
for (CloudExpansion exp : ex.values()) {
|
||||
for (final CloudExpansion exp : ex.values()) {
|
||||
if (exp == null || exp.getName() == null) {
|
||||
continue;
|
||||
}
|
||||
@@ -144,7 +146,7 @@ public final class EcloudListCommand extends Command {
|
||||
expansions.put(exp.getName(), exp);
|
||||
}
|
||||
|
||||
List<String> ce = expansions.keySet().stream().sorted().collect(Collectors.toList());
|
||||
final List<String> ce = expansions.keySet().stream().sorted().collect(Collectors.toList());
|
||||
|
||||
int i = page > 1 ? page * 10 : 0;
|
||||
|
||||
@@ -153,8 +155,8 @@ public final class EcloudListCommand extends Command {
|
||||
continue;
|
||||
}
|
||||
|
||||
CloudExpansion expansion = expansions.get(name);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
final CloudExpansion expansion = expansions.get(name);
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
|
||||
if (expansion.shouldUpdate()) {
|
||||
sb.append("&6Click to update to the latest version of this expansion\n\n");
|
||||
@@ -170,13 +172,13 @@ public final class EcloudListCommand extends Command {
|
||||
sb.append("&bLast updated&7: &f").append(expansion.getTimeSinceLastUpdate()).append(" ago\n");
|
||||
sb.append("\n").append(expansion.getDescription());
|
||||
|
||||
String msg = color(
|
||||
final String msg = color(
|
||||
"&b" + (i + 1) + "&7: " + (expansion.shouldUpdate() ? "&6"
|
||||
: (expansion.hasExpansion() ? "&a" : "")) + expansion.getName());
|
||||
|
||||
String hover = color(sb.toString());
|
||||
final String hover = color(sb.toString());
|
||||
|
||||
JSONMessage line = JSONMessage.create(msg);
|
||||
final JSONMessage line = JSONMessage.create(msg);
|
||||
line.tooltip(hover);
|
||||
|
||||
if (expansion.shouldUpdate() || !expansion.hasExpansion()) {
|
||||
@@ -190,9 +192,9 @@ public final class EcloudListCommand extends Command {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<String> handleCompletion(CommandSender sender, String[] args) {
|
||||
public List<String> handleCompletion(@NotNull final CommandSender sender, @NotNull final String[] args) {
|
||||
if (args.length == MINIMUM_ARGUMENTS) {
|
||||
return StringUtil.copyPartialMatches(args[0], COMPLETIONS, new ArrayList<>(COMPLETIONS.size()));
|
||||
}
|
||||
|
||||
@@ -8,26 +8,27 @@ import me.clip.placeholderapi.util.Msg;
|
||||
import me.rayzr522.jsonmessage.JSONMessage;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class EcloudPlaceholdersCommand extends Command {
|
||||
public EcloudPlaceholdersCommand() {
|
||||
super("ecloud placeholders", options("&cAn expansion name must be specified!", 1));
|
||||
super("ecloud placeholders", options("&cAn expansion name must be specified!", 1, "placeholderapi.ecloud"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
PlaceholderAPIPlugin plugin = PlaceholderAPIPlugin.getInstance();
|
||||
String input = args[0];
|
||||
CloudExpansion expansion = plugin.getExpansionCloud().getCloudExpansion(input);
|
||||
public void execute(@NotNull final CommandSender sender, @NotNull final String[] args) {
|
||||
final PlaceholderAPIPlugin plugin = PlaceholderAPIPlugin.getInstance();
|
||||
final String input = args[0];
|
||||
final CloudExpansion expansion = plugin.getExpansionCloud().getCloudExpansion(input);
|
||||
if (expansion == null) {
|
||||
Msg.msg(sender, "&cNo expansion found by the name: &f" + input);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> placeholders = expansion.getPlaceholders();
|
||||
final List<String> placeholders = expansion.getPlaceholders();
|
||||
if (placeholders == null) {
|
||||
Msg.msg(sender, "&cThe expansion: &f" + expansion.getName()
|
||||
+ " &cdoes not have any placeholders listed.",
|
||||
@@ -44,15 +45,15 @@ public final class EcloudPlaceholdersCommand extends Command {
|
||||
return;
|
||||
}
|
||||
|
||||
Player p = (Player) sender;
|
||||
JSONMessage message = JSONMessage.create(Msg.color("&bPlaceholders: &f" + placeholders.size()));
|
||||
final Player p = (Player) sender;
|
||||
final JSONMessage message = JSONMessage.create(Msg.color("&bPlaceholders: &f" + placeholders.size()));
|
||||
message.then("\n");
|
||||
|
||||
for (int i = 0; i < placeholders.size(); i++) {
|
||||
message.then(i == placeholders.size() - 1 ? placeholders.get(i) : Msg.color(placeholders.get(i) + "&b, &f"));
|
||||
try {
|
||||
message.tooltip(PlaceholderAPI.setPlaceholders(p, placeholders.get(i)));
|
||||
} catch (Exception ignored) {
|
||||
} catch (final Exception ignored) {
|
||||
// Ignored exception
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,16 +5,17 @@ import me.clip.placeholderapi.commands.Command;
|
||||
import me.clip.placeholderapi.expansion.cloud.ExpansionCloudManager;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class EcloudRefreshCommand extends Command {
|
||||
public EcloudRefreshCommand() {
|
||||
super("ecloud refresh");
|
||||
super("ecloud refresh", permissions("placeholderapi.ecloud"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
PlaceholderAPIPlugin plugin = PlaceholderAPIPlugin.getInstance();
|
||||
ExpansionCloudManager cloud = plugin.getExpansionCloud();
|
||||
public void execute(@NotNull final CommandSender sender, @NotNull final String[] args) {
|
||||
final PlaceholderAPIPlugin plugin = PlaceholderAPIPlugin.getInstance();
|
||||
final ExpansionCloudManager cloud = plugin.getExpansionCloud();
|
||||
Msg.msg(sender, "&aRefresh task started. Use &f/papi ecloud list all &ain a few!!");
|
||||
cloud.clean();
|
||||
cloud.fetch(plugin.getPlaceholderAPIConfig().cloudAllowUnverifiedExpansions());
|
||||
|
||||
@@ -4,15 +4,16 @@ import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.commands.Command;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class EcloudStatusCommand extends Command {
|
||||
public EcloudStatusCommand() {
|
||||
super("ecloud status");
|
||||
super("ecloud status", permissions("placeholderapi.ecloud"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
PlaceholderAPIPlugin plugin = PlaceholderAPIPlugin.getInstance();
|
||||
public void execute(@NotNull final CommandSender sender, @NotNull final String[] args) {
|
||||
final PlaceholderAPIPlugin plugin = PlaceholderAPIPlugin.getInstance();
|
||||
Msg.msg(sender, "&bThere are &f" + plugin.getExpansionCloud().getCloudExpansions().size()
|
||||
+ " &bexpansions available on the cloud.",
|
||||
"&7A total of &f" + plugin.getExpansionCloud().getCloudAuthorCount()
|
||||
|
||||
@@ -7,22 +7,24 @@ import me.clip.placeholderapi.util.Msg;
|
||||
import me.rayzr522.jsonmessage.JSONMessage;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class EcloudVersionInfoCommand extends Command {
|
||||
public EcloudVersionInfoCommand() {
|
||||
super("ecloud versioninfo", options("&cIncorrect usage! &7/papi ecloud versioninfo <name> <version>", 2));
|
||||
super("ecloud versioninfo", options("&cIncorrect usage! &7/papi ecloud versioninfo <name> <version>",
|
||||
2, "placeholderapi.ecloud"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
String input = args[0];
|
||||
CloudExpansion expansion = PlaceholderAPIPlugin.getInstance().getExpansionCloud().getCloudExpansion(input);
|
||||
public void execute(@NotNull final CommandSender sender, @NotNull final String[] args) {
|
||||
final String input = args[0];
|
||||
final CloudExpansion expansion = PlaceholderAPIPlugin.getInstance().getExpansionCloud().getCloudExpansion(input);
|
||||
if (expansion == null) {
|
||||
Msg.msg(sender, "&cNo expansion found by the name: &f" + input);
|
||||
return;
|
||||
}
|
||||
|
||||
CloudExpansion.Version version = expansion.getVersion(args[1]);
|
||||
final CloudExpansion.Version version = expansion.getVersion(args[1]);
|
||||
if (version == null) {
|
||||
Msg.msg(sender, "&cThe version specified does not exist for expansion: &f" + expansion.getName());
|
||||
return;
|
||||
@@ -37,10 +39,10 @@ public final class EcloudVersionInfoCommand extends Command {
|
||||
return;
|
||||
}
|
||||
|
||||
Player p = (Player) sender;
|
||||
JSONMessage download = JSONMessage.create(Msg.color("&7Click to download this version"));
|
||||
final Player p = (Player) sender;
|
||||
final JSONMessage download = JSONMessage.create(Msg.color("&7Click to download this version"));
|
||||
download.suggestCommand(
|
||||
"/papi ecloud download " + expansion.getName() + ' ' + version.getVersion());
|
||||
"/papi ecloud download " + expansion.getName() + " " + version.getVersion());
|
||||
download.send(p);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user