mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2026-02-06 12:17:13 +01:00
Changed command system (#304)
* Save Cacheable expansions data on shutdown * Prepare for 1.16 * 1.16.1 is out apparently * Further fixes, still not done * Inline JSONMessages & fix for 1.16 * Done :O * Done for real now, (hopefully) * Changed to static instead of DI for plugin instance * Cleanup * Modified tab completions. Removed extra command. * Apparently this is needed * Started cleaning stuff up basically just pushing so I can continue on laptop * did more cleaning, probs like half way done * more cleaning. reverted back to a min arg system somewhat similar to what frosty had, but less boilerplate. * Started debugging and fixing runtime/compile errors * Fixed bugs, still needs thorough testing * Re-enable metrics * relocated stuff again * - Remove json message relocation - uncomment other relocations - reformat pom - remove useless scope declaration - Fix metrics constructor - Switch commands to use inline json message Co-authored-by: iGabyTM <contactgabytm@gmail.com> Co-authored-by: darbyjack <admin@glaremasters.me> Co-authored-by: PiggyPiglet <noreply@piggypiglet.me>
This commit is contained in:
82
src/main/java/me/clip/placeholderapi/commands/Command.java
Normal file
82
src/main/java/me/clip/placeholderapi/commands/Command.java
Normal file
@@ -0,0 +1,82 @@
|
||||
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<String> 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 + " <required args> [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<String> getPermissions() {
|
||||
return permissions;
|
||||
}
|
||||
|
||||
public abstract void execute(@NotNull final CommandSender sender, @NotNull final String[] args);
|
||||
|
||||
@NotNull
|
||||
public List<String> handleCompletion(@NotNull final CommandSender sender, @NotNull final String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
private static class Options {
|
||||
private final String usage;
|
||||
private final int minimumArguments;
|
||||
private final String[] permissions;
|
||||
|
||||
private Options(@Nullable final String usage, final int minimumArguments,
|
||||
@Nullable final String[] permissions) {
|
||||
this.usage = usage;
|
||||
this.minimumArguments = minimumArguments;
|
||||
this.permissions = permissions;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
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.InfoCommand;
|
||||
import me.clip.placeholderapi.commands.command.ecloud.ListCommand;
|
||||
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<Command> COMMANDS = Lists.newArrayList(
|
||||
new ClearCommand(),
|
||||
new DownloadCommand(),
|
||||
new InfoCommand(),
|
||||
new ListCommand(),
|
||||
new PlaceholdersCommand(),
|
||||
new RefreshCommand(),
|
||||
new StatusCommand(),
|
||||
new VersionInfoCommand(),
|
||||
new EcloudCommand(),
|
||||
new BcParseCommand(),
|
||||
new ParseCommand(),
|
||||
new ParseRelCommand(),
|
||||
new DisableEcloudCommand(),
|
||||
new EnableCloudCommand(),
|
||||
new HelpCommand(),
|
||||
new me.clip.placeholderapi.commands.command.InfoCommand(),
|
||||
new me.clip.placeholderapi.commands.command.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;
|
||||
});
|
||||
}
|
||||
|
||||
private static final Pattern SPACE_PATTERN = Pattern.compile(" ");
|
||||
|
||||
static {
|
||||
Objects.requireNonNull(PlaceholderAPIPlugin.getInstance().getCommand("placeholderapi"))
|
||||
.setTabCompleter(new CompletionHandler(COMMANDS));
|
||||
}
|
||||
|
||||
@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<Command> 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
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<Command> commands;
|
||||
|
||||
CompletionHandler(@NotNull final List<Command> commands) {
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
// it makes me physically cringe trying to understand why bukkit uses a list instead of a set for this
|
||||
@NotNull
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull final CommandSender sender, @NotNull final org.bukkit.command.Command bukkitCommand,
|
||||
@NotNull final String name, @NotNull final String[] args) {
|
||||
final String joined = String.join(" ", args).toLowerCase();
|
||||
final Optional<Command> optional = commands.stream()
|
||||
.filter(command -> joined.startsWith(command.getMatch()))
|
||||
.findAny();
|
||||
|
||||
return optional
|
||||
.map(command -> command.handleCompletion(sender, CommandHandler.splitArguments(joined, command.getMatch())))
|
||||
.orElse(Collections.emptyList());
|
||||
}
|
||||
}
|
||||
@@ -1,469 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (C) 2019 Ryan McCarthy
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package me.clip.placeholderapi.commands;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import me.clip.placeholderapi.expansion.cloud.CloudExpansion;
|
||||
import me.rayzr522.jsonmessage.JSONMessage;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static me.clip.placeholderapi.util.Msg.color;
|
||||
import static me.clip.placeholderapi.util.Msg.msg;
|
||||
|
||||
public class ExpansionCloudCommands implements CommandExecutor {
|
||||
|
||||
private final PlaceholderAPIPlugin plugin;
|
||||
|
||||
public ExpansionCloudCommands(PlaceholderAPIPlugin instance) {
|
||||
plugin = instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender s, Command c, String label, String[] args) {
|
||||
|
||||
if (args.length == 1) {
|
||||
msg(s, "&bExpansion cloud commands",
|
||||
" ",
|
||||
"&b/papi ecloud status",
|
||||
"&fView status of the ecloud",
|
||||
"&b/papi ecloud list <all/author> (page)",
|
||||
"&fList all/author specific available expansions",
|
||||
"&b/papi ecloud info <expansion name>",
|
||||
"&fView information about a specific expansion available on the cloud",
|
||||
"&b/papi ecloud versioninfo <expansion name> <version>",
|
||||
"&fView information about a specific version of an expansion",
|
||||
"&b/papi ecloud placeholders <expansion name>",
|
||||
"&fView placeholders for an expansion",
|
||||
"&b/papi ecloud download <expansion name> (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 true;
|
||||
}
|
||||
|
||||
if (args[1].equalsIgnoreCase("refresh") || args[1].equalsIgnoreCase("update") || args[1]
|
||||
.equalsIgnoreCase("fetch")) {
|
||||
msg(s, "&aRefresh task started. Use &f/papi ecloud list all &ain a few!!");
|
||||
plugin.getExpansionCloud().clean();
|
||||
plugin.getExpansionCloud().fetch(plugin.getPlaceholderAPIConfig().cloudAllowUnverifiedExpansions());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (plugin.getExpansionCloud().getCloudExpansions().isEmpty()) {
|
||||
msg(s, "&7No cloud expansions are available at this time.");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[1].equalsIgnoreCase("clear")) {
|
||||
msg(s, "&aThe cache has been cleared!!");
|
||||
plugin.getExpansionCloud().clean();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[1].equalsIgnoreCase("status")) {
|
||||
msg(s, "&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(s, "&eYou have &f" + plugin.getExpansionCloud().getToUpdateCount()
|
||||
+ " &eexpansions installed that have updates available.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[1].equalsIgnoreCase("info")) {
|
||||
if (args.length < 3) {
|
||||
msg(s, "&cAn expansion name must be specified!");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
CloudExpansion expansion = plugin.getExpansionCloud().getCloudExpansion(args[2]);
|
||||
|
||||
if (expansion == null) {
|
||||
msg(s, "&cNo expansion found by the name: &f" + args[2]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(s instanceof Player)) {
|
||||
msg(s,
|
||||
(expansion.shouldUpdate() ? "&e" : "") + expansion.getName() + " &8&m-- &r" + expansion
|
||||
.getVersion().getUrl());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Player p = (Player) s;
|
||||
|
||||
msg(s, "&bExpansion&7: &f" + expansion.getName(),
|
||||
"&bAuthor: &f" + expansion.getAuthor(),
|
||||
"&bVerified: &f" + expansion.isVerified()
|
||||
);
|
||||
|
||||
// latest version
|
||||
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
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[1].equalsIgnoreCase("versioninfo")) {
|
||||
if (args.length < 4) {
|
||||
msg(s, "&cAn expansion name and version must be specified!");
|
||||
return true;
|
||||
}
|
||||
|
||||
CloudExpansion expansion = plugin.getExpansionCloud().getCloudExpansion(args[2]);
|
||||
if (expansion == null) {
|
||||
msg(s, "&cNo expansion found by the name: &f" + args[2]);
|
||||
return true;
|
||||
}
|
||||
|
||||
CloudExpansion.Version version = expansion.getVersion(args[3]);
|
||||
if (version == null) {
|
||||
msg(s, "&cThe version specified does not exist for expansion: &f" + expansion.getName());
|
||||
return true;
|
||||
}
|
||||
|
||||
msg(s, "&bExpansion: " + (expansion.shouldUpdate() ? "&e" : "&f") + expansion.getName(),
|
||||
"&bVersion: &f" + version.getVersion(),
|
||||
"&bVersion info: &f" + version.getReleaseNotes());
|
||||
|
||||
if (!(s instanceof Player)) {
|
||||
msg(s, "&bDownload url: " + version.getUrl());
|
||||
return true;
|
||||
}
|
||||
|
||||
Player p = (Player) s;
|
||||
|
||||
JSONMessage download = JSONMessage.create(color("&7Click to download this version"));
|
||||
download.suggestCommand(
|
||||
"/papi ecloud download " + expansion.getName() + " " + version.getVersion());
|
||||
download.send(p);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[1].equalsIgnoreCase("placeholders")) {
|
||||
if (args.length < 3) {
|
||||
msg(s, "&cAn expansion name must be specified!");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
CloudExpansion expansion = plugin.getExpansionCloud().getCloudExpansion(args[2]);
|
||||
if (expansion == null) {
|
||||
msg(s, "&cNo expansion found by the name: &f" + args[2]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
List<String> placeholders = expansion.getPlaceholders();
|
||||
if (placeholders == null) {
|
||||
msg(s, "&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 true;
|
||||
}
|
||||
|
||||
if (!(s instanceof Player)
|
||||
|| plugin.getExpansionManager().getRegisteredExpansion(expansion.getName()) == null) {
|
||||
msg(s, "&bPlaceholders: &f" + placeholders.size(),
|
||||
String.join("&a, &f", placeholders));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Player p = (Player) s;
|
||||
JSONMessage message = JSONMessage.create(color("&bPlaceholders: &f" + placeholders.size()));
|
||||
message.then("\n");
|
||||
|
||||
for (int i = 0; i < placeholders.size(); i++) {
|
||||
if (i == placeholders.size() - 1) {
|
||||
message.then(placeholders.get(i));
|
||||
} else {
|
||||
message.then(color(placeholders.get(i) + "&b, &f"));
|
||||
}
|
||||
try {
|
||||
message.tooltip(PlaceholderAPI.setPlaceholders(p, placeholders.get(i)));
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
message.send(p);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[1].equalsIgnoreCase("list")) {
|
||||
int page = 1;
|
||||
|
||||
String author;
|
||||
boolean installed = false;
|
||||
|
||||
if (args.length < 3) {
|
||||
msg(s, "&cIncorrect usage! &7/papi ecloud list <all/author/installed> (page)");
|
||||
return true;
|
||||
}
|
||||
|
||||
author = args[2];
|
||||
|
||||
if (author.equalsIgnoreCase("all")) {
|
||||
author = null;
|
||||
} else if (author.equalsIgnoreCase("installed")) {
|
||||
author = null;
|
||||
installed = true;
|
||||
}
|
||||
|
||||
if (args.length >= 4) {
|
||||
try {
|
||||
page = Integer.parseInt(args[3]);
|
||||
} catch (NumberFormatException ex) {
|
||||
msg(s, "&cPage number must be an integer!");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (page < 1) {
|
||||
msg(s, "&cPage must be greater than or equal to 1!");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int avail;
|
||||
Map<Integer, CloudExpansion> 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(s, "&cNo expansions available" + (author != null ? " for author &f" + author : ""));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
avail = plugin.getExpansionCloud().getPagesAvailable(ex, 10);
|
||||
if (page > avail) {
|
||||
msg(s, "&cThere " + ((avail == 1) ? " is only &f" + avail + " &cpage available!"
|
||||
: "are only &f" + avail + " &cpages available!"));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
msg(s, "&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(s, "&cThere was a problem getting the requested page...");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
msg(s, "&aGreen = Expansions you have");
|
||||
msg(s, "&6Gold = Expansions which need updated");
|
||||
|
||||
if (!(s instanceof Player)) {
|
||||
Map<String, CloudExpansion> expansions = new HashMap<>();
|
||||
|
||||
for (CloudExpansion exp : ex.values()) {
|
||||
if (exp == null || exp.getName() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
expansions.put(exp.getName(), exp);
|
||||
}
|
||||
|
||||
List<String> 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;
|
||||
}
|
||||
|
||||
CloudExpansion expansion = expansions.get(name);
|
||||
|
||||
msg(s,
|
||||
"&b" + i + "&7: " + (expansion.shouldUpdate() ? "&6"
|
||||
: (expansion.hasExpansion() ? "&a" : "&7")) + expansion
|
||||
.getName() + " &8&m-- &r" + expansion.getVersion().getUrl());
|
||||
i++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Player p = (Player) s;
|
||||
|
||||
Map<String, CloudExpansion> expansions = new HashMap<>();
|
||||
|
||||
for (CloudExpansion exp : ex.values()) {
|
||||
if (exp == null || exp.getName() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
expansions.put(exp.getName(), exp);
|
||||
}
|
||||
|
||||
List<String> 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;
|
||||
}
|
||||
|
||||
CloudExpansion expansion = expansions.get(name);
|
||||
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());
|
||||
|
||||
String msg = color(
|
||||
"&b" + (i + 1) + "&7: " + (expansion.shouldUpdate() ? "&6"
|
||||
: (expansion.hasExpansion() ? "&a" : "")) + expansion.getName());
|
||||
|
||||
String hover = color(sb.toString());
|
||||
|
||||
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++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[1].equalsIgnoreCase("download")) {
|
||||
if (args.length < 3) {
|
||||
msg(s, "&cAn expansion name must be specified!");
|
||||
return true;
|
||||
}
|
||||
|
||||
CloudExpansion expansion = plugin.getExpansionCloud().getCloudExpansion(args[2]);
|
||||
if (expansion == null) {
|
||||
msg(s, "&cNo expansion found with the name: &f" + args[2]);
|
||||
return true;
|
||||
}
|
||||
|
||||
PlaceholderExpansion loaded = plugin.getExpansionManager().getRegisteredExpansion(args[2]);
|
||||
if (loaded != null && loaded.isRegistered()) {
|
||||
PlaceholderAPI.unregisterPlaceholderHook(loaded.getIdentifier());
|
||||
}
|
||||
|
||||
String version = expansion.getLatestVersion();
|
||||
|
||||
if (args.length == 4) {
|
||||
version = args[3];
|
||||
if (expansion.getVersion(version) == null) {
|
||||
msg(s, "&cThe version you specified does not exist for &f" + expansion.getName());
|
||||
msg(s, "&7Available versions: &f" + expansion.getVersions().size());
|
||||
msg(s, String.join("&a, &f", expansion.getAvailableVersions()));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
msg(s, "&aDownload starting for expansion: &f" + expansion.getName() + " &aversion: &f" + version);
|
||||
String player = ((s instanceof Player) ? s.getName() : null);
|
||||
plugin.getExpansionCloud().downloadExpansion(player, expansion, version);
|
||||
plugin.getExpansionCloud().clean();
|
||||
plugin.getExpansionCloud().fetch(plugin.getPlaceholderAPIConfig().cloudAllowUnverifiedExpansions());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
msg(s, "&cIncorrect usage! &b/papi ecloud");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,330 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* PlaceholderAPI
|
||||
* Copyright (C) 2019 Ryan McCarthy
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
*/
|
||||
package me.clip.placeholderapi.commands;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PlaceholderAPICommands implements CommandExecutor {
|
||||
|
||||
private final PlaceholderAPIPlugin plugin;
|
||||
private final CommandExecutor eCloud;
|
||||
|
||||
public PlaceholderAPICommands(PlaceholderAPIPlugin i) {
|
||||
plugin = i;
|
||||
eCloud = new ExpansionCloudCommands(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender s, Command c, String label, String[] args) {
|
||||
if (args.length == 0) {
|
||||
|
||||
Msg.msg(s, "PlaceholderAPI &7version &b&o" + plugin.getDescription().getVersion(),
|
||||
"&fCreated by&7: &b" + plugin.getDescription().getAuthors(),
|
||||
"&fPapi commands: &b/papi help",
|
||||
"&fEcloud commands: &b/papi ecloud");
|
||||
|
||||
return true;
|
||||
} else {
|
||||
if (args[0].equalsIgnoreCase("help")) {
|
||||
|
||||
Msg.msg(s, "PlaceholderAPI &aHelp &e(&f" + plugin.getDescription().getVersion() + "&e)",
|
||||
"&b/papi",
|
||||
"&fView plugin info/version info",
|
||||
"&b/papi list",
|
||||
"&fList all placeholder expansions that are currently active",
|
||||
"&b/papi info <placeholder name>",
|
||||
"&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 <player one> <player two> <...args>",
|
||||
"&fParse a String with relational placeholders",
|
||||
"&b/papi register <fileName>",
|
||||
"&fRegister an expansion by the name of the file",
|
||||
"&b/papi unregister <Expansion name>",
|
||||
"&fUnregister an expansion by name",
|
||||
"&b/papi reload",
|
||||
"&fReload the config settings");
|
||||
|
||||
if (s.hasPermission("placeholderapi.ecloud")) {
|
||||
Msg.msg(s, "&b/papi disablecloud",
|
||||
"&fDisable the expansion cloud",
|
||||
"&b/papi ecloud",
|
||||
"&fView ecloud command usage");
|
||||
|
||||
Msg.msg(s, "&b/papi enablecloud",
|
||||
"&fEnable the expansion cloud");
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (args[0].equalsIgnoreCase("ecloud")) {
|
||||
if (!s.hasPermission("placeholderapi.ecloud")) {
|
||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (plugin.getExpansionCloud() == null) {
|
||||
Msg.msg(s, "&7The expansion cloud is not enabled!");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return eCloud.onCommand(s, c, label, args);
|
||||
} else if (args[0].equalsIgnoreCase("enablecloud")) {
|
||||
if (!s.hasPermission("placeholderapi.ecloud")) {
|
||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (plugin.getExpansionCloud() != null) {
|
||||
Msg.msg(s, "&7The cloud is already enabled!");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
plugin.enableCloud();
|
||||
plugin.getPlaceholderAPIConfig().setCloudEnabled(true);
|
||||
Msg.msg(s, "&aThe cloud has been enabled!");
|
||||
|
||||
return true;
|
||||
} else if (args[0].equalsIgnoreCase("disablecloud")) {
|
||||
if (!s.hasPermission("placeholderapi.ecloud")) {
|
||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (plugin.getExpansionCloud() == null) {
|
||||
Msg.msg(s, "&7The cloud is already disabled!");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
plugin.disableCloud();
|
||||
plugin.getPlaceholderAPIConfig().setCloudEnabled(false);
|
||||
Msg.msg(s, "&aThe cloud has been disabled!");
|
||||
|
||||
return true;
|
||||
} else if (args.length > 1 && args[0].equalsIgnoreCase("info")) {
|
||||
if (!s.hasPermission("placeholderapi.info")) {
|
||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
PlaceholderExpansion ex = plugin.getExpansionManager().getRegisteredExpansion(args[1]);
|
||||
if (ex == null) {
|
||||
Msg.msg(s, "&cThere is no expansion loaded with the identifier: &f" + args[1]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Msg.msg(s, "&7Placeholder expansion info for: &f" + ex.getName());
|
||||
Msg.msg(s, "&7Status: " + (ex.isRegistered() ? "&aRegistered" : "&cNot registered"));
|
||||
|
||||
if (ex.getAuthor() != null) {
|
||||
Msg.msg(s, "&7Created by: &f" + ex.getAuthor());
|
||||
}
|
||||
|
||||
if (ex.getVersion() != null) {
|
||||
Msg.msg(s, "&7Version: &f" + ex.getVersion());
|
||||
}
|
||||
|
||||
if (ex.getRequiredPlugin() != null) {
|
||||
Msg.msg(s, "&7Requires plugin: &f" + ex.getRequiredPlugin());
|
||||
}
|
||||
|
||||
if (ex.getPlaceholders() != null) {
|
||||
Msg.msg(s, "&8&m-- &r&7Placeholders &8&m--");
|
||||
|
||||
for (String placeholder : ex.getPlaceholders()) {
|
||||
Msg.msg(s, placeholder);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (args.length > 2 && args[0].equalsIgnoreCase("parse")
|
||||
|| args.length > 2 && args[0].equalsIgnoreCase("bcparse")) {
|
||||
|
||||
if (!s.hasPermission("placeholderapi.parse")) {
|
||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
OfflinePlayer pl;
|
||||
|
||||
if (args[1].equalsIgnoreCase("me")) {
|
||||
if (s instanceof Player) {
|
||||
pl = (Player) s;
|
||||
} else {
|
||||
Msg.msg(s, "&cThis command must target a player when used by console");
|
||||
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (Bukkit.getPlayer(args[1]) != null) {
|
||||
pl = Bukkit.getPlayer(args[1]);
|
||||
} else {
|
||||
pl = Bukkit.getOfflinePlayer(args[1]);
|
||||
}
|
||||
}
|
||||
|
||||
if (pl == null || (!pl.hasPlayedBefore() && !pl.isOnline())) {
|
||||
Msg.msg(s, "&cFailed to find player: &f" + args[1]);
|
||||
return true;
|
||||
}
|
||||
|
||||
String parse = StringUtils.join(args, " ", 2, args.length);
|
||||
|
||||
if (args[0].equalsIgnoreCase("bcparse")) {
|
||||
Msg.broadcast("&r" + PlaceholderAPI.setPlaceholders(pl, parse));
|
||||
} else {
|
||||
Msg.msg(s, "&r" + PlaceholderAPI.setPlaceholders(pl, parse));
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (args.length > 3 && args[0].equalsIgnoreCase("parserel")) {
|
||||
if (!(s instanceof Player)) {
|
||||
Msg.msg(s, "&cThis command can only be used in game!");
|
||||
|
||||
return true;
|
||||
} else {
|
||||
if (!s.hasPermission("placeholderapi.parse")) {
|
||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Player one = Bukkit.getPlayer(args[1]);
|
||||
if (one == null) {
|
||||
Msg.msg(s, args[1] + " &cis not online!");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Player two = Bukkit.getPlayer(args[2]);
|
||||
if (two == null) {
|
||||
Msg.msg(s, args[2] + " &cis not online!");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
String parse = StringUtils.join(args, " ", 3, args.length);
|
||||
Msg.msg(s, "&r" + PlaceholderAPI.setRelationalPlaceholders(one, two, parse));
|
||||
|
||||
return true;
|
||||
} else if (args[0].equalsIgnoreCase("reload")) {
|
||||
if (s instanceof Player) {
|
||||
if (!s.hasPermission("placeholderapi.reload")) {
|
||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Msg.msg(s, "&fPlaceholder&7API &bconfiguration reloaded!");
|
||||
plugin.reloadConf(s);
|
||||
} else if (args[0].equalsIgnoreCase("list")) {
|
||||
if (s instanceof Player) {
|
||||
if (!s.hasPermission("placeholderapi.list")) {
|
||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Set<String> registered = PlaceholderAPI.getRegisteredIdentifiers();
|
||||
if (registered.isEmpty()) {
|
||||
Msg.msg(s, "&7There are no placeholder hooks currently registered!");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Msg.msg(s, registered.size() + " &7Placeholder hooks registered:");
|
||||
Msg.msg(s, registered.stream().sorted().collect(Collectors.joining(", ")));
|
||||
} else if (args.length > 1 && args[0].equalsIgnoreCase("register")) {
|
||||
if (s instanceof Player) {
|
||||
if (!s.hasPermission("placeholderapi.register")) {
|
||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
String fileName = args[1].replace(".jar", "");
|
||||
PlaceholderExpansion ex = plugin.getExpansionManager().registerExpansion(fileName);
|
||||
|
||||
if (ex == null) {
|
||||
Msg.msg(s, "&cFailed to register expansion from " + fileName);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Msg.msg(s, "&aSuccessfully registered expansion: &f" + ex.getName());
|
||||
} else if (args.length > 1 && args[0].equalsIgnoreCase("unregister")) {
|
||||
|
||||
if (s instanceof Player) {
|
||||
if (!s.hasPermission("placeholderapi.register")) {
|
||||
Msg.msg(s, "&cYou don't have permission to do that!");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
PlaceholderExpansion ex = plugin.getExpansionManager().getRegisteredExpansion(args[1]);
|
||||
if (ex == null) {
|
||||
Msg.msg(s, "&cFailed to find expansion: &f" + args[1]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (PlaceholderAPI.unregisterExpansion(ex)) {
|
||||
Msg.msg(s, "&aSuccessfully unregistered expansion: &f" + ex.getName());
|
||||
} else {
|
||||
Msg.msg(s, "&cFailed to unregister expansion: &f" + ex.getName());
|
||||
}
|
||||
|
||||
} else {
|
||||
Msg.msg(s, "&cIncorrect usage! &7/papi help");
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
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<String> 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 <all/author> (page)",
|
||||
"&fList all/author specific available expansions",
|
||||
"&b/papi ecloud info <expansion name>",
|
||||
"&fView information about a specific expansion available on the cloud",
|
||||
"&b/papi ecloud versioninfo <expansion name> <version>",
|
||||
"&fView information about a specific version of an expansion",
|
||||
"&b/papi ecloud placeholders <expansion name>",
|
||||
"&fView placeholders for an expansion",
|
||||
"&b/papi ecloud download <expansion name> (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<String> handleCompletion(@NotNull final CommandSender sender, @NotNull final String[] args) {
|
||||
if (args.length == MAXIMUM_ARGUMENTS) {
|
||||
return StringUtil.copyPartialMatches(args[0], COMPLETIONS, new ArrayList<>(COMPLETIONS.size()));
|
||||
}
|
||||
|
||||
return super.handleCompletion(sender, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
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!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
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 <placeholder name>",
|
||||
"&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 <player one> <player two> <...args>",
|
||||
"&fParse a String with relational placeholders",
|
||||
"&b/papi register <fileName>",
|
||||
"&fRegister an expansion by the name of the file",
|
||||
"&b/papi unregister <Expansion name>",
|
||||
"&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");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
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 <expansion>", 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<String> handleCompletion(@NotNull final CommandSender sender, @NotNull final String[] args) {
|
||||
if (args.length == MINIMUM_ARGUMENTS) {
|
||||
final Set<String> completions = PlaceholderAPI.getRegisteredIdentifiers();
|
||||
|
||||
return StringUtil.copyPartialMatches(args[0], completions, new ArrayList<>(completions.size()));
|
||||
}
|
||||
|
||||
return super.handleCompletion(sender, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
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<String> 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(", ")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
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<String> handleCompletion(@NotNull final CommandSender sender, @NotNull final String[] args) {
|
||||
if (args.length == MINIMUM_ARGUMENTS) {
|
||||
final Set<String> completions = PlaceholderAPI.getRegisteredIdentifiers();
|
||||
|
||||
return StringUtil.copyPartialMatches(args[0], completions, new ArrayList<>(completions.size()));
|
||||
}
|
||||
|
||||
return super.handleCompletion(sender, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
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<String> 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<String> 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
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 ClearCommand extends Command {
|
||||
public ClearCommand() {
|
||||
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!!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
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 DownloadCommand extends Command {
|
||||
public DownloadCommand() {
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
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.JSONMessage;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
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 InfoCommand extends Command {
|
||||
public InfoCommand() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
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.JSONMessage;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
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 ListCommand extends Command {
|
||||
private static final int MINIMUM_ARGUMENTS = 1;
|
||||
private static final Set<String> COMPLETIONS = Sets.newHashSet(
|
||||
"all",
|
||||
"author",
|
||||
"installed"
|
||||
);
|
||||
|
||||
public ListCommand() {
|
||||
super("ecloud list", options("&cIncorrect usage! &7/papi ecloud list <all/author/installed> (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<Integer, CloudExpansion> 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<String, CloudExpansion> expansions = new HashMap<>();
|
||||
|
||||
for (CloudExpansion exp : ex.values()) {
|
||||
if (exp == null || exp.getName() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
expansions.put(exp.getName(), exp);
|
||||
}
|
||||
|
||||
final List<String> 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<String, CloudExpansion> expansions = new HashMap<>();
|
||||
|
||||
for (final CloudExpansion exp : ex.values()) {
|
||||
if (exp == null || exp.getName() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
expansions.put(exp.getName(), exp);
|
||||
}
|
||||
|
||||
final List<String> 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<String> handleCompletion(@NotNull final CommandSender sender, @NotNull final String[] args) {
|
||||
if (args.length == MINIMUM_ARGUMENTS) {
|
||||
return StringUtil.copyPartialMatches(args[0], COMPLETIONS, new ArrayList<>(COMPLETIONS.size()));
|
||||
}
|
||||
|
||||
if (args.length == MINIMUM_ARGUMENTS + 1) {
|
||||
return Collections.singletonList("Pages");
|
||||
}
|
||||
|
||||
return super.handleCompletion(sender, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
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.JSONMessage;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class PlaceholdersCommand extends Command {
|
||||
public PlaceholdersCommand() {
|
||||
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<String> 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
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 RefreshCommand extends Command {
|
||||
public RefreshCommand() {
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
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 StatusCommand extends Command {
|
||||
public StatusCommand() {
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
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.JSONMessage;
|
||||
import me.clip.placeholderapi.util.Msg;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class VersionInfoCommand extends Command {
|
||||
public VersionInfoCommand() {
|
||||
super("ecloud versioninfo", options("&cIncorrect usage! &7/papi ecloud versioninfo <name> <version>",
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user