From b7d1c6969ecc57f162f1e5fdd93a4473919ef633 Mon Sep 17 00:00:00 2001 From: Sxtanna Date: Fri, 24 Jul 2020 01:29:11 -0400 Subject: [PATCH] Commands rewrite (#357) * began rewriting command system * began rewriting command system * updated formatting * added new info command * added new reload command * updated new parse command to support all three parsing types * added new commands to command router * deleted old unused commands * removed parserel * added new expansion register and unregister commands * deleted unused commands * fixed annotation order * added labels helper to command * updated alias method to return an immutable view * updated params param with unmodifiable annotation * updated router to build an immutable map of the commands * began rewriting command system * updated formatting * added new info command * added new reload command * updated new parse command to support all three parsing types * added new commands to command router * deleted old unused commands * removed parserel * added new expansion register and unregister commands * deleted unused commands * fixed annotation order * added labels helper to command * updated alias method to return an immutable view * updated params param with unmodifiable annotation * updated router to build an immutable map of the commands * updated plugin class to use new command router * updated switch to break on parse match * updated register completions to suggest file names * updated router to allow entering labels in any case * updated parse command to send message to players as components * added command dispatching parsing * moved new commands into local package * added helper functions for filtering and suggesting * updated imports, updated tab completion to use helper functions * added start of ecloud commands * replace ecloud enable and disable commands with single toggle command evaluator * deleted unused commands * updated commands to use helper functions for suggesting * updated downloading to use completablefuture, updated all methods to use streams exclusively * updated to use the config instead of a null check * deleted old commands system * finished new command system * updated to use new method from cloud manager * fixed annotation ordering and added missing annotations * updated ecloud subcommands to have a more specific permission * updated plugin.yml with the new permissions, (and also fixed its formatting) * fixed annotations intellij missed * this should probably be there... --- .../placeholderapi/PlaceholderAPIPlugin.java | 7 +- .../clip/placeholderapi/commands/Command.java | 82 --- .../commands/CommandHandler.java | 101 ---- .../commands/CompletionHandler.java | 32 -- .../commands/PlaceholderCommand.java | 98 ++++ .../commands/PlaceholderCommandRouter.java | 126 ++++ .../commands/command/BcParseCommand.java | 47 -- .../command/DisableEcloudCommand.java | 29 - .../commands/command/EcloudCommand.java | 81 --- .../commands/command/EnableCloudCommand.java | 27 - .../commands/command/HelpCommand.java | 46 -- .../commands/command/InfoCommand.java | 68 --- .../commands/command/ListCommand.java | 28 - .../commands/command/ParseCommand.java | 47 -- .../commands/command/ParseRelCommand.java | 36 -- .../commands/command/RegisterCommand.java | 28 - .../commands/command/ReloadCommand.java | 19 - .../commands/command/UnregisterCommand.java | 53 -- .../commands/command/VersionCommand.java | 55 -- .../command/ecloud/EcloudClearCommand.java | 19 - .../command/ecloud/EcloudDownloadCommand.java | 55 -- .../command/ecloud/EcloudInfoCommand.java | 70 --- .../command/ecloud/EcloudListCommand.java | 208 ------- .../ecloud/EcloudPlaceholdersCommand.java | 63 -- .../command/ecloud/EcloudRefreshCommand.java | 23 - .../command/ecloud/EcloudStatusCommand.java | 26 - .../ecloud/EcloudVersionInfoCommand.java | 48 -- .../commands/impl/cloud/CommandECloud.java | 129 +++++ .../impl/cloud/CommandECloudClear.java | 28 + .../impl/cloud/CommandECloudDownload.java | 104 ++++ .../cloud/CommandECloudExpansionInfo.java | 116 ++++ .../cloud/CommandECloudExpansionList.java | 174 ++++++ .../CommandECloudExpansionPlaceholders.java | 70 +++ .../impl/cloud/CommandECloudRefresh.java | 30 + .../impl/cloud/CommandECloudStatus.java | 43 ++ .../impl/cloud/CommandECloudToggle.java | 62 ++ .../impl/local/CommandExpansionRegister.java | 61 ++ .../local/CommandExpansionUnregister.java | 59 ++ .../commands/impl/local/CommandHelp.java | 50 ++ .../commands/impl/local/CommandInfo.java | 100 ++++ .../commands/impl/local/CommandList.java | 42 ++ .../commands/impl/local/CommandParse.java | 185 ++++++ .../commands/impl/local/CommandReload.java | 27 + .../commands/impl/local/CommandVersion.java | 34 ++ .../expansion/ExpansionManager.java | 10 +- .../cloud/ExpansionCloudManager.java | 537 ++++++++---------- .../listeners/PlaceholderListener.java | 7 +- .../clip/placeholderapi/util/Constants.java | 9 - src/main/resources/plugin.yml | 138 +++-- 49 files changed, 1899 insertions(+), 1638 deletions(-) delete mode 100644 src/main/java/me/clip/placeholderapi/commands/Command.java delete mode 100644 src/main/java/me/clip/placeholderapi/commands/CommandHandler.java delete mode 100644 src/main/java/me/clip/placeholderapi/commands/CompletionHandler.java create mode 100644 src/main/java/me/clip/placeholderapi/commands/PlaceholderCommand.java create mode 100644 src/main/java/me/clip/placeholderapi/commands/PlaceholderCommandRouter.java delete mode 100644 src/main/java/me/clip/placeholderapi/commands/command/BcParseCommand.java delete mode 100644 src/main/java/me/clip/placeholderapi/commands/command/DisableEcloudCommand.java delete mode 100644 src/main/java/me/clip/placeholderapi/commands/command/EcloudCommand.java delete mode 100644 src/main/java/me/clip/placeholderapi/commands/command/EnableCloudCommand.java delete mode 100644 src/main/java/me/clip/placeholderapi/commands/command/HelpCommand.java delete mode 100644 src/main/java/me/clip/placeholderapi/commands/command/InfoCommand.java delete mode 100644 src/main/java/me/clip/placeholderapi/commands/command/ListCommand.java delete mode 100644 src/main/java/me/clip/placeholderapi/commands/command/ParseCommand.java delete mode 100644 src/main/java/me/clip/placeholderapi/commands/command/ParseRelCommand.java delete mode 100644 src/main/java/me/clip/placeholderapi/commands/command/RegisterCommand.java delete mode 100644 src/main/java/me/clip/placeholderapi/commands/command/ReloadCommand.java delete mode 100644 src/main/java/me/clip/placeholderapi/commands/command/UnregisterCommand.java delete mode 100644 src/main/java/me/clip/placeholderapi/commands/command/VersionCommand.java delete mode 100644 src/main/java/me/clip/placeholderapi/commands/command/ecloud/EcloudClearCommand.java delete mode 100644 src/main/java/me/clip/placeholderapi/commands/command/ecloud/EcloudDownloadCommand.java delete mode 100644 src/main/java/me/clip/placeholderapi/commands/command/ecloud/EcloudInfoCommand.java delete mode 100644 src/main/java/me/clip/placeholderapi/commands/command/ecloud/EcloudListCommand.java delete mode 100644 src/main/java/me/clip/placeholderapi/commands/command/ecloud/EcloudPlaceholdersCommand.java delete mode 100644 src/main/java/me/clip/placeholderapi/commands/command/ecloud/EcloudRefreshCommand.java delete mode 100644 src/main/java/me/clip/placeholderapi/commands/command/ecloud/EcloudStatusCommand.java delete mode 100644 src/main/java/me/clip/placeholderapi/commands/command/ecloud/EcloudVersionInfoCommand.java create mode 100644 src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloud.java create mode 100644 src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudClear.java create mode 100644 src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudDownload.java create mode 100644 src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudExpansionInfo.java create mode 100644 src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudExpansionList.java create mode 100644 src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudExpansionPlaceholders.java create mode 100644 src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudRefresh.java create mode 100644 src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudStatus.java create mode 100644 src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudToggle.java create mode 100644 src/main/java/me/clip/placeholderapi/commands/impl/local/CommandExpansionRegister.java create mode 100644 src/main/java/me/clip/placeholderapi/commands/impl/local/CommandExpansionUnregister.java create mode 100644 src/main/java/me/clip/placeholderapi/commands/impl/local/CommandHelp.java create mode 100644 src/main/java/me/clip/placeholderapi/commands/impl/local/CommandInfo.java create mode 100644 src/main/java/me/clip/placeholderapi/commands/impl/local/CommandList.java create mode 100644 src/main/java/me/clip/placeholderapi/commands/impl/local/CommandParse.java create mode 100644 src/main/java/me/clip/placeholderapi/commands/impl/local/CommandReload.java create mode 100644 src/main/java/me/clip/placeholderapi/commands/impl/local/CommandVersion.java delete mode 100644 src/main/java/me/clip/placeholderapi/util/Constants.java diff --git a/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java b/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java index 44e5be1..db2e2ed 100644 --- a/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java +++ b/src/main/java/me/clip/placeholderapi/PlaceholderAPIPlugin.java @@ -20,7 +20,7 @@ */ package me.clip.placeholderapi; -import me.clip.placeholderapi.commands.CommandHandler; +import me.clip.placeholderapi.commands.PlaceholderCommandRouter; import me.clip.placeholderapi.configuration.PlaceholderAPIConfig; import me.clip.placeholderapi.expansion.ExpansionManager; import me.clip.placeholderapi.expansion.PlaceholderExpansion; @@ -177,8 +177,9 @@ public final class PlaceholderAPIPlugin extends JavaPlugin return; } - final CommandHandler evaluator = new CommandHandler(); - pluginCommand.setExecutor(evaluator); + final PlaceholderCommandRouter router = new PlaceholderCommandRouter(this); + pluginCommand.setExecutor(router); + pluginCommand.setTabCompleter(router); } private void setupMetrics() diff --git a/src/main/java/me/clip/placeholderapi/commands/Command.java b/src/main/java/me/clip/placeholderapi/commands/Command.java deleted file mode 100644 index 531c8be..0000000 --- a/src/main/java/me/clip/placeholderapi/commands/Command.java +++ /dev/null @@ -1,82 +0,0 @@ -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, null); - - private final String match; - private final String usage; - private final int minimumArguments; - private final Set permissions; - - protected Command(@NotNull final String match) { - this(match, EMPTY_OPTIONS); - } - - protected Command(@NotNull final String match, @NotNull final Options options) { - this.match = match; - this.usage = options.usage == null ? "/papi " + match + " [optional args]" : options.usage; - this.permissions = options.permissions == null ? Collections.emptySet() : ImmutableSet.copyOf(options.permissions); - this.minimumArguments = options.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; - } - - public int getMinimumArguments() { - return minimumArguments; - } - - @NotNull - public Set getPermissions() { - return permissions; - } - - public abstract void execute(@NotNull final CommandSender sender, @NotNull final String[] args); - - @NotNull - public List 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(@Nullable final String usage, final int minimumArguments, - @Nullable final String[] permissions) { - this.usage = usage; - this.minimumArguments = minimumArguments; - this.permissions = permissions; - } - } -} diff --git a/src/main/java/me/clip/placeholderapi/commands/CommandHandler.java b/src/main/java/me/clip/placeholderapi/commands/CommandHandler.java deleted file mode 100644 index 12374cd..0000000 --- a/src/main/java/me/clip/placeholderapi/commands/CommandHandler.java +++ /dev/null @@ -1,101 +0,0 @@ -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.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(); - - private static final List COMMANDS = Lists.newArrayList( - new EcloudClearCommand(), - new EcloudDownloadCommand(), - new EcloudInfoCommand(), - new EcloudListCommand(), - new EcloudPlaceholdersCommand(), - new EcloudRefreshCommand(), - new EcloudStatusCommand(), - new EcloudVersionInfoCommand(), - 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) -> { - 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 final Pattern SPACE_PATTERN = Pattern.compile(" "); - - @Override - 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; - } - - final String joined = String.join(" ", args).toLowerCase(); - final Optional optional = COMMANDS.stream() - .filter(command -> joined.startsWith(command.getMatch())) - .findFirst(); - - if (!optional.isPresent()) { - sender.sendMessage("Specified command is not valid."); - return true; - } - - 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; - } -} diff --git a/src/main/java/me/clip/placeholderapi/commands/CompletionHandler.java b/src/main/java/me/clip/placeholderapi/commands/CompletionHandler.java deleted file mode 100644 index a48173f..0000000 --- a/src/main/java/me/clip/placeholderapi/commands/CompletionHandler.java +++ /dev/null @@ -1,32 +0,0 @@ -package me.clip.placeholderapi.commands; - -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabCompleter; -import org.jetbrains.annotations.NotNull; - -import java.util.Collections; -import java.util.List; -import java.util.Optional; - -public final class CompletionHandler implements TabCompleter { - private final List commands; - - CompletionHandler(@NotNull final List commands) { - this.commands = commands; - } - - // it makes me physically cringe trying to understand why bukkit uses a list instead of a set for this - @NotNull - @Override - public List 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 optional = commands.stream() - .filter(command -> joined.startsWith(command.getMatch())) - .findAny(); - - return optional - .map(command -> command.handleCompletion(sender, CommandHandler.splitArguments(joined, command.getMatch()))) - .orElse(Collections.emptyList()); - } -} diff --git a/src/main/java/me/clip/placeholderapi/commands/PlaceholderCommand.java b/src/main/java/me/clip/placeholderapi/commands/PlaceholderCommand.java new file mode 100644 index 0000000..96e2cb3 --- /dev/null +++ b/src/main/java/me/clip/placeholderapi/commands/PlaceholderCommand.java @@ -0,0 +1,98 @@ +package me.clip.placeholderapi.commands; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; +import me.clip.placeholderapi.PlaceholderAPIPlugin; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Unmodifiable; + +import java.util.List; +import java.util.Set; +import java.util.stream.Stream; + +public abstract class PlaceholderCommand +{ + + @NotNull + private final String label; + @NotNull + private final Set alias; + + @Nullable + private String permission; + + + protected PlaceholderCommand(@NotNull final String label, @NotNull final String... alias) + { + this.label = label; + this.alias = Sets.newHashSet(alias); + + setPermission("placeholderapi." + label); + } + + + @NotNull + public final String getLabel() + { + return label; + } + + @NotNull + @Unmodifiable + public final Set getAlias() + { + return ImmutableSet.copyOf(alias); + } + + @NotNull + @Unmodifiable + public final Set getLabels() + { + return ImmutableSet.builder().add(label).addAll(alias).build(); + } + + + @Nullable + public final String getPermission() + { + return permission; + } + + public void setPermission(@NotNull final String permission) + { + this.permission = permission; + } + + + public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params) + { + + } + + public void complete(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params, @NotNull final List suggestions) + { + + } + + + @NotNull + public static Stream filterByPermission(@NotNull final CommandSender sender, @NotNull final Stream commands) + { + return commands.filter(target -> target.getPermission() == null || sender.hasPermission(target.getPermission())); + } + + public static void suggestByParameter(@NotNull final Stream possible, @NotNull final List suggestions, @Nullable final String parameter) + { + if (parameter == null) + { + possible.forEach(suggestions::add); + } + else + { + possible.filter(suggestion -> suggestion.toLowerCase().startsWith(parameter.toLowerCase())).forEach(suggestions::add); + } + } + +} diff --git a/src/main/java/me/clip/placeholderapi/commands/PlaceholderCommandRouter.java b/src/main/java/me/clip/placeholderapi/commands/PlaceholderCommandRouter.java new file mode 100644 index 0000000..cc75744 --- /dev/null +++ b/src/main/java/me/clip/placeholderapi/commands/PlaceholderCommandRouter.java @@ -0,0 +1,126 @@ +package me.clip.placeholderapi.commands; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import me.clip.placeholderapi.PlaceholderAPIPlugin; +import me.clip.placeholderapi.commands.impl.cloud.CommandECloud; +import me.clip.placeholderapi.commands.impl.local.CommandExpansionRegister; +import me.clip.placeholderapi.commands.impl.local.CommandExpansionUnregister; +import me.clip.placeholderapi.commands.impl.local.CommandHelp; +import me.clip.placeholderapi.commands.impl.local.CommandInfo; +import me.clip.placeholderapi.commands.impl.local.CommandList; +import me.clip.placeholderapi.commands.impl.local.CommandParse; +import me.clip.placeholderapi.commands.impl.local.CommandReload; +import me.clip.placeholderapi.commands.impl.local.CommandVersion; +import me.clip.placeholderapi.util.Msg; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Unmodifiable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.stream.Stream; + +public final class PlaceholderCommandRouter implements CommandExecutor, TabCompleter +{ + + @Unmodifiable + private static final List COMMANDS = ImmutableList.of(new CommandHelp(), + new CommandInfo(), + new CommandList(), + new CommandECloud(), + new CommandParse(), + new CommandReload(), + new CommandVersion(), + new CommandExpansionRegister(), + new CommandExpansionUnregister()); + + + @NotNull + private final PlaceholderAPIPlugin plugin; + @NotNull + @Unmodifiable + private final Map commands; + + + public PlaceholderCommandRouter(@NotNull final PlaceholderAPIPlugin plugin) + { + this.plugin = plugin; + + final ImmutableMap.Builder commands = ImmutableMap.builder(); + + for (final PlaceholderCommand command : COMMANDS) + { + command.getLabels().forEach(label -> commands.put(label, command)); + } + + this.commands = commands.build(); + } + + + @Override + public boolean onCommand(@NotNull final CommandSender sender, @NotNull final Command command, @NotNull final String alias, @NotNull final String[] args) + { + if (args.length == 0) + { + final PlaceholderCommand fallback = commands.get("version"); + if (fallback != null) + { + fallback.evaluate(plugin, sender, "", Collections.emptyList()); + } + + return true; + } + + final String search = args[0].toLowerCase(); + final PlaceholderCommand target = commands.get(search); + + if (target == null) + { + Msg.msg(sender, "&cUnknown command &7" + search); + return true; + } + + final String permission = target.getPermission(); + if (permission != null && !permission.isEmpty() && !sender.hasPermission(permission)) + { + Msg.msg(sender, "&cYou do not have permission to do this!"); + return true; + } + + target.evaluate(plugin, sender, search, Arrays.asList(Arrays.copyOfRange(args, 1, args.length))); + + return true; + } + + @Override + public List onTabComplete(@NotNull final CommandSender sender, @NotNull final Command command, @NotNull final String alias, @NotNull final String[] args) + { + final List suggestions = new ArrayList<>(); + + if (args.length > 1) + { + final PlaceholderCommand target = this.commands.get(args[0].toLowerCase()); + + if (target != null) + { + target.complete(plugin, sender, args[0].toLowerCase(), Arrays.asList(Arrays.copyOfRange(args, 1, args.length)), suggestions); + } + + return suggestions; + } + + final Stream targets = PlaceholderCommand.filterByPermission(sender, commands.values().stream()).map(PlaceholderCommand::getLabels).flatMap(Collection::stream); + PlaceholderCommand.suggestByParameter(targets, suggestions, args.length == 0 ? null : args[0]); + + return suggestions; + } + +} diff --git a/src/main/java/me/clip/placeholderapi/commands/command/BcParseCommand.java b/src/main/java/me/clip/placeholderapi/commands/command/BcParseCommand.java deleted file mode 100644 index 8808dc3..0000000 --- a/src/main/java/me/clip/placeholderapi/commands/command/BcParseCommand.java +++ /dev/null @@ -1,47 +0,0 @@ -package me.clip.placeholderapi.commands.command; - -import me.clip.placeholderapi.PlaceholderAPI; -import me.clip.placeholderapi.commands.Command; -import me.clip.placeholderapi.util.Msg; -import org.apache.commons.lang.StringUtils; -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, "placeholderapi.parse")); - } - - @Override - 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 { - if (Bukkit.getPlayer(input) != null) { - player = Bukkit.getPlayer(input); - } else { - player = Bukkit.getOfflinePlayer(input); - } - } - - 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)); - } -} diff --git a/src/main/java/me/clip/placeholderapi/commands/command/DisableEcloudCommand.java b/src/main/java/me/clip/placeholderapi/commands/command/DisableEcloudCommand.java deleted file mode 100644 index 9e2e841..0000000 --- a/src/main/java/me/clip/placeholderapi/commands/command/DisableEcloudCommand.java +++ /dev/null @@ -1,29 +0,0 @@ -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 DisableEcloudCommand extends Command { - public DisableEcloudCommand() { - super("disablecloud", permissions("placeholderapi.ecloud")); - } - - @Override - 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; - } -} diff --git a/src/main/java/me/clip/placeholderapi/commands/command/EcloudCommand.java b/src/main/java/me/clip/placeholderapi/commands/command/EcloudCommand.java deleted file mode 100644 index b37899e..0000000 --- a/src/main/java/me/clip/placeholderapi/commands/command/EcloudCommand.java +++ /dev/null @@ -1,81 +0,0 @@ -package me.clip.placeholderapi.commands.command; - -import com.google.common.collect.Sets; -import me.clip.placeholderapi.PlaceholderAPIPlugin; -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; -import java.util.Set; - -public final class EcloudCommand extends Command { - private static final int MAXIMUM_ARGUMENTS = 1; - private static final Set COMPLETIONS = Sets.newHashSet( - "clear", - "download", - "info", - "list", - "placeholders", - "refresh", - "status", - "versioninfo" - ); - - public EcloudCommand() { - super("ecloud", permissions("placeholderapi.ecloud")); - } - - @Override - 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", - " ", - "&b/papi ecloud status", - "&fView status of the ecloud", - "&b/papi ecloud list (page)", - "&fList all/author specific available expansions", - "&b/papi ecloud info ", - "&fView information about a specific expansion available on the cloud", - "&b/papi ecloud versioninfo ", - "&fView information about a specific version of an expansion", - "&b/papi ecloud placeholders ", - "&fView placeholders for an expansion", - "&b/papi ecloud download (version)", - "&fDownload an expansion from the ecloud", - "&b/papi ecloud refresh", - "&fFetch the most up to date list of expansions available.", - "&b/papi ecloud clear", - "&fClear the expansion cloud cache."); - return; - } - - if (plugin.getExpansionCloud() == null) { - Msg.msg(sender, "&7The expansion cloud is not enabled!"); - - return; - } - - if (plugin.getExpansionCloud().getCloudExpansions().isEmpty()) { - Msg.msg(sender, "&7No cloud expansions are available at this time."); - return; - } - - sender.sendMessage("Specified command is not valid."); - } - - @NotNull - @Override - public List handleCompletion(@NotNull final CommandSender sender, @NotNull final String[] args) { - if (args.length == MAXIMUM_ARGUMENTS) { - return StringUtil.copyPartialMatches(args[0], COMPLETIONS, new ArrayList<>(COMPLETIONS.size())); - } - - return super.handleCompletion(sender, args); - } -} diff --git a/src/main/java/me/clip/placeholderapi/commands/command/EnableCloudCommand.java b/src/main/java/me/clip/placeholderapi/commands/command/EnableCloudCommand.java deleted file mode 100644 index f82ce4e..0000000 --- a/src/main/java/me/clip/placeholderapi/commands/command/EnableCloudCommand.java +++ /dev/null @@ -1,27 +0,0 @@ -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 EnableCloudCommand extends Command { - public EnableCloudCommand() { - super("enablecloud", permissions("placeholderapi.ecloud")); - } - - @Override - 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; - } - - plugin.enableCloud(); - plugin.getPlaceholderAPIConfig().setCloudEnabled(true); - Msg.msg(sender, "&aThe cloud has been enabled!"); - } -} diff --git a/src/main/java/me/clip/placeholderapi/commands/command/HelpCommand.java b/src/main/java/me/clip/placeholderapi/commands/command/HelpCommand.java deleted file mode 100644 index 0ef952f..0000000 --- a/src/main/java/me/clip/placeholderapi/commands/command/HelpCommand.java +++ /dev/null @@ -1,46 +0,0 @@ -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 HelpCommand extends Command { - public HelpCommand() { - super("help", permissions("placeholderapi.ecloud")); - } - - @Override - 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", - "&b/papi list", - "&fList all placeholder expansions that are currently active", - "&b/papi info ", - "&fView information for a specific expansion", - "&b/papi parse <(playername)/me> <...args>", - "&fParse a String with placeholders", - "&b/papi bcparse <(playername)/me> <...args>", - "&fParse a String with placeholders and broadcast the message", - "&b/papi parserel <...args>", - "&fParse a String with relational placeholders", - "&b/papi register ", - "&fRegister an expansion by the name of the file", - "&b/papi unregister ", - "&fUnregister an expansion by name", - "&b/papi reload", - "&fReload the config settings"); - - if (sender.hasPermission("placeholderapi.ecloud")) { - Msg.msg(sender, "&b/papi disablecloud", - "&fDisable the expansion cloud", - "&b/papi ecloud", - "&fView ecloud command usage", - "&b/papi enablecloud", - "&fEnable the expansion cloud"); - - } - } -} diff --git a/src/main/java/me/clip/placeholderapi/commands/command/InfoCommand.java b/src/main/java/me/clip/placeholderapi/commands/command/InfoCommand.java deleted file mode 100644 index 8987932..0000000 --- a/src/main/java/me/clip/placeholderapi/commands/command/InfoCommand.java +++ /dev/null @@ -1,68 +0,0 @@ -package me.clip.placeholderapi.commands.command; - -import me.clip.placeholderapi.PlaceholderAPI; -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.bukkit.command.CommandSender; -import org.bukkit.util.StringUtil; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -public final class InfoCommand extends Command { - private static final int MINIMUM_ARGUMENTS = 1; - - public InfoCommand() { - super("info", options("&cIncorrect usage! &7/papi info ", MINIMUM_ARGUMENTS, "placeholderapi.info")); - } - - @Override - 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); - - return; - } - - Msg.msg(sender, "&7Placeholder expansion info for: &f" + ex.getName()); - Msg.msg(sender, "&7Status: " + (ex.isRegistered() ? "&aRegistered" : "&cNot registered")); - - if (ex.getAuthor() != null) { - Msg.msg(sender, "&7Created by: &f" + ex.getAuthor()); - } - - if (ex.getVersion() != null) { - Msg.msg(sender, "&7Version: &f" + ex.getVersion()); - } - - if (ex.getRequiredPlugin() != null) { - Msg.msg(sender, "&7Requires plugin: &f" + ex.getRequiredPlugin()); - } - - if (ex.getPlaceholders() != null) { - Msg.msg(sender, "&8&m-- &r&7Placeholders &8&m--"); - - for (String placeholder : ex.getPlaceholders()) { - Msg.msg(sender, placeholder); - } - } - } - - @NotNull - @Override - public List handleCompletion(@NotNull final CommandSender sender, @NotNull final String[] args) { - if (args.length == MINIMUM_ARGUMENTS) { - final Set completions = PlaceholderAPI.getRegisteredIdentifiers(); - - return StringUtil.copyPartialMatches(args[0], completions, new ArrayList<>(completions.size())); - } - - return super.handleCompletion(sender, args); - } -} diff --git a/src/main/java/me/clip/placeholderapi/commands/command/ListCommand.java b/src/main/java/me/clip/placeholderapi/commands/command/ListCommand.java deleted file mode 100644 index ba8aa66..0000000 --- a/src/main/java/me/clip/placeholderapi/commands/command/ListCommand.java +++ /dev/null @@ -1,28 +0,0 @@ -package me.clip.placeholderapi.commands.command; - -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", permissions("placeholderapi.list")); - } - - @Override - public void execute(@NotNull final CommandSender sender, @NotNull final String[] args) { - final Set registered = PlaceholderAPI.getRegisteredIdentifiers(); - if (registered.isEmpty()) { - Msg.msg(sender, "&7There are no placeholder hooks currently registered!"); - return; - } - - Msg.msg(sender, registered.size() + " &7Placeholder hooks registered:", - registered.stream().sorted().collect(Collectors.joining(", "))); - } -} diff --git a/src/main/java/me/clip/placeholderapi/commands/command/ParseCommand.java b/src/main/java/me/clip/placeholderapi/commands/command/ParseCommand.java deleted file mode 100644 index 4166a47..0000000 --- a/src/main/java/me/clip/placeholderapi/commands/command/ParseCommand.java +++ /dev/null @@ -1,47 +0,0 @@ -package me.clip.placeholderapi.commands.command; - -import me.clip.placeholderapi.PlaceholderAPI; -import me.clip.placeholderapi.commands.Command; -import me.clip.placeholderapi.util.Msg; -import org.apache.commons.lang.StringUtils; -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 ParseCommand extends Command { - public ParseCommand() { - super("parse", options("&cYou must specify a player.", 1, "placeholderapi.parse")); - } - - @Override - 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 { - if (Bukkit.getPlayer(input) != null) { - player = Bukkit.getPlayer(input); - } else { - player = Bukkit.getOfflinePlayer(input); - } - } - - 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)); - } -} diff --git a/src/main/java/me/clip/placeholderapi/commands/command/ParseRelCommand.java b/src/main/java/me/clip/placeholderapi/commands/command/ParseRelCommand.java deleted file mode 100644 index 20afb90..0000000 --- a/src/main/java/me/clip/placeholderapi/commands/command/ParseRelCommand.java +++ /dev/null @@ -1,36 +0,0 @@ -package me.clip.placeholderapi.commands.command; - -import me.clip.placeholderapi.PlaceholderAPI; -import me.clip.placeholderapi.commands.Command; -import me.clip.placeholderapi.util.Msg; -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, "placeholderapi.parse")); - } - - @Override - 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; - } - - final Player two = Bukkit.getPlayer(args[1]); - if (two == null) { - Msg.msg(sender, args[1] + " &cis not online!"); - - return; - } - - final String parse = StringUtils.join(args, " ", 1, args.length); - Msg.msg(sender, "&r" + PlaceholderAPI.setRelationalPlaceholders(one, two, parse)); - } -} diff --git a/src/main/java/me/clip/placeholderapi/commands/command/RegisterCommand.java b/src/main/java/me/clip/placeholderapi/commands/command/RegisterCommand.java deleted file mode 100644 index 6df7b74..0000000 --- a/src/main/java/me/clip/placeholderapi/commands/command/RegisterCommand.java +++ /dev/null @@ -1,28 +0,0 @@ -package me.clip.placeholderapi.commands.command; - -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.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,"placeholderapi.register")); - } - - @Override - 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; - } - - Msg.msg(sender, "&aSuccessfully registered expansion: &f" + expansion.getName()); - } -} diff --git a/src/main/java/me/clip/placeholderapi/commands/command/ReloadCommand.java b/src/main/java/me/clip/placeholderapi/commands/command/ReloadCommand.java deleted file mode 100644 index cf01301..0000000 --- a/src/main/java/me/clip/placeholderapi/commands/command/ReloadCommand.java +++ /dev/null @@ -1,19 +0,0 @@ -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 ReloadCommand extends Command { - public ReloadCommand() { - super("reload", permissions("placeholderapi.reload")); - } - - @Override - public void execute(@NotNull final CommandSender sender, @NotNull final String[] args) { - Msg.msg(sender, "&fPlaceholder&7API &bconfiguration reloaded!"); - PlaceholderAPIPlugin.getInstance().reloadConf(sender); - } -} diff --git a/src/main/java/me/clip/placeholderapi/commands/command/UnregisterCommand.java b/src/main/java/me/clip/placeholderapi/commands/command/UnregisterCommand.java deleted file mode 100644 index b20657e..0000000 --- a/src/main/java/me/clip/placeholderapi/commands/command/UnregisterCommand.java +++ /dev/null @@ -1,53 +0,0 @@ -package me.clip.placeholderapi.commands.command; - -import me.clip.placeholderapi.PlaceholderAPI; -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.bukkit.command.CommandSender; -import org.bukkit.util.StringUtil; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -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, "placeholderapi.register")); - } - - @Override - 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; - } - - if (PlaceholderAPI.unregisterExpansion(expansion)) { - Msg.msg(sender, "&aSuccessfully unregistered expansion: &f" + expansion.getName()); - } else { - Msg.msg(sender, "&cFailed to unregister expansion: &f" + expansion.getName()); - } - } - - @NotNull - @Override - public List handleCompletion(@NotNull final CommandSender sender, @NotNull final String[] args) { - if (args.length == MINIMUM_ARGUMENTS) { - final Set completions = PlaceholderAPI.getRegisteredIdentifiers(); - - return StringUtil.copyPartialMatches(args[0], completions, new ArrayList<>(completions.size())); - } - - return super.handleCompletion(sender, args); - } -} diff --git a/src/main/java/me/clip/placeholderapi/commands/command/VersionCommand.java b/src/main/java/me/clip/placeholderapi/commands/command/VersionCommand.java deleted file mode 100644 index efab041..0000000 --- a/src/main/java/me/clip/placeholderapi/commands/command/VersionCommand.java +++ /dev/null @@ -1,55 +0,0 @@ -package me.clip.placeholderapi.commands.command; - -import com.google.common.collect.Sets; -import me.clip.placeholderapi.PlaceholderAPIPlugin; -import me.clip.placeholderapi.commands.Command; -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; -import java.util.Set; - -public final class VersionCommand extends Command { - private static final Set COMPLETIONS = Sets.newHashSet( - "unregister", - "reload", - "register", - "parserel", - "parse", - "list", - "info", - "help", - "ecloud", - "enablecloud", - "disablecloud", - "bcparse" - ); - - public VersionCommand() { - super("version"); - } - - @Override - 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(), - "&fPapi commands: &b/papi help", - "&fEcloud commands: &b/papi ecloud"); - } - - @NotNull - @Override - public List handleCompletion(@NotNull final CommandSender sender, @NotNull final String[] args) { - if (args.length == 1) { - return StringUtil.copyPartialMatches(args[0], COMPLETIONS, new ArrayList<>(COMPLETIONS.size())); - } - - return super.handleCompletion(sender, args); - } -} \ No newline at end of file diff --git a/src/main/java/me/clip/placeholderapi/commands/command/ecloud/EcloudClearCommand.java b/src/main/java/me/clip/placeholderapi/commands/command/ecloud/EcloudClearCommand.java deleted file mode 100644 index 3a77d89..0000000 --- a/src/main/java/me/clip/placeholderapi/commands/command/ecloud/EcloudClearCommand.java +++ /dev/null @@ -1,19 +0,0 @@ -package me.clip.placeholderapi.commands.command.ecloud; - -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", permissions("placeholderapi.ecloud")); - } - - @Override - public void execute(@NotNull final CommandSender sender, @NotNull final String[] args) { - PlaceholderAPIPlugin.getInstance().getExpansionCloud().clean(); - Msg.msg(sender, "&aThe cache has been cleared!!"); - } -} diff --git a/src/main/java/me/clip/placeholderapi/commands/command/ecloud/EcloudDownloadCommand.java b/src/main/java/me/clip/placeholderapi/commands/command/ecloud/EcloudDownloadCommand.java deleted file mode 100644 index d9bac27..0000000 --- a/src/main/java/me/clip/placeholderapi/commands/command/ecloud/EcloudDownloadCommand.java +++ /dev/null @@ -1,55 +0,0 @@ -package me.clip.placeholderapi.commands.command.ecloud; - -import me.clip.placeholderapi.PlaceholderAPI; -import me.clip.placeholderapi.PlaceholderAPIPlugin; -import me.clip.placeholderapi.commands.Command; -import me.clip.placeholderapi.expansion.PlaceholderExpansion; -import me.clip.placeholderapi.expansion.cloud.CloudExpansion; -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, "placeholderapi.ecloud")); - } - - @Override - 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; - } - - final PlaceholderExpansion loaded = plugin.getExpansionManager().getRegisteredExpansion(input); - if (loaded != null && loaded.isRegistered()) { - PlaceholderAPI.unregisterPlaceholderHook(loaded.getIdentifier()); - } - - String version = expansion.getLatestVersion(); - - if (args.length == 2) { - version = args[1]; - if (expansion.getVersion(version) == null) { - Msg.msg(sender, "&cThe version you specified does not exist for &f" + expansion.getName()); - Msg.msg(sender, "&7Available versions: &f" + expansion.getVersions().size()); - Msg.msg(sender, String.join("&a, &f", expansion.getAvailableVersions())); - - return; - } - } - - Msg.msg(sender, "&aDownload starting for expansion: &f" + expansion.getName() + " &aversion: &f" + version); - 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()); - } -} diff --git a/src/main/java/me/clip/placeholderapi/commands/command/ecloud/EcloudInfoCommand.java b/src/main/java/me/clip/placeholderapi/commands/command/ecloud/EcloudInfoCommand.java deleted file mode 100644 index de40e0b..0000000 --- a/src/main/java/me/clip/placeholderapi/commands/command/ecloud/EcloudInfoCommand.java +++ /dev/null @@ -1,70 +0,0 @@ -package me.clip.placeholderapi.commands.command.ecloud; - -import me.clip.placeholderapi.PlaceholderAPIPlugin; -import me.clip.placeholderapi.commands.Command; -import me.clip.placeholderapi.expansion.cloud.CloudExpansion; -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, "placeholderapi.ecloud")); - } - - @Override - 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; - } - - if (!(sender instanceof Player)) { - Msg.msg(sender, - (expansion.shouldUpdate() ? "&e" : "") + expansion.getName() + " &8&m-- &r" + expansion - .getVersion().getUrl()); - - return; - } - - final Player p = (Player) sender; - - Msg.msg(sender, "&bExpansion&7: &f" + expansion.getName(), - "&bAuthor: &f" + expansion.getAuthor(), - "&bVerified: &f" + expansion.isVerified() - ); - - // latest version - 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() - )); - latestVersion.send(p); - - // versions - final JSONMessage versions = JSONMessage - .create(color("&bVersions available: &f" + expansion.getVersions().size())); - versions.tooltip(color(String.join("&b, &f", expansion.getAvailableVersions()))); - versions.suggestCommand( - "/papi ecloud versioninfo " + expansion.getName() + " " + expansion.getLatestVersion()); - versions.send(p); - - // placeholders - if (expansion.getPlaceholders() != null) { - 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()); - placeholders.send(p); - } - } -} diff --git a/src/main/java/me/clip/placeholderapi/commands/command/ecloud/EcloudListCommand.java b/src/main/java/me/clip/placeholderapi/commands/command/ecloud/EcloudListCommand.java deleted file mode 100644 index adc545e..0000000 --- a/src/main/java/me/clip/placeholderapi/commands/command/ecloud/EcloudListCommand.java +++ /dev/null @@ -1,208 +0,0 @@ -package me.clip.placeholderapi.commands.command.ecloud; - -import com.google.common.collect.Sets; -import me.clip.placeholderapi.PlaceholderAPIPlugin; -import me.clip.placeholderapi.commands.Command; -import me.clip.placeholderapi.expansion.cloud.CloudExpansion; -import me.clip.placeholderapi.util.Msg; -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; - -import static me.clip.placeholderapi.util.Msg.color; - -public final class EcloudListCommand extends Command { - private static final int MINIMUM_ARGUMENTS = 1; - private static final Set COMPLETIONS = Sets.newHashSet( - "all", - "author", - "installed" - ); - - public EcloudListCommand() { - super("ecloud list", options("&cIncorrect usage! &7/papi ecloud list (page)", - MINIMUM_ARGUMENTS, "placeholderapi.ecloud")); - } - - @Override - public void execute(@NotNull final CommandSender sender, @NotNull final String[] args) { - final PlaceholderAPIPlugin plugin = PlaceholderAPIPlugin.getInstance(); - int page = 1; - - String author; - boolean installed = false; - - author = args[0]; - - if (author.equalsIgnoreCase("all")) { - author = null; - } else if (author.equalsIgnoreCase("installed")) { - author = null; - installed = true; - } - - if (args.length >= 2) { - try { - page = Integer.parseInt(args[1]); - } catch (NumberFormatException ex) { - Msg.msg(sender, "&cPage number must be an integer!"); - - return; - } - } - - if (page < 1) { - Msg.msg(sender, "&cPage must be greater than or equal to 1!"); - - return; - } - - int avail; - Map ex; - - if (installed) { - ex = plugin.getExpansionCloud().getAllInstalled(); - } else if (author == null) { - ex = plugin.getExpansionCloud().getCloudExpansions(); - } else { - ex = plugin.getExpansionCloud().getAllByAuthor(author); - } - - if (ex == null || ex.isEmpty()) { - Msg.msg(sender, "&cNo expansions available" + (author != null ? " for author &f" + author : "")); - - return; - } - - avail = plugin.getExpansionCloud().getPagesAvailable(ex, 10); - if (page > avail) { - Msg.msg(sender, "&cThere " + ((avail == 1) ? " is only &f" + avail + " &cpage available!" - : "are only &f" + avail + " &cpages available!")); - - return; - } - - Msg.msg(sender, "&bShowing expansions for&7: &f" + (author != null ? author - : (installed ? "all installed" : "all available")) + " &8&m--&r &bamount&7: &f" + ex - .size() + " &bpage&7: &f" + page + "&7/&f" + avail); - - ex = plugin.getExpansionCloud().getPage(ex, page, 10); - - if (ex == null) { - Msg.msg(sender, "&cThere was a problem getting the requested page..."); - - return; - } - - Msg.msg(sender, "&aGreen = Expansions you have"); - Msg.msg(sender, "&6Gold = Expansions which need updated"); - - if (!(sender instanceof Player)) { - final Map expansions = new HashMap<>(); - - for (CloudExpansion exp : ex.values()) { - if (exp == null || exp.getName() == null) { - continue; - } - - expansions.put(exp.getName(), exp); - } - - final List ce = expansions.keySet().stream().sorted().collect(Collectors.toList()); - - int i = (int) ex.keySet().toArray()[0]; - - for (String name : ce) { - if (expansions.get(name) == null) { - continue; - } - - final CloudExpansion expansion = expansions.get(name); - - Msg.msg(sender, - "&b" + i + "&7: " + (expansion.shouldUpdate() ? "&6" - : (expansion.hasExpansion() ? "&a" : "&7")) + expansion - .getName() + " &8&m-- &r" + expansion.getVersion().getUrl()); - i++; - } - - return; - } - - final Player p = (Player) sender; - - final Map expansions = new HashMap<>(); - - for (final CloudExpansion exp : ex.values()) { - if (exp == null || exp.getName() == null) { - continue; - } - - expansions.put(exp.getName(), exp); - } - - final List ce = expansions.keySet().stream().sorted().collect(Collectors.toList()); - - int i = page > 1 ? page * 10 : 0; - - for (String name : ce) { - if (expansions.get(name) == null) { - continue; - } - - 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"); - } else if (!expansion.hasExpansion()) { - sb.append("&bClick to download this expansion\n\n"); - } else { - sb.append("&aYou have the latest version of this expansion\n\n"); - } - - sb.append("&bAuthor&7: &f").append(expansion.getAuthor()).append("\n"); - sb.append("&bVerified&7: &f").append(expansion.isVerified()).append("\n"); - sb.append("&bLatest version&7: &f").append(expansion.getVersion().getVersion()).append("\n"); - sb.append("&bLast updated&7: &f").append(expansion.getTimeSinceLastUpdate()).append(" ago\n"); - sb.append("\n").append(expansion.getDescription()); - - final String msg = color( - "&b" + (i + 1) + "&7: " + (expansion.shouldUpdate() ? "&6" - : (expansion.hasExpansion() ? "&a" : "")) + expansion.getName()); - - final String hover = color(sb.toString()); - - final JSONMessage line = JSONMessage.create(msg); - line.tooltip(hover); - - if (expansion.shouldUpdate() || !expansion.hasExpansion()) { - line.suggestCommand("/papi ecloud download " + expansion.getName()); - } else { - line.suggestCommand("/papi ecloud info " + expansion.getName()); - } - - line.send(p); - i++; - } - } - - @NotNull - @Override - public List handleCompletion(@NotNull final CommandSender sender, @NotNull final String[] args) { - if (args.length == MINIMUM_ARGUMENTS) { - return StringUtil.copyPartialMatches(args[0], COMPLETIONS, new ArrayList<>(COMPLETIONS.size())); - } - - if (args.length == MINIMUM_ARGUMENTS + 1) { - return Collections.singletonList("Pages"); - } - - return super.handleCompletion(sender, args); - } -} diff --git a/src/main/java/me/clip/placeholderapi/commands/command/ecloud/EcloudPlaceholdersCommand.java b/src/main/java/me/clip/placeholderapi/commands/command/ecloud/EcloudPlaceholdersCommand.java deleted file mode 100644 index 49ded05..0000000 --- a/src/main/java/me/clip/placeholderapi/commands/command/ecloud/EcloudPlaceholdersCommand.java +++ /dev/null @@ -1,63 +0,0 @@ -package me.clip.placeholderapi.commands.command.ecloud; - -import me.clip.placeholderapi.PlaceholderAPI; -import me.clip.placeholderapi.PlaceholderAPIPlugin; -import me.clip.placeholderapi.commands.Command; -import me.clip.placeholderapi.expansion.cloud.CloudExpansion; -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, "placeholderapi.ecloud")); - } - - @Override - 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; - } - - final List placeholders = expansion.getPlaceholders(); - if (placeholders == null) { - Msg.msg(sender, "&cThe expansion: &f" + expansion.getName() - + " &cdoes not have any placeholders listed.", - "&7You should contact &f" + expansion.getAuthor() + " &7and ask for them to be added."); - - return; - } - - if (!(sender instanceof Player) - || plugin.getExpansionManager().getRegisteredExpansion(expansion.getName()) == null) { - Msg.msg(sender, "&bPlaceholders: &f" + placeholders.size(), - String.join("&a, &f", placeholders)); - - return; - } - - 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 (final Exception ignored) { - // Ignored exception - } - } - - message.send(p); - } -} diff --git a/src/main/java/me/clip/placeholderapi/commands/command/ecloud/EcloudRefreshCommand.java b/src/main/java/me/clip/placeholderapi/commands/command/ecloud/EcloudRefreshCommand.java deleted file mode 100644 index 8e1dd8b..0000000 --- a/src/main/java/me/clip/placeholderapi/commands/command/ecloud/EcloudRefreshCommand.java +++ /dev/null @@ -1,23 +0,0 @@ -package me.clip.placeholderapi.commands.command.ecloud; - -import me.clip.placeholderapi.PlaceholderAPIPlugin; -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", permissions("placeholderapi.ecloud")); - } - - @Override - 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()); - } -} diff --git a/src/main/java/me/clip/placeholderapi/commands/command/ecloud/EcloudStatusCommand.java b/src/main/java/me/clip/placeholderapi/commands/command/ecloud/EcloudStatusCommand.java deleted file mode 100644 index fa5eec6..0000000 --- a/src/main/java/me/clip/placeholderapi/commands/command/ecloud/EcloudStatusCommand.java +++ /dev/null @@ -1,26 +0,0 @@ -package me.clip.placeholderapi.commands.command.ecloud; - -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", permissions("placeholderapi.ecloud")); - } - - @Override - 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() - + " &7authors have contributed to the expansion cloud."); - if (plugin.getExpansionCloud().getToUpdateCount() > 0) { - Msg.msg(sender, "&eYou have &f" + plugin.getExpansionCloud().getToUpdateCount() - + " &eexpansions installed that have updates available."); - } - } -} diff --git a/src/main/java/me/clip/placeholderapi/commands/command/ecloud/EcloudVersionInfoCommand.java b/src/main/java/me/clip/placeholderapi/commands/command/ecloud/EcloudVersionInfoCommand.java deleted file mode 100644 index 59637ea..0000000 --- a/src/main/java/me/clip/placeholderapi/commands/command/ecloud/EcloudVersionInfoCommand.java +++ /dev/null @@ -1,48 +0,0 @@ -package me.clip.placeholderapi.commands.command.ecloud; - -import me.clip.placeholderapi.PlaceholderAPIPlugin; -import me.clip.placeholderapi.commands.Command; -import me.clip.placeholderapi.expansion.cloud.CloudExpansion; -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 ", - 2, "placeholderapi.ecloud")); - } - - @Override - 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; - } - - 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; - } - - Msg.msg(sender, "&bExpansion: " + (expansion.shouldUpdate() ? "&e" : "&f") + expansion.getName(), - "&bVersion: &f" + version.getVersion(), - "&bVersion info: &f" + version.getReleaseNotes()); - - if (!(sender instanceof Player)) { - Msg.msg(sender, "&bDownload url: " + version.getUrl()); - return; - } - - 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()); - download.send(p); - } -} diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloud.java b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloud.java new file mode 100644 index 0000000..08eec91 --- /dev/null +++ b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloud.java @@ -0,0 +1,129 @@ +package me.clip.placeholderapi.commands.impl.cloud; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import me.clip.placeholderapi.PlaceholderAPIPlugin; +import me.clip.placeholderapi.commands.PlaceholderCommand; +import me.clip.placeholderapi.util.Msg; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Unmodifiable; + +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.stream.Stream; + +public final class CommandECloud extends PlaceholderCommand +{ + + @Unmodifiable + private static final List COMMANDS = ImmutableList.of(new CommandECloudClear(), + new CommandECloudToggle(), + new CommandECloudStatus(), + new CommandECloudRefresh(), + new CommandECloudDownload(), + new CommandECloudExpansionInfo(), + new CommandECloudExpansionList(), + new CommandECloudExpansionPlaceholders()); + + static + { + COMMANDS.forEach(command -> command.setPermission("placeholderapi.ecloud." + command.getLabel())); + } + + @NotNull + @Unmodifiable + private final Map commands; + + + public CommandECloud() + { + super("ecloud"); + + final ImmutableMap.Builder commands = ImmutableMap.builder(); + + for (final PlaceholderCommand command : COMMANDS) + { + command.getLabels().forEach(label -> commands.put(label, command)); + } + + this.commands = commands.build(); + } + + + @Override + public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params) + { + if (params.isEmpty()) + { + Msg.msg(sender, + "&b&lPlaceholderAPI &8- &7ECloud Help Menu &8- ", + " ", + "&b/papi &fecloud status", + " &7&oView status of the ecloud", + "&b/papi &fecloud list {page}", + " &7&oList all/author specific available expansions", + "&b/papi &fecloud info {version}", + " &7&oView information about a specific expansion available on the cloud", + "&b/papi &fecloud placeholders ", + " &7&oView placeholders for an expansion", + "&b/papi &fecloud download {version}", + " &7&oDownload an expansion from the ecloud", + "&b/papi &fecloud refresh", + " &7&oFetch the most up to date list of expansions available.", + "&b/papi &fecloud clear", + " &7&oClear the expansion cloud cache."); + + return; + } + + final String search = params.get(0).toLowerCase(); + final PlaceholderCommand target = commands.get(search); + + if (target == null) + { + Msg.msg(sender, "&cUnknown command &7ecloud " + search); + return; + } + + final String permission = target.getPermission(); + if (permission != null && !permission.isEmpty() && !sender.hasPermission(permission)) + { + Msg.msg(sender, "&cYou do not have permission to do this!"); + return; + } + + if (!(target instanceof CommandECloudToggle) && !plugin.getPlaceholderAPIConfig().isCloudEnabled()) + { + Msg.msg(sender, + "&cThe ECloud Manager is not enabled!"); + return; + } + + target.evaluate(plugin, sender, search, params.subList(1, params.size())); + } + + @Override + public void complete(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params, @NotNull final List suggestions) + { + if (params.size() <= 1) + { + final Stream targets = filterByPermission(sender, commands.values().stream()).map(PlaceholderCommand::getLabels).flatMap(Collection::stream); + suggestByParameter(targets, suggestions, params.isEmpty() ? null : params.get(0)); + + return; // send sub commands + } + + final String search = params.get(0).toLowerCase(); + final PlaceholderCommand target = commands.get(search); + + if (target == null) + { + return; + } + + target.complete(plugin, sender, search, params.subList(1, params.size()), suggestions); + } + +} diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudClear.java b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudClear.java new file mode 100644 index 0000000..a428669 --- /dev/null +++ b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudClear.java @@ -0,0 +1,28 @@ +package me.clip.placeholderapi.commands.impl.cloud; + +import me.clip.placeholderapi.PlaceholderAPIPlugin; +import me.clip.placeholderapi.commands.PlaceholderCommand; +import me.clip.placeholderapi.util.Msg; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Unmodifiable; + +import java.util.List; + +public final class CommandECloudClear extends PlaceholderCommand +{ + + public CommandECloudClear() + { + super("clear"); + } + + @Override + public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params) + { + plugin.getExpansionCloud().clean(); + Msg.msg(sender, + "&aThe ECloud cache has been cleared!"); + } + +} diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudDownload.java b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudDownload.java new file mode 100644 index 0000000..15431d1 --- /dev/null +++ b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudDownload.java @@ -0,0 +1,104 @@ +package me.clip.placeholderapi.commands.impl.cloud; + +import me.clip.placeholderapi.PlaceholderAPIPlugin; +import me.clip.placeholderapi.commands.PlaceholderCommand; +import me.clip.placeholderapi.expansion.cloud.CloudExpansion; +import me.clip.placeholderapi.util.Msg; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Unmodifiable; + +import java.util.List; +import java.util.Optional; +import java.util.stream.Stream; + +public final class CommandECloudDownload extends PlaceholderCommand +{ + + public CommandECloudDownload() + { + super("download"); + } + + @Override + public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params) + { + if (params.isEmpty()) + { + Msg.msg(sender, + "&cYou must supply the name of a cloud expansion."); + return; + } + + final CloudExpansion expansion = plugin.getExpansionCloud().getCloudExpansion(params.get(0)).orElse(null); + if (expansion == null) + { + Msg.msg(sender, + "&cCould not find expansion named: &f" + params.get(0)); + return; + } + + final CloudExpansion.Version version; + if (params.size() < 2) + { + version = expansion.getVersion(expansion.getLatestVersion()); + if (version == null) + { + Msg.msg(sender, + "&cCould not find latest version for expansion."); + return; + } + } + else + { + version = expansion.getVersion(params.get(1)); + if (version == null) + { + Msg.msg(sender, + "&cCould not find specified version: &f" + params.get(1), + "&7Versions: &a" + expansion.getAvailableVersions()); + return; + } + } + + plugin.getExpansionCloud().downloadExpansion(expansion, version).whenComplete((file, exception) -> { + if (exception != null) + { + Msg.msg(sender, + "&cFailed to download expansion: &e" + exception.getMessage()); + return; + } + + Msg.msg(sender, + "&aSuccessfully downloaded expansion to file: &e" + file.getName()); + + plugin.getExpansionCloud().clean(); + plugin.getExpansionCloud().fetch(plugin.getPlaceholderAPIConfig().cloudAllowUnverifiedExpansions()); + }); + } + + @Override + public void complete(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params, @NotNull final List suggestions) + { + if (params.size() > 2) + { + return; + } + + if (params.size() <= 1) + { + final Stream names = plugin.getExpansionCloud().getCloudExpansions().values().stream().map(CloudExpansion::getName).map(name -> name.replace(' ', '_')); + suggestByParameter(names, suggestions, params.isEmpty() ? null : params.get(0)); + return; + } + + final Optional expansion = plugin.getExpansionCloud().getCloudExpansion(params.get(0)); + if (!expansion.isPresent()) + { + return; + } + + suggestByParameter(expansion.get().getAvailableVersions().stream(), suggestions, params.get(1)); + } + +} diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudExpansionInfo.java b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudExpansionInfo.java new file mode 100644 index 0000000..91514f3 --- /dev/null +++ b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudExpansionInfo.java @@ -0,0 +1,116 @@ +package me.clip.placeholderapi.commands.impl.cloud; + +import me.clip.placeholderapi.PlaceholderAPIPlugin; +import me.clip.placeholderapi.commands.PlaceholderCommand; +import me.clip.placeholderapi.expansion.cloud.CloudExpansion; +import me.clip.placeholderapi.util.Msg; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Unmodifiable; + +import java.util.List; +import java.util.Optional; +import java.util.stream.Stream; + +public final class CommandECloudExpansionInfo extends PlaceholderCommand +{ + + public CommandECloudExpansionInfo() + { + super("info"); + } + + @Override + public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params) + { + if (params.isEmpty()) + { + Msg.msg(sender, + "&cYou must specify the name of the expansion."); + return; + } + + final CloudExpansion expansion = plugin.getExpansionCloud().getCloudExpansion(params.get(0)).orElse(null); + if (expansion == null) + { + Msg.msg(sender, + "&cThere is no expansion with the name: &f" + params.get(0)); + return; + } + + final StringBuilder builder = new StringBuilder(); + + builder.append("&bExpansion: &f") + .append(expansion.shouldUpdate() ? "&e" : "&a") + .append(expansion.getName()) + .append('\n') + .append("&bAuthor: &f") + .append(expansion.getAuthor()) + .append('\n') + .append("&bVerified: ") + .append(expansion.isVerified() ? "&a&l✔" : "&c&l❌") + .append('\n'); + + if (params.size() < 2) + { + builder.append("&bLatest Version: &f") + .append(expansion.getLatestVersion()) + .append('\n') + .append("&bReleased: &f") + .append(expansion.getTimeSinceLastUpdate()) + .append(" ago") + .append('\n') + .append("&bRelease Notes: &f") + .append(expansion.getVersion().getReleaseNotes()) + .append('\n'); + } + else + { + final CloudExpansion.Version version = expansion.getVersion(params.get(1)); + if (version == null) + { + Msg.msg(sender, + "&cCould not find specified version: &f" + params.get(1), + "&7Versions: &a" + expansion.getAvailableVersions()); + return; + } + + builder.append("&bVersion: &f") + .append(version.getVersion()) + .append('\n') + .append("&bRelease Notes: &f") + .append(version.getReleaseNotes()) + .append('\n') + .append("&bDownload URL: &f") + .append(version.getUrl()) + .append('\n'); + } + + Msg.msg(sender, builder.toString()); + } + + @Override + public void complete(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params, @NotNull final List suggestions) + { + if (params.size() > 2) + { + return; + } + + if (params.size() <= 1) + { + final Stream names = plugin.getExpansionCloud().getCloudExpansions().values().stream().map(CloudExpansion::getName).map(name -> name.replace(' ', '_')); + suggestByParameter(names, suggestions, params.isEmpty() ? null : params.get(0)); + return; + } + + final Optional expansion = plugin.getExpansionCloud().getCloudExpansion(params.get(0)); + if (!expansion.isPresent()) + { + return; + } + + suggestByParameter(expansion.get().getAvailableVersions().stream(), suggestions, params.get(1)); + } + +} diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudExpansionList.java b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudExpansionList.java new file mode 100644 index 0000000..4e4a8d5 --- /dev/null +++ b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudExpansionList.java @@ -0,0 +1,174 @@ +package me.clip.placeholderapi.commands.impl.cloud; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; +import com.google.common.primitives.Ints; +import me.clip.placeholderapi.PlaceholderAPIPlugin; +import me.clip.placeholderapi.commands.PlaceholderCommand; +import me.clip.placeholderapi.expansion.cloud.CloudExpansion; +import me.clip.placeholderapi.util.Msg; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Unmodifiable; + +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +public final class CommandECloudExpansionList extends PlaceholderCommand +{ + + private static final int PAGE_SIZE = 3; + + + @Unmodifiable + private static final Set OPTIONS = ImmutableSet.of("all", "installed"); + + + public CommandECloudExpansionList() + { + super("list"); + } + + + @Override + public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params) + { + if (params.isEmpty()) + { + Msg.msg(sender, + "&cYou must specify an option. [all, {author}, installed]"); + return; + } + + + @Unmodifiable final Map expansions = getExpansions(params.get(0), plugin); + + final int page; + + if (params.size() < 2) + { + page = 1; + } + else + { + //noinspection UnstableApiUsage + final Integer parsed = Ints.tryParse(params.get(1)); + if (parsed == null) + { + Msg.msg(sender, + "&cPage number must be an integer."); + return; + } + + final int limit = (int) Math.ceil((double) expansions.size() / PAGE_SIZE); + + if (parsed < 1 || parsed > limit) + { + Msg.msg(sender, + "&cPage number must be in the range &8[&a1&7..&a" + limit + "&8]"); + return; + } + + page = parsed; + } + + + final StringBuilder builder = new StringBuilder(); + final List values = getPage(expansions, page - 1, PAGE_SIZE); + + + switch (params.get(0).toLowerCase()) + { + case "all": + builder.append("&bAll Expansions"); + break; + case "installed": + builder.append("&bInstalled Expansions"); + break; + default: + builder.append("&bExpansions by &6") + .append(params.get(0)); + break; + } + + builder.append(" &bPage&7: &a") + .append(page) + .append('\n'); + + int index = ((page - 1) * PAGE_SIZE) + 1; + for (final CloudExpansion expansion : values) + { + builder.append("&8") + .append(index++) + .append(". ") + .append(expansion.shouldUpdate() ? "&e" : "&a") + .append(expansion.getName()) + .append('\n') + .append(" &bAuthor: &f") + .append(expansion.getAuthor()) + .append('\n') + .append(" &bVerified: ") + .append(expansion.isVerified() ? "&a&l✔&r" : "&c&l❌&r") + .append('\n') + .append(" &bLatest Version: &f") + .append(expansion.getLatestVersion()) + .append('\n'); + } + + Msg.msg(sender, builder.toString()); + } + + @Override + public void complete(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params, @NotNull final List suggestions) + { + if (params.size() > 2) + { + return; + } + + if (params.size() <= 1) + { + suggestByParameter(Sets.union(OPTIONS, plugin.getExpansionCloud().getCloudAuthorNames()).stream(), suggestions, params.isEmpty() ? null : params.get(0)); + return; + } + + final Map expansions = getExpansions(params.get(0), plugin); + + suggestByParameter(IntStream.rangeClosed(1, (int) Math.ceil((double) expansions.size() / PAGE_SIZE)).mapToObj(Objects::toString), suggestions, params.get(1)); + } + + + @NotNull + private static List getPage(@NotNull final Map expansions, final int page, final int pageSize) + { + if (expansions.isEmpty()) + { + return Collections.emptyList(); + } + + final int head = (page * pageSize); + final int tail = (head + pageSize); + + return IntStream.range(head, tail).mapToObj(expansions::get).filter(Objects::nonNull).collect(Collectors.toList()); + } + + @NotNull + private static Map getExpansions(@NotNull final String target, @NotNull final PlaceholderAPIPlugin plugin) + { + switch (target.toLowerCase()) + { + case "all": + return plugin.getExpansionCloud().getCloudExpansions(); + case "installed": + return plugin.getExpansionCloud().getAllInstalled(); + default: + return plugin.getExpansionCloud().getAllByAuthor(target); + } + } + +} diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudExpansionPlaceholders.java b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudExpansionPlaceholders.java new file mode 100644 index 0000000..9f6a3ac --- /dev/null +++ b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudExpansionPlaceholders.java @@ -0,0 +1,70 @@ +package me.clip.placeholderapi.commands.impl.cloud; + +import com.google.common.collect.Lists; +import me.clip.placeholderapi.PlaceholderAPIPlugin; +import me.clip.placeholderapi.commands.PlaceholderCommand; +import me.clip.placeholderapi.expansion.cloud.CloudExpansion; +import me.clip.placeholderapi.util.Msg; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Unmodifiable; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public final class CommandECloudExpansionPlaceholders extends PlaceholderCommand +{ + + public CommandECloudExpansionPlaceholders() + { + super("placeholders"); + } + + @Override + public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params) + { + if (params.isEmpty()) + { + Msg.msg(sender, + "&cYou must specify the name of the expansion."); + return; + } + + final CloudExpansion expansion = plugin.getExpansionCloud().getCloudExpansion(params.get(0)).orElse(null); + if (expansion == null) + { + Msg.msg(sender, + "&cThere is no expansion with the name: &f" + params.get(0)); + return; + } + + final List placeholders = expansion.getPlaceholders(); + if (placeholders == null || placeholders.isEmpty()) + { + Msg.msg(sender, + "&cThat expansion does not have placeholders listed."); + return; + } + + final List> partitions = Lists.partition(placeholders.stream().sorted().collect(Collectors.toList()), 10); + + Msg.msg(sender, + "&6" + placeholders.size() + "&7 placeholders: &a", + partitions.stream().map(partition -> " " + String.join(", ", partition)).collect(Collectors.joining("\n"))); + + } + + @Override + public void complete(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params, @NotNull final List suggestions) + { + if (params.size() > 1) + { + return; + } + + final Stream names = plugin.getExpansionCloud().getCloudExpansions().values().stream().map(CloudExpansion::getName).map(name -> name.replace(' ', '_')); + suggestByParameter(names, suggestions, params.isEmpty() ? null : params.get(0)); + } + +} diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudRefresh.java b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudRefresh.java new file mode 100644 index 0000000..f67a854 --- /dev/null +++ b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudRefresh.java @@ -0,0 +1,30 @@ +package me.clip.placeholderapi.commands.impl.cloud; + +import me.clip.placeholderapi.PlaceholderAPIPlugin; +import me.clip.placeholderapi.commands.PlaceholderCommand; +import me.clip.placeholderapi.util.Msg; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Unmodifiable; + +import java.util.List; + +public final class CommandECloudRefresh extends PlaceholderCommand +{ + + public CommandECloudRefresh() + { + super("refresh"); + } + + @Override + public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params) + { + plugin.getExpansionCloud().clean(); + plugin.getExpansionCloud().fetch(plugin.getPlaceholderAPIConfig().cloudAllowUnverifiedExpansions()); + + Msg.msg(sender, + "&aThe ECloud Manager has been refreshed!"); + } + +} diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudStatus.java b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudStatus.java new file mode 100644 index 0000000..74bd025 --- /dev/null +++ b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudStatus.java @@ -0,0 +1,43 @@ +package me.clip.placeholderapi.commands.impl.cloud; + +import me.clip.placeholderapi.PlaceholderAPIPlugin; +import me.clip.placeholderapi.commands.PlaceholderCommand; +import me.clip.placeholderapi.expansion.cloud.ExpansionCloudManager; +import me.clip.placeholderapi.util.Msg; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Unmodifiable; + +import java.util.List; + +public final class CommandECloudStatus extends PlaceholderCommand +{ + + public CommandECloudStatus() + { + super("status"); + } + + @Override + public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params) + { + final ExpansionCloudManager manager = plugin.getExpansionCloud(); + + final int updateCount = manager.getCloudUpdateCount(); + final int authorCount = manager.getCloudAuthorCount(); + final int expansionCount = manager.getCloudExpansions().size(); + + final StringBuilder builder = new StringBuilder(); + + builder.append("&bThere are &a").append(expansionCount).append("&b expansions available on the cloud.").append('\n'); + builder.append("&7A total of &f").append(authorCount).append("&7 authors have contributed to the expansion cloud.").append('\n'); + + if (updateCount > 0) + { + builder.append("&eYou have &a").append(updateCount).append("&e expansions installed that have updates available."); + } + + Msg.msg(sender,builder.toString()); + } + +} diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudToggle.java b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudToggle.java new file mode 100644 index 0000000..fdff773 --- /dev/null +++ b/src/main/java/me/clip/placeholderapi/commands/impl/cloud/CommandECloudToggle.java @@ -0,0 +1,62 @@ +package me.clip.placeholderapi.commands.impl.cloud; + +import me.clip.placeholderapi.PlaceholderAPIPlugin; +import me.clip.placeholderapi.commands.PlaceholderCommand; +import me.clip.placeholderapi.util.Msg; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Unmodifiable; + +import java.util.List; + +public final class CommandECloudToggle extends PlaceholderCommand +{ + + public CommandECloudToggle() + { + super("toggle", "enable", "disable"); + } + + + @Override + public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params) + { + final boolean desiredState; + final boolean currentState = plugin.getPlaceholderAPIConfig().isCloudEnabled(); + + switch (alias.toLowerCase()) + { + case "enable": + desiredState = true; + break; + case "disable": + desiredState = false; + break; + default: + desiredState = !currentState; + break; + } + + if (desiredState == currentState) + { + Msg.msg(sender, + "&7The ECloud Manager is already " + (desiredState ? "enabled" : "disabled")); + return; + } + + plugin.getPlaceholderAPIConfig().setCloudEnabled(desiredState); + + if (desiredState) + { + plugin.enableCloud(); + } + else + { + plugin.disableCloud(); + } + + Msg.msg(sender, + "&aThe ECloud Manager has been " + (desiredState ? "enabled" : "disabled")); + } + +} diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandExpansionRegister.java b/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandExpansionRegister.java new file mode 100644 index 0000000..1f7c740 --- /dev/null +++ b/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandExpansionRegister.java @@ -0,0 +1,61 @@ +package me.clip.placeholderapi.commands.impl.local; + +import me.clip.placeholderapi.PlaceholderAPIPlugin; +import me.clip.placeholderapi.commands.PlaceholderCommand; +import me.clip.placeholderapi.expansion.PlaceholderExpansion; +import me.clip.placeholderapi.util.Msg; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Unmodifiable; + +import java.util.Arrays; +import java.util.List; + +public final class CommandExpansionRegister extends PlaceholderCommand +{ + + public CommandExpansionRegister() + { + super("register"); + } + + @Override + public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params) + { + if (params.size() < 1) + { + Msg.msg(sender, + "&cYou must specify the name of an expansion file."); + return; + } + + final PlaceholderExpansion expansion = plugin.getExpansionManager().registerExpansion(params.get(0)); + if (expansion == null) + { + Msg.msg(sender, + "&cFailed to register expansion from &f" + params.get(0)); + return; + } + + Msg.msg(sender, + "&aSuccessfully registered expansion: &f" + expansion.getName()); + } + + @Override + public void complete(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params, @NotNull final List suggestions) + { + if (params.size() > 1) + { + return; + } + + final String[] fileNames = plugin.getExpansionManager().getFolder().list((dir, name) -> name.endsWith(".jar")); + if (fileNames == null || fileNames.length == 0) + { + return; + } + + suggestByParameter(Arrays.stream(fileNames), suggestions, params.isEmpty() ? null : params.get(0)); + } + +} diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandExpansionUnregister.java b/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandExpansionUnregister.java new file mode 100644 index 0000000..6d08056 --- /dev/null +++ b/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandExpansionUnregister.java @@ -0,0 +1,59 @@ +package me.clip.placeholderapi.commands.impl.local; + +import me.clip.placeholderapi.PlaceholderAPI; +import me.clip.placeholderapi.PlaceholderAPIPlugin; +import me.clip.placeholderapi.commands.PlaceholderCommand; +import me.clip.placeholderapi.expansion.PlaceholderExpansion; +import me.clip.placeholderapi.util.Msg; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Unmodifiable; + +import java.util.List; + +public final class CommandExpansionUnregister extends PlaceholderCommand +{ + + public CommandExpansionUnregister() + { + super("unregister"); + } + + @Override + public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params) + { + if (params.isEmpty()) + { + Msg.msg(sender, + "&cYou must specify the name of the expansion."); + return; + } + + final PlaceholderExpansion expansion = plugin.getExpansionManager().getRegisteredExpansion(params.get(0)); + if (expansion == null) + { + Msg.msg(sender, + "&cThere is no expansion loaded with the identifier: &f" + params.get(0)); + return; + } + + + final String message = !PlaceholderAPI.unregisterExpansion(expansion) ? + "&cFailed to unregister expansion: &f" : + "&aSuccessfully unregistered expansion: &f"; + + Msg.msg(sender, message + expansion.getName()); + } + + @Override + public void complete(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params, @NotNull final List suggestions) + { + if (params.size() > 1) + { + return; + } + + suggestByParameter(PlaceholderAPI.getRegisteredIdentifiers().stream(), suggestions, params.isEmpty() ? null : params.get(0)); + } + +} diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandHelp.java b/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandHelp.java new file mode 100644 index 0000000..b4824a6 --- /dev/null +++ b/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandHelp.java @@ -0,0 +1,50 @@ +package me.clip.placeholderapi.commands.impl.local; + +import me.clip.placeholderapi.PlaceholderAPIPlugin; +import me.clip.placeholderapi.commands.PlaceholderCommand; +import me.clip.placeholderapi.util.Msg; +import org.bukkit.command.CommandSender; +import org.bukkit.plugin.PluginDescriptionFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Unmodifiable; + +import java.util.List; + +public final class CommandHelp extends PlaceholderCommand +{ + + public CommandHelp() + { + super("help"); + } + + + @Override + public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params) + { + final PluginDescriptionFile description = plugin.getDescription(); + + Msg.msg(sender, + "&b&lPlaceholderAPI &8- &7Help Menu &8- &7(&f" + description.getVersion() + "&7)", + " ", + "&b/papi", + " &7&oView plugin info/version", + "&b/papi &freload", + " &7&oReload the config of PAPI", + "&b/papi &flist", + " &7&oList active expansions", + "&b/papi &finfo &9", + " &7&oView information for a specific expansion", + "&b/papi &fparse &9 ", + " &7&oParse a message with placeholders", + "&b/papi &fbcparse &9 ", + " &7&oParse a message with placeholders and broadcast it", + "&b/papi &fparserel &9 ", + " &7&oParse a message with relational placeholders", + "&b/papi &fregister &9", + " &7&oRegister an expansion by the name of the file", + "&b/papi &funregister &9", + " &7&oUnregister an expansion by name"); + } + +} diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandInfo.java b/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandInfo.java new file mode 100644 index 0000000..e142305 --- /dev/null +++ b/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandInfo.java @@ -0,0 +1,100 @@ +package me.clip.placeholderapi.commands.impl.local; + +import me.clip.placeholderapi.PlaceholderAPI; +import me.clip.placeholderapi.PlaceholderAPIPlugin; +import me.clip.placeholderapi.commands.PlaceholderCommand; +import me.clip.placeholderapi.expansion.PlaceholderExpansion; +import me.clip.placeholderapi.util.Msg; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Unmodifiable; + +import java.util.List; + +public final class CommandInfo extends PlaceholderCommand +{ + + public CommandInfo() + { + super("info"); + } + + @Override + public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params) + { + if (params.isEmpty()) + { + Msg.msg(sender, + "&cYou must specify the name of the expansion."); + return; + } + + final PlaceholderExpansion expansion = plugin.getExpansionManager().getRegisteredExpansion(params.get(0)); + if (expansion == null) + { + Msg.msg(sender, + "&cThere is no expansion loaded with the identifier: &f" + params.get(0)); + return; + } + + final StringBuilder builder = new StringBuilder(); + + builder.append("&7Placeholder expansion info for: &r") + .append(expansion.getName()) + .append('\n') + .append("&7Status: &r") + .append(expansion.isRegistered() ? "&aRegistered" : "7cNotRegistered") + .append('\n'); + + final String author = expansion.getAuthor(); + if (author != null) + { + builder.append("&7Author: &r") + .append(author) + .append('\n'); + } + + final String version = expansion.getVersion(); + if (version != null) + { + builder.append("&7Version: &r") + .append(version) + .append('\n'); + } + + final String requiredPlugin = expansion.getRequiredPlugin(); + if (requiredPlugin != null) + { + builder.append("&7Requires plugin: &r") + .append(requiredPlugin) + .append('\n'); + } + + final List placeholders = expansion.getPlaceholders(); + if (placeholders != null && !placeholders.isEmpty()) + { + builder.append("&8&m-- &7Placeholders &8&m--&r") + .append('\n'); + + for (final String placeholder : placeholders) + { + builder.append(placeholder) + .append('\n'); + } + } + + Msg.msg(sender, builder.toString()); + } + + @Override + public void complete(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params, @NotNull final List suggestions) + { + if (params.size() > 1) + { + return; + } + + suggestByParameter(PlaceholderAPI.getRegisteredIdentifiers().stream(), suggestions, params.isEmpty() ? null : params.get(0)); + } + +} diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandList.java b/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandList.java new file mode 100644 index 0000000..f5c1dc7 --- /dev/null +++ b/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandList.java @@ -0,0 +1,42 @@ +package me.clip.placeholderapi.commands.impl.local; + +import com.google.common.collect.Lists; +import me.clip.placeholderapi.PlaceholderAPI; +import me.clip.placeholderapi.PlaceholderAPIPlugin; +import me.clip.placeholderapi.commands.PlaceholderCommand; +import me.clip.placeholderapi.util.Msg; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Unmodifiable; + +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +public final class CommandList extends PlaceholderCommand +{ + + public CommandList() + { + super("list"); + } + + + @Override + public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params) + { + final Set identifiers = PlaceholderAPI.getRegisteredIdentifiers(); + if (identifiers.isEmpty()) + { + Msg.msg(sender, "&6There are no placeholder hooks active!"); + return; + } + + final List> partitions = Lists.partition(identifiers.stream().sorted().collect(Collectors.toList()), 10); + + Msg.msg(sender, + "&6" + identifiers.size() + "&7 placeholder hook(s) active: &a", + partitions.stream().map(partition -> " " + String.join(", ", partition)).collect(Collectors.joining("\n"))); + } + +} diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandParse.java b/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandParse.java new file mode 100644 index 0000000..5190a26 --- /dev/null +++ b/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandParse.java @@ -0,0 +1,185 @@ +package me.clip.placeholderapi.commands.impl.local; + +import me.clip.placeholderapi.PlaceholderAPI; +import me.clip.placeholderapi.PlaceholderAPIPlugin; +import me.clip.placeholderapi.commands.PlaceholderCommand; +import me.clip.placeholderapi.util.Msg; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Unmodifiable; + +import java.util.List; +import java.util.stream.Stream; + +public final class CommandParse extends PlaceholderCommand +{ + + public CommandParse() + { + super("parse", "bcparse", "parserel", "cmdparse"); + } + + + @Override + public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params) + { + switch (alias.toLowerCase()) + { + case "parserel": + evaluateParseRelation(sender, params); + break; + case "parse": + evaluateParseSingular(sender, params, false, false); + break; + case "bcparse": + evaluateParseSingular(sender, params, true, false); + break; + case "cmdparse": + evaluateParseSingular(sender, params, false, true); + break; + } + } + + @Override + public void complete(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params, @NotNull final List suggestions) + { + switch (alias.toLowerCase()) + { + case "parserel": + completeParseRelation(params, suggestions); + break; + case "parse": + case "bcparse": + completeParseSingular(sender, params, suggestions); + break; + } + } + + + private void evaluateParseSingular(@NotNull final CommandSender sender, @NotNull @Unmodifiable final List params, final boolean broadcast, final boolean command) + { + if (params.size() < 2) + { + Msg.msg(sender, "&cYou must supply a target, and a message: &b/papi " + (broadcast ? "bcparse" : "parse") + " &7{target} &a{message}"); + return; + } + + @NotNull final OfflinePlayer player; + + if ("me".equalsIgnoreCase(params.get(0))) + { + if (!(sender instanceof Player)) + { + Msg.msg(sender, "&cYou must be a player to use &7me&c as a target!"); + return; + } + + player = ((Player) sender); + } + else + { + final OfflinePlayer target = resolvePlayer(params.get(0)); + if (target == null) + { + Msg.msg(sender, "&cFailed to find player: &7" + params.get(0)); + return; + } + + player = target; + } + + final String message = PlaceholderAPI.setPlaceholders(player, String.join(" ", params.subList(1, params.size()))); + + if (command) + { + Bukkit.dispatchCommand(sender, message); + return; + } + + if (broadcast) + { + Msg.broadcast(message); + } + else + { + if (!(sender instanceof Player)) + { + Msg.msg(sender, message); + } + else + { + sender.spigot().sendMessage(TextComponent.fromLegacyText(message)); + } + } + } + + private void evaluateParseRelation(@NotNull final CommandSender sender, @NotNull @Unmodifiable final List params) + { + if (params.size() < 3) + { + Msg.msg(sender, "&cYou must supply two targets, and a message: &b/papi parserel &7{target one} {target two} &a{message}"); + return; + } + + final OfflinePlayer targetOne = resolvePlayer(params.get(0)); + if (targetOne == null || !targetOne.isOnline()) + { + Msg.msg(sender, "&cFailed to find player: &7" + params.get(0)); + return; + } + + final OfflinePlayer targetTwo = resolvePlayer(params.get(1)); + if (targetTwo == null || !targetTwo.isOnline()) + { + Msg.msg(sender, "&cFailed to find player: &7" + params.get(1)); + return; + } + + final String message = PlaceholderAPI.setRelationalPlaceholders(((Player) targetOne), ((Player) targetTwo), String.join(" ", params.subList(2, params.size()))); + Msg.msg(sender, message); + } + + + private void completeParseSingular(@NotNull final CommandSender sender, @NotNull @Unmodifiable final List params, @NotNull final List suggestions) + { + if (sender instanceof Player && (params.isEmpty() || (params.size() == 1 && params.get(0).toLowerCase().startsWith("m")))) + { + suggestions.add("me"); + } + + final Stream names = Bukkit.getOnlinePlayers().stream().map(Player::getName); + suggestByParameter(names, suggestions, params.isEmpty() ? null : params.get(0)); + } + + private void completeParseRelation(@NotNull @Unmodifiable final List params, @NotNull final List suggestions) + { + if (params.size() > 2) + { + return; + } + + final Stream names = Bukkit.getOnlinePlayers().stream().map(Player::getName); + suggestByParameter(names, suggestions, params.isEmpty() ? null : params.get(params.size() - 1)); + } + + + @Nullable + private OfflinePlayer resolvePlayer(@NotNull final String name) + { + OfflinePlayer target = Bukkit.getPlayer(name); + + if (target == null) + { + target = Bukkit.getOfflinePlayer(name); // this is probably not a great idea. + } + + return target.hasPlayedBefore() ? target : null; + + } + +} diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandReload.java b/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandReload.java new file mode 100644 index 0000000..90277ea --- /dev/null +++ b/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandReload.java @@ -0,0 +1,27 @@ +package me.clip.placeholderapi.commands.impl.local; + +import me.clip.placeholderapi.PlaceholderAPIPlugin; +import me.clip.placeholderapi.commands.PlaceholderCommand; +import me.clip.placeholderapi.util.Msg; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Unmodifiable; + +import java.util.List; + +public final class CommandReload extends PlaceholderCommand +{ + + public CommandReload() + { + super("reload"); + } + + @Override + public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params) + { + plugin.reloadConf(sender); + Msg.msg(sender, "&fPlaceholder&7API &bconfiguration reloaded!"); + } + +} diff --git a/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandVersion.java b/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandVersion.java new file mode 100644 index 0000000..2e46fff --- /dev/null +++ b/src/main/java/me/clip/placeholderapi/commands/impl/local/CommandVersion.java @@ -0,0 +1,34 @@ +package me.clip.placeholderapi.commands.impl.local; + +import me.clip.placeholderapi.PlaceholderAPIPlugin; +import me.clip.placeholderapi.commands.PlaceholderCommand; +import me.clip.placeholderapi.util.Msg; +import org.bukkit.command.CommandSender; +import org.bukkit.plugin.PluginDescriptionFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Unmodifiable; + +import java.util.List; + +public final class CommandVersion extends PlaceholderCommand +{ + + public CommandVersion() + { + super("version"); + } + + + @Override + public void evaluate(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List params) + { + final PluginDescriptionFile description = plugin.getDescription(); + + Msg.msg(sender, + "&b&lPlaceholderAPI &e(&f" + description.getVersion() + "&e)", + "&fAuthors&8: &6" + description.getAuthors(), + "&fPAPI Commands&8: &b/papi &7help", + "&fECloud Commands&8: &b/papi &7ecloud"); + } + +} diff --git a/src/main/java/me/clip/placeholderapi/expansion/ExpansionManager.java b/src/main/java/me/clip/placeholderapi/expansion/ExpansionManager.java index 9f827e6..63358ab 100644 --- a/src/main/java/me/clip/placeholderapi/expansion/ExpansionManager.java +++ b/src/main/java/me/clip/placeholderapi/expansion/ExpansionManager.java @@ -57,6 +57,12 @@ public final class ExpansionManager } + @NotNull + public File getFolder() + { + return folder; + } + public void initializeExpansions() { plugin.getLogger().info("Placeholder expansion registration initializing..."); @@ -166,9 +172,9 @@ public final class ExpansionManager ((Taskable) expansion).start(); } - if (plugin.getExpansionCloud() != null) + if (plugin.getPlaceholderAPIConfig().isCloudEnabled()) { - final CloudExpansion cloudExpansion = plugin.getExpansionCloud().getCloudExpansion(expansion.getIdentifier()); + final CloudExpansion cloudExpansion = plugin.getExpansionCloud().getCloudExpansion(expansion.getIdentifier()).orElse(null); if (cloudExpansion != null) { diff --git a/src/main/java/me/clip/placeholderapi/expansion/cloud/ExpansionCloudManager.java b/src/main/java/me/clip/placeholderapi/expansion/cloud/ExpansionCloudManager.java index 78e6cc3..86fa45c 100644 --- a/src/main/java/me/clip/placeholderapi/expansion/cloud/ExpansionCloudManager.java +++ b/src/main/java/me/clip/placeholderapi/expansion/cloud/ExpansionCloudManager.java @@ -20,301 +20,264 @@ */ package me.clip.placeholderapi.expansion.cloud; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import me.clip.placeholderapi.PlaceholderAPI; import me.clip.placeholderapi.PlaceholderAPIPlugin; import me.clip.placeholderapi.expansion.PlaceholderExpansion; -import me.clip.placeholderapi.util.Msg; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Unmodifiable; -import java.io.*; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; import java.net.URL; -import java.net.URLConnection; -import java.util.*; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.TreeMap; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionException; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Function; +import java.util.logging.Level; import java.util.stream.Collectors; -import java.util.stream.IntStream; -public class ExpansionCloudManager { +public final class ExpansionCloudManager +{ + + private static final String API_URL = "http://api.extendedclip.com/v2/"; + private static final Gson GSON = new Gson(); + + + @NotNull + private final File folder; + @NotNull + private final PlaceholderAPIPlugin plugin; + + + @NotNull + private final Map expansions = new TreeMap<>(); + @NotNull + private final Map> downloading = new HashMap<>(); + + + public ExpansionCloudManager(@NotNull final PlaceholderAPIPlugin plugin) + { + this.plugin = plugin; + this.folder = new File(plugin.getDataFolder(), "expansions"); + + if (!this.folder.exists() && !this.folder.mkdirs()) + { + plugin.getLogger().severe("Failed to create expansions directory!"); + } + } + + + @NotNull + @Unmodifiable + public Map getCloudExpansions() + { + return ImmutableMap.copyOf(expansions); + } + + @NotNull + @Unmodifiable + public Set getCloudAuthorNames() + { + return ImmutableSet.copyOf(expansions.values().stream().map(CloudExpansion::getAuthor).collect(Collectors.toSet())); + } + + public int getCloudAuthorCount() + { + return expansions.values() + .stream() + .collect(Collectors.groupingBy(CloudExpansion::getAuthor, Collectors.counting())) + .size(); + } + + @NotNull + public Optional getCloudExpansion(String name) + { + return expansions.values() + .stream() + .filter(ex -> ex.getName().replace(' ', '_').equalsIgnoreCase(name.replace(' ', '_'))) + .findFirst(); + } + + + public int getCloudUpdateCount() + { + return ((int) PlaceholderAPI.getExpansions() + .stream() + .filter(ex -> getCloudExpansion(ex.getName()).map(CloudExpansion::shouldUpdate).isPresent()) + .count()); + } + + @NotNull + @Unmodifiable + public Map getAllByAuthor(@NotNull final String author) + { + if (expansions.isEmpty()) + { + return Collections.emptyMap(); + } + + final AtomicInteger index = new AtomicInteger(); + + return expansions.values() + .stream() + .filter(expansion -> author.equalsIgnoreCase(expansion.getAuthor())) + .collect(Collectors.toMap(($) -> index.incrementAndGet(), Function.identity())); + } + + @NotNull + @Unmodifiable + public Map getAllInstalled() + { + if (expansions.isEmpty()) + { + return Collections.emptyMap(); + } + + final AtomicInteger index = new AtomicInteger(); + + return expansions.values() + .stream() + .filter(CloudExpansion::hasExpansion) + .collect(Collectors.toMap(($) -> index.incrementAndGet(), Function.identity())); + } + + + public void clean() + { + expansions.clear(); + + downloading.values().forEach(future -> future.cancel(true)); + downloading.clear(); + } + + public void fetch(boolean allowUnverified) + { + plugin.getLogger().info("Fetching available expansion information..."); + + plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> { + final Map data = new HashMap<>(); + + try (BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(API_URL).openStream()))) + { + data.putAll(GSON.fromJson(reader, new TypeToken>() + { + }.getType())); + } + catch (Exception ex) + { + if (plugin.getPlaceholderAPIConfig().isDebugMode()) + { + ex.printStackTrace(); + } + else + { + plugin.getLogger().warning("Unable to fetch expansions!\nThere was an error with the server host connecting to the PlaceholderAPI eCloud (https://api.extendedclip.com/v2/)"); + } + } + + final List unsorted = new ArrayList<>(); + + data.forEach((name, cexp) -> { + if ((allowUnverified || cexp.isVerified()) && cexp.getLatestVersion() != null && cexp.getVersion(cexp.getLatestVersion()) != null) + { + cexp.setName(name); + + PlaceholderExpansion ex = plugin.getExpansionManager().getRegisteredExpansion(cexp.getName()); + + if (ex != null && ex.isRegistered()) + { + cexp.setHasExpansion(true); + if (!ex.getVersion().equals(cexp.getLatestVersion())) + { + cexp.setShouldUpdate(true); + } + } + + unsorted.add(cexp); + } + }); + + unsorted.sort(Comparator.comparing(CloudExpansion::getLastUpdate).reversed()); + + int count = 0; + for (CloudExpansion e : unsorted) + { + expansions.put(count++, e); + } + + plugin.getLogger().info(count + " placeholder expansions are available on the cloud."); + + long updates = getCloudUpdateCount(); + + if (updates > 0) + { + plugin.getLogger().info(updates + " installed expansions have updates available."); + } + }); + } + + + public boolean isDownloading(@NotNull final CloudExpansion expansion) + { + return downloading.containsKey(expansion); + } + + + @NotNull + public CompletableFuture<@NotNull File> downloadExpansion(@NotNull final CloudExpansion expansion, @NotNull final CloudExpansion.Version version) + { + final CompletableFuture previous = downloading.get(expansion); + if (previous != null) + { + return previous; + } + + final File file = new File(folder, "Expansion-" + expansion.getName() + ".jar"); + + final CompletableFuture download = CompletableFuture.supplyAsync(() -> { + + try (final ReadableByteChannel source = Channels.newChannel(new URL(version.getUrl()).openStream()); final FileOutputStream target = new FileOutputStream(file)) + { + target.getChannel().transferFrom(source, 0, Long.MAX_VALUE); + } + catch (final IOException ex) + { + throw new CompletionException(ex); + } + + return file; + }); + + download.whenCompleteAsync((value, exception) -> { + downloading.remove(expansion); + + if (exception != null) + { + plugin.getLogger().log(Level.SEVERE, "failed to download " + expansion.getName() + ":" + version.getVersion(), exception); + } + }); + + downloading.put(expansion, download); + + return download; + } - private static final String API_URL = "http://api.extendedclip.com/v2/"; - private static final Gson GSON = new Gson(); - - - private final PlaceholderAPIPlugin plugin; - private final File expansionsDir; - - private final List downloading = new ArrayList<>(); - private final Map remote = new TreeMap<>(); - - - public ExpansionCloudManager(PlaceholderAPIPlugin plugin) { - this.plugin = plugin; - - expansionsDir = new File(plugin.getDataFolder(), "expansions"); - - final boolean result = expansionsDir.mkdirs(); - if (result) { - plugin.getLogger().info("Created Expansions Directory"); - } - - } - - - public void clean() { - remote.clear(); - downloading.clear(); - } - - - public Map getCloudExpansions() { - return remote; - } - - public CloudExpansion getCloudExpansion(String name) { - return remote.values() - .stream() - .filter(ex -> ex.getName().equalsIgnoreCase(name)) - .findFirst() - .orElse(null); - } - - - public int getCloudAuthorCount() { - return remote.values() - .stream() - .collect(Collectors.groupingBy(CloudExpansion::getAuthor, Collectors.counting())) - .size(); - } - - public int getToUpdateCount() { - return ((int) PlaceholderAPI.getExpansions() - .stream() - .filter(ex -> getCloudExpansion(ex.getName()) != null && getCloudExpansion(ex.getName()).shouldUpdate()) - .count()); - } - - - public Map getAllByAuthor(String author) { - if (remote.isEmpty()) return new HashMap<>(); - - Map byAuthor = new TreeMap<>(); - - for (CloudExpansion ex : remote.values()) { - if (!ex.getAuthor().equalsIgnoreCase(author)) continue; - - byAuthor.put(byAuthor.size(), ex); - } - - return byAuthor; - } - - public Map getAllInstalled() { - if (remote.isEmpty()) return new HashMap<>(); - - Map has = new TreeMap<>(); - - for (CloudExpansion ex : remote.values()) { - if (!ex.hasExpansion()) continue; - - has.put(has.size(), ex); - } - - return has; - } - - - public int getPagesAvailable(Map map, int amount) { - if (map == null) { - return 0; - } - - int pages = map.size() > 0 ? 1 : 0; - if (pages == 0) { - return pages; - } - - if (map.size() > amount) { - pages = map.size() / amount; - if (map.size() % amount > 0) { - pages++; - } - } - - return pages; - } - - public Map getPage(Map map, int page, int size) { - if (map == null || map.size() == 0 || page > getPagesAvailable(map, size)) { - return new HashMap<>(); - } - - int end = size * page; - int start = end - size; - - Map ex = new TreeMap<>(); - IntStream.range(start, end).forEach(n -> ex.put(n, map.get(n))); - - return ex; - } - - - public void fetch(boolean allowUnverified) { - plugin.getLogger().info("Fetching available expansion information..."); - - plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> { - final Map data = new HashMap<>(); - - try (BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(API_URL).openStream()))) { - data.putAll(GSON.fromJson(reader, new TypeToken>() { - }.getType())); - } catch (Exception ex) { - if (plugin.getPlaceholderAPIConfig().isDebugMode()) { - ex.printStackTrace(); - } else { - plugin.getLogger().warning("Unable to fetch expansions!\nThere was an error with the server host connecting to the PlaceholderAPI eCloud (https://api.extendedclip.com/v2/)"); - } - } - - final List unsorted = new ArrayList<>(); - - data.forEach((name, cexp) -> { - if ((allowUnverified || cexp.isVerified()) && cexp.getLatestVersion() != null && cexp.getVersion(cexp.getLatestVersion()) != null) { - cexp.setName(name); - - PlaceholderExpansion ex = plugin.getExpansionManager().getRegisteredExpansion(cexp.getName()); - - if (ex != null && ex.isRegistered()) { - cexp.setHasExpansion(true); - if (!ex.getVersion().equals(cexp.getLatestVersion())) { - cexp.setShouldUpdate(true); - } - } - - unsorted.add(cexp); - } - }); - - unsorted.sort(Comparator.comparing(CloudExpansion::getLastUpdate).reversed()); - - int count = 0; - for (CloudExpansion e : unsorted) { - remote.put(count++, e); - } - - plugin.getLogger().info(count + " placeholder expansions are available on the cloud."); - - long updates = getToUpdateCount(); - - if (updates > 0) { - plugin.getLogger().info(updates + " installed expansions have updates available."); - } - }); - } - - - public boolean isDownloading(String expansion) { - return downloading.contains(expansion); - } - - private void download(URL url, String name) throws IOException { - InputStream is = null; - - FileOutputStream fos = null; - - try { - URLConnection urlConn = url.openConnection(); - - is = urlConn.getInputStream(); - - fos = new FileOutputStream( - expansionsDir.getAbsolutePath() + File.separator + "Expansion-" + name + ".jar"); - - byte[] buffer = new byte[is.available()]; - - int l; - - while ((l = is.read(buffer)) > 0) { - fos.write(buffer, 0, l); - } - } finally { - try { - if (is != null) { - is.close(); - } - } finally { - if (fos != null) { - fos.close(); - } - } - } - } - - - public void downloadExpansion(final String player, final CloudExpansion ex) { - downloadExpansion(player, ex, ex.getLatestVersion()); - } - - public void downloadExpansion(final String player, final CloudExpansion ex, final String version) { - if (downloading.contains(ex.getName())) { - return; - } - - final CloudExpansion.Version ver = ex.getVersions() - .stream() - .filter(v -> v.getVersion().equals(version)) - .findFirst() - .orElse(null); - - if (ver == null) { - return; - } - - downloading.add(ex.getName()); - - plugin.getLogger().info("Attempting download of expansion: " + ex.getName() + (player != null ? " by user: " + player : "") + " from url: " + ver.getUrl()); - - Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { - - try { - download(new URL(ver.getUrl()), ex.getName()); - - plugin.getLogger().info("Download of expansion: " + ex.getName() + " complete!"); - - } catch (Exception e) { - plugin.getLogger() - .warning("Failed to download expansion: " + ex.getName() + " from: " + ver.getUrl()); - - Bukkit.getScheduler().runTask(plugin, () -> { - - downloading.remove(ex.getName()); - - if (player != null) { - Player p = Bukkit.getPlayer(player); - - if (p != null) { - Msg.msg(p, "&cThere was a problem downloading expansion: &f" + ex.getName()); - } - } - }); - - return; - } - - Bukkit.getScheduler().runTask(plugin, () -> { - downloading.remove(ex.getName()); - - if (player != null) { - Player p = Bukkit.getPlayer(player); - - if (p != null) { - Msg.msg(p, "&aExpansion &f" + ex.getName() + " &adownload complete!"); - Msg.msg(p, "&aMake sure to run &f/papi reload &ato enable it!"); - } - } - }); - - }); - } } diff --git a/src/main/java/me/clip/placeholderapi/listeners/PlaceholderListener.java b/src/main/java/me/clip/placeholderapi/listeners/PlaceholderListener.java index c6c06b5..875c5a1 100644 --- a/src/main/java/me/clip/placeholderapi/listeners/PlaceholderListener.java +++ b/src/main/java/me/clip/placeholderapi/listeners/PlaceholderListener.java @@ -65,11 +65,8 @@ public class PlaceholderListener implements Listener { ((Cacheable) event.getExpansion()).clear(); } - if (plugin.getExpansionCloud() != null) { - - CloudExpansion ex = plugin.getExpansionCloud() - .getCloudExpansion(event.getExpansion().getName()); - + if (plugin.getPlaceholderAPIConfig().isCloudEnabled()) { + CloudExpansion ex = plugin.getExpansionCloud().getCloudExpansion(event.getExpansion().getName()).orElse(null); if (ex != null) { ex.setHasExpansion(false); ex.setShouldUpdate(false); diff --git a/src/main/java/me/clip/placeholderapi/util/Constants.java b/src/main/java/me/clip/placeholderapi/util/Constants.java deleted file mode 100644 index d911793..0000000 --- a/src/main/java/me/clip/placeholderapi/util/Constants.java +++ /dev/null @@ -1,9 +0,0 @@ -package me.clip.placeholderapi.util; - -public class Constants { - public static final String ADMIN_PERMISSION = "placeholderapi.admin"; - public static final String ECLOUD_PERMISSION = "placeholderapi.ecloud"; - public static final String INFO_PERMISSION = "placeholderapi.info"; - public static final String LIST_PERMISSION = "placeholderapi.list"; - public static final String RELOAD_PERMISSION = "placeholderapi.reload"; -} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index d4031ef..86d0c7f 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,42 +1,98 @@ -name: ${project.name} -main: me.clip.placeholderapi.PlaceholderAPIPlugin -version: ${project.version} -api-version: '1.13' -authors: [extended_clip, Glare] -description: ${project.description} -permissions: - placeholderapi.*: - description: ability to use all commands - children: - placeholderapi.admin: true - placeholderapi.admin: - description: ability to use all commands - children: - placeholderapi.list: true - placeholderapi.reload: true - placeholderapi.ecloud: true - placeholderapi.parse: true - placeholderapi.register: true - placeholderapi.updatenotify: true - placeholderapi.list: - description: ability to use the list command - default: op - placeholderapi.reload: - description: ability to use the reload command - default: op - placeholderapi.parse: - description: ability to use parse command - default: op - placeholderapi.register: - description: ability to register or unregister placeholder expansions - default: op - placeholderapi.ecloud: - description: allows the usage of ecloud commands - default: op - placeholderapi.updatenotify: - description: notifies you when there is a PAPI update - default: op +name: "${project.name}" +main: "me.clip.placeholderapi.PlaceholderAPIPlugin" + +version: "${project.version}" +authors: ["extended_clip", "Glare"] + +api-version: "1.13" +description: "${project.description}" + commands: - placeholderapi: - description: PlaceholderAPI command - aliases: [papi] + placeholderapi: + description: "PlaceholderAPI Command" + aliases: ["papi"] + +permissions: + placeholderapi.*: + description: "ability to use all papi commands" + children: + placeholderapi.admin: true + placeholderapi.ecloud.*: true + placeholderapi.admin: + description: "ability to use all papi commands" + children: + placeholderapi.help: true + placeholderapi.info: true + placeholderapi.list: true + placeholderapi.parse: true + placeholderapi.reload: true + placeholderapi.version: true + placeholderapi.register: true + placeholderapi.unregister: true + placeholderapi.updatenotify: true + placeholderapi.ecloud.*: + description: "ability to use all papi ecloud commands" + children: + placeholderapi.ecloud: true + placeholderapi.ecloud.info: true + placeholderapi.ecloud.list: true + placeholderapi.ecloud.clear: true + placeholderapi.ecloud.toggle: true + placeholderapi.ecloud.status: true + placeholderapi.ecloud.refresh: true + placeholderapi.ecloud.download: true + placeholderapi.ecloud.placeholders: true + placeholderapi.help: + default: "op" + description: "allows you to view the list of papi commands" + placeholderapi.info: + default: "op" + description: "allows you to view expansion information" + placeholderapi.list: + default: "op" + description: "allows you to list active expansions" + placeholderapi.ecloud: + default: "op" + description: "allows you to access papi ecloud" + placeholderapi.parse: + default: "op" + description: "allows you to parse placeholders" + placeholderapi.reload: + default: "op" + description: "allows you to reload papi and its configuration" + placeholderapi.version: + default: "op" + description: "allows you to view the version of papi installed" + placeholderapi.register: + default: "op" + description: "allows you to register expansions" + placeholderapi.unregister: + default: "op" + description: "allows you to unregister expansions" + placeholderapi.updatenotify: + default: "op" + description: "notifies you when there is a PAPI update" + placeholderapi.ecloud.info: + default: "op" + description: "allows you to view cloud expansion information" + placeholderapi.ecloud.list: + default: "op" + description: "allows you to list cloud expansions" + placeholderapi.ecloud.clear: + default: "op" + description: "allows you to clear the local cloud expansion cache" + placeholderapi.ecloud.toggle: + default: "op" + description: "allows you to toggle/enable/disable the cloud manager" + placeholderapi.ecloud.status: + default: "op" + description: "allows you to view the status of cloud expansions" + placeholderapi.ecloud.refresh: + default: "op" + description: "allows you to refresh the local cloud expansion cache" + placeholderapi.ecloud.download: + default: "op" + description: "allows you to download an expansion from the cloud" + placeholderapi.ecloud.placeholders: + default: "op" + description: "allows you to view the placeholders of a cloud expansion" \ No newline at end of file