Merge branch 'master' into gradle

This commit is contained in:
PiggyPiglet 2020-07-24 15:50:17 +08:00 committed by GitHub
commit 8b3f37b61e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
59 changed files with 2411 additions and 2052 deletions

View File

@ -604,6 +604,14 @@ public final class PlaceholderAPI
return null;
}
/**
* @deprecated Will be removed in a future release.
*/
@Deprecated
public static String setPlaceholders(Player player, String text) {
return setPlaceholders(((OfflinePlayer) player), text);
}
/**
* @deprecated Will be removed in a future release.
*/

View File

@ -20,291 +20,287 @@
*/
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;
import me.clip.placeholderapi.expansion.Version;
import me.clip.placeholderapi.expansion.cloud.ExpansionCloudManager;
import me.clip.placeholderapi.external.EZPlaceholderHook;
import me.clip.placeholderapi.listeners.PlaceholderListener;
import me.clip.placeholderapi.listeners.ServerLoadEventListener;
import me.clip.placeholderapi.updatechecker.UpdateChecker;
import me.clip.placeholderapi.util.TimeUtil;
import me.clip.placeholderapi.util.Msg;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
/**
* Yes I have a shit load of work to do...
*
* @author Ryan McCarthy
*/
public class PlaceholderAPIPlugin extends JavaPlugin {
public final class PlaceholderAPIPlugin extends JavaPlugin
{
private static PlaceholderAPIPlugin instance;
private static SimpleDateFormat dateFormat;
private static String booleanTrue;
private static String booleanFalse;
private static Version serverVersion;
private PlaceholderAPIConfig config;
private ExpansionManager expansionManager;
private ExpansionCloudManager expansionCloud;
private long startTime;
@NotNull
private static final Version version = resolveServerVersion();
private static Version getVersion() {
String v = "unknown";
boolean spigot = false;
try {
v = Bukkit.getServer().getClass().getPackage().getName()
.split("\\.")[3];
} catch (ArrayIndexOutOfBoundsException ex) {
}
private static PlaceholderAPIPlugin instance;
try {
Class.forName("org.spigotmc.SpigotConfig");
Class.forName("net.md_5.bungee.api.chat.BaseComponent");
spigot = true;
} catch (ExceptionInInitializerError | ClassNotFoundException ignored) {
}
return new Version(v, spigot);
}
@NotNull
private final PlaceholderAPIConfig config = new PlaceholderAPIConfig(this);
@NotNull
private final ExpansionCloudManager cloud = new ExpansionCloudManager(this);
@NotNull
private final ExpansionManager manager = new ExpansionManager(this);
/**
* Gets the static instance of the main class for PlaceholderAPI. This class is not the actual API
* class, this is the main class that extends JavaPlugin. For most API methods, use static methods
* available from the class: {@link PlaceholderAPI}
*
* @return PlaceholderAPIPlugin instance
*/
public static PlaceholderAPIPlugin getInstance() {
return instance;
}
/**
* Get the configurable {@linkplain SimpleDateFormat} object that is used to parse time for
* generic time based placeholders
*
* @return date format
*/
public static SimpleDateFormat getDateFormat() {
return dateFormat != null ? dateFormat : new SimpleDateFormat(
"MM/dd/yy HH:mm:ss");
}
@Override
public void onLoad()
{
instance = this;
/**
* Get the configurable {@linkplain String} value that should be returned when a boolean is true
*
* @return string value of true
*/
public static String booleanTrue() {
return booleanTrue != null ? booleanTrue : "true";
}
saveDefaultConfig();
}
/**
* Get the configurable {@linkplain String} value that should be returned when a boolean is false
*
* @return string value of false
*/
public static String booleanFalse() {
return booleanFalse != null ? booleanFalse : "false";
}
@Override
public void onEnable()
{
setupCommand();
setupMetrics();
setupExpansions();
public static Version getServerVersion() {
return serverVersion != null ? serverVersion : getVersion();
}
new PlaceholderListener(this);
@Override
public void onLoad() {
startTime = System.currentTimeMillis();
instance = this;
serverVersion = getVersion();
config = new PlaceholderAPIConfig(this);
expansionManager = new ExpansionManager(this);
}
if (config.isCloudEnabled())
{
enableCloud();
}
@Override
public void onEnable() {
config.loadDefConfig();
setupOptions();
if (config.checkUpdates())
{
new UpdateChecker(this).fetch();
}
}
Objects.requireNonNull(getCommand("placeholderapi")).setExecutor(new CommandHandler());
new PlaceholderListener(this);
@Override
public void onDisable()
{
disableCloud();
try {
Class.forName("org.bukkit.event.server.ServerLoadEvent");
new ServerLoadEventListener(this);
} catch (ExceptionInInitializerError | ClassNotFoundException exception) {
Bukkit.getScheduler().runTaskLater(this, () -> {
getLogger().info("Placeholder expansion registration initializing...");
PlaceholderAPI.unregisterAll();
//fetch any hooks that may have registered externally onEnable first otherwise they will be lost
final Map<String, PlaceholderHook> alreadyRegistered = PlaceholderAPI.getPlaceholders();
getExpansionManager().registerAllExpansions();
HandlerList.unregisterAll(this);
Bukkit.getScheduler().cancelTasks(this);
if (alreadyRegistered != null && !alreadyRegistered.isEmpty()) {
alreadyRegistered.forEach(PlaceholderAPI::registerPlaceholderHook);
}
}, 1);
}
instance = null;
}
if (config.checkUpdates()) {
new UpdateChecker(this).fetch();
}
if (config.isCloudEnabled()) {
enableCloud();
}
public void reloadConf(@NotNull final CommandSender sender)
{
PlaceholderAPI.unregisterAllProvidedExpansions();
setupMetrics();
getServer().getScheduler().runTaskLater(this, this::checkHook, 40);
}
reloadConfig();
@Override
public void onDisable() {
disableCloud();
PlaceholderAPI.unregisterAll();
expansionManager = null;
Bukkit.getScheduler().cancelTasks(this);
serverVersion = null;
instance = null;
}
manager.registerAllExpansions();
public void reloadConf(CommandSender s) {
boolean cloudEnabled = this.expansionCloud != null;
PlaceholderAPI.unregisterAllProvidedExpansions();
reloadConfig();
setupOptions();
expansionManager.registerAllExpansions();
if (config.isCloudEnabled())
{
enableCloud();
}
else
{
disableCloud();
}
if (!config.isCloudEnabled()) {
disableCloud();
} else if (!cloudEnabled) {
enableCloud();
}
Msg.msg(sender,
PlaceholderAPI.getRegisteredIdentifiers().size() + " &aplaceholder hooks successfully registered!");
}
s.sendMessage(ChatColor.translateAlternateColorCodes('&',
PlaceholderAPI.getRegisteredIdentifiers().size()
+ " &aplaceholder hooks successfully registered!"));
}
public void enableCloud()
{
disableCloud();
cloud.fetch(config.cloudAllowUnverifiedExpansions());
}
private void checkHook() {
Map<String, PlaceholderHook> loaded = PlaceholderAPI.getPlaceholders();
public void disableCloud()
{
cloud.clean();
}
loaded.values().forEach(h -> {
if (h instanceof EZPlaceholderHook) {
String author;
try {
author = Bukkit.getPluginManager().getPlugin(((EZPlaceholderHook) h).getPluginName()).getDescription().getAuthors().toString();
} catch (Exception ex) {
author = "the author of the hook's plugin";
}
/**
* Obtain the configuration class for PlaceholderAPI.
*
* @return PlaceholderAPIConfig instance
*/
@NotNull
public PlaceholderAPIConfig getPlaceholderAPIConfig()
{
return config;
}
getLogger().severe(((EZPlaceholderHook) h).getPluginName() +
" is currently using a deprecated method to hook into PlaceholderAPI. Placeholders for that plugin no longer work. " +
"Please consult {author} and urge them to update it ASAP.".replace("{author}", author));
@NotNull
public ExpansionManager getExpansionManager()
{
return manager;
}
// disable the hook on startup
PlaceholderAPI.unregisterPlaceholderHook(((EZPlaceholderHook) h).getPlaceholderName());
}
});
}
@NotNull
public ExpansionCloudManager getExpansionCloud()
{
return cloud;
}
private void setupOptions() {
booleanTrue = config.booleanTrue();
if (booleanTrue == null) {
booleanTrue = "true";
}
private void setupCommand()
{
final PluginCommand pluginCommand = getCommand("placeholderapi");
if (pluginCommand == null)
{
return;
}
booleanFalse = config.booleanFalse();
final PlaceholderCommandRouter router = new PlaceholderCommandRouter(this);
pluginCommand.setExecutor(router);
pluginCommand.setTabCompleter(router);
}
if (booleanFalse == null) {
booleanFalse = "false";
}
private void setupMetrics()
{
final Metrics metrics = new Metrics(this);
metrics.addCustomChart(new Metrics.SimplePie("using_expansion_cloud", () -> getPlaceholderAPIConfig().isCloudEnabled() ? "yes" : "no"));
try {
dateFormat = new SimpleDateFormat(config.dateFormat());
} catch (Exception e) {
dateFormat = new SimpleDateFormat("MM/dd/yy HH:mm:ss");
}
}
metrics.addCustomChart(new Metrics.SimplePie("using_spigot", () -> getServerVersion().isSpigot() ? "yes" : "no"));
private void setupMetrics() {
Metrics m = new Metrics(this);
m.addCustomChart(new Metrics.SimplePie("using_expansion_cloud", () -> getExpansionCloud() != null ? "yes" : "no"));
metrics.addCustomChart(new Metrics.AdvancedPie("expansions_used", () -> {
m.addCustomChart(new Metrics.SimplePie("using_spigot", () -> getServerVersion().isSpigot() ? "yes" : "no"));
Map<String, Integer> map = new HashMap<>();
Map<String, PlaceholderHook> hooks = PlaceholderAPI.getPlaceholders();
m.addCustomChart(new Metrics.AdvancedPie("expansions_used", () -> {
Map<String, Integer> map = new HashMap<>();
Map<String, PlaceholderHook> hooks = PlaceholderAPI.getPlaceholders();
if (!hooks.isEmpty())
{
if (!hooks.isEmpty()) {
for (PlaceholderHook hook : hooks.values())
{
if (hook instanceof PlaceholderExpansion)
{
PlaceholderExpansion expansion = (PlaceholderExpansion) hook;
map.put(expansion.getRequiredPlugin() == null ? expansion.getIdentifier() : expansion.getRequiredPlugin(), 1);
}
}
}
for (PlaceholderHook hook : hooks.values()) {
if (hook instanceof PlaceholderExpansion) {
PlaceholderExpansion expansion = (PlaceholderExpansion) hook;
map.put(expansion.getRequiredPlugin() == null ? expansion.getIdentifier() : expansion.getRequiredPlugin(), 1);
}
}
}
return map;
return map;
}));
}
}));
}
private void setupExpansions()
{
try
{
Class.forName("org.bukkit.event.server.ServerLoadEvent");
new ServerLoadEventListener(this);
}
catch (final ExceptionInInitializerError | ClassNotFoundException exception)
{
Bukkit.getScheduler().runTaskLater(this, getExpansionManager()::initializeExpansions, 1);
}
}
public void enableCloud() {
if (expansionCloud == null) {
expansionCloud = new ExpansionCloudManager(this);
} else {
expansionCloud.clean();
}
expansionCloud.fetch(config.cloudAllowUnverifiedExpansions());
}
public void disableCloud() {
if (expansionCloud != null) {
expansionCloud.clean();
expansionCloud = null;
}
}
/**
* Gets the static instance of the main class for PlaceholderAPI. This class is not the actual API
* class, this is the main class that extends JavaPlugin. For most API methods, use static methods
* available from the class: {@link PlaceholderAPI}
*
* @return PlaceholderAPIPlugin instance
*/
@NotNull
public static PlaceholderAPIPlugin getInstance()
{
return instance;
}
/**
* Obtain the configuration class for PlaceholderAPI.
*
* @return PlaceholderAPIConfig instance
*/
public PlaceholderAPIConfig getPlaceholderAPIConfig() {
return config;
}
public ExpansionManager getExpansionManager() {
return expansionManager;
}
/**
* Get the configurable {@linkplain SimpleDateFormat} object that is used to parse time for
* generic time based placeholders
*
* @return date format
*/
@NotNull
public static SimpleDateFormat getDateFormat()
{
try
{
return new SimpleDateFormat(getInstance().getPlaceholderAPIConfig().dateFormat());
}
catch (final IllegalArgumentException ex)
{
public ExpansionCloudManager getExpansionCloud() {
return expansionCloud;
}
getInstance().getLogger().log(Level.WARNING, "configured date format is invalid", ex);
public String getUptime() {
return TimeUtil
.getTime((int) TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - startTime));
}
return new SimpleDateFormat("MM/dd/yy HH:mm:ss");
}
}
/**
* Get the configurable {@linkplain String} value that should be returned when a boolean is true
*
* @return string value of true
*/
@NotNull
public static String booleanTrue()
{
return getInstance().getPlaceholderAPIConfig().booleanTrue();
}
/**
* Get the configurable {@linkplain String} value that should be returned when a boolean is false
*
* @return string value of false
*/
@NotNull
public static String booleanFalse()
{
return getInstance().getPlaceholderAPIConfig().booleanFalse();
}
public static Version getServerVersion()
{
return version;
}
private static Version resolveServerVersion()
{
final String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
boolean isSpigot;
try
{
Class.forName("org.spigotmc.SpigotConfig");
isSpigot = true;
}
catch (final ExceptionInInitializerError | ClassNotFoundException ignored)
{
isSpigot = false;
}
return new Version(version, isSpigot);
}
public long getUptimeMillis() {
return (System.currentTimeMillis() - startTime);
}
}

View File

@ -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<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;
}
}
}

View File

@ -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<Command> 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<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;
}
}

View File

@ -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<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());
}
}

View File

@ -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<String> 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<String> getAlias()
{
return ImmutableSet.copyOf(alias);
}
@NotNull
@Unmodifiable
public final Set<String> getLabels()
{
return ImmutableSet.<String>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<String> params)
{
}
public void complete(@NotNull final PlaceholderAPIPlugin plugin, @NotNull final CommandSender sender, @NotNull final String alias, @NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions)
{
}
@NotNull
public static Stream<PlaceholderCommand> filterByPermission(@NotNull final CommandSender sender, @NotNull final Stream<PlaceholderCommand> commands)
{
return commands.filter(target -> target.getPermission() == null || sender.hasPermission(target.getPermission()));
}
public static void suggestByParameter(@NotNull final Stream<String> possible, @NotNull final List<String> suggestions, @Nullable final String parameter)
{
if (parameter == null)
{
possible.forEach(suggestions::add);
}
else
{
possible.filter(suggestion -> suggestion.toLowerCase().startsWith(parameter.toLowerCase())).forEach(suggestions::add);
}
}
}

View File

@ -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<PlaceholderCommand> 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<String, PlaceholderCommand> commands;
public PlaceholderCommandRouter(@NotNull final PlaceholderAPIPlugin plugin)
{
this.plugin = plugin;
final ImmutableMap.Builder<String, PlaceholderCommand> 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<String> onTabComplete(@NotNull final CommandSender sender, @NotNull final Command command, @NotNull final String alias, @NotNull final String[] args)
{
final List<String> 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<String> 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;
}
}

View File

@ -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));
}
}

View File

@ -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;
}
}

View File

@ -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<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);
}
}

View File

@ -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!");
}
}

View File

@ -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 <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");
}
}
}

View File

@ -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 <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);
}
}

View File

@ -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<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(", ")));
}
}

View File

@ -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));
}
}

View File

@ -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));
}
}

View File

@ -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());
}
}

View File

@ -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);
}
}

View File

@ -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<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);
}
}

View File

@ -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<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);
}
}

View File

@ -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!!");
}
}

View File

@ -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());
}
}

View File

@ -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);
}
}
}

View File

@ -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<String> COMPLETIONS = Sets.newHashSet(
"all",
"author",
"installed"
);
public EcloudListCommand() {
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);
}
}

View File

@ -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<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);
}
}

View File

@ -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());
}
}

View File

@ -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.");
}
}
}

View File

@ -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 <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);
}
}

View File

@ -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<PlaceholderCommand> 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<String, PlaceholderCommand> commands;
public CommandECloud()
{
super("ecloud");
final ImmutableMap.Builder<String, PlaceholderCommand> 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<String> 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 <all/{author}/installed> {page}",
" &7&oList all/author specific available expansions",
"&b/papi &fecloud info <expansion name> {version}",
" &7&oView information about a specific expansion available on the cloud",
"&b/papi &fecloud placeholders <expansion name>",
" &7&oView placeholders for an expansion",
"&b/papi &fecloud download <expansion name> {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<String> params, @NotNull final List<String> suggestions)
{
if (params.size() <= 1)
{
final Stream<String> 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);
}
}

View File

@ -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<String> params)
{
plugin.getExpansionCloud().clean();
Msg.msg(sender,
"&aThe ECloud cache has been cleared!");
}
}

View File

@ -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<String> 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<String> params, @NotNull final List<String> suggestions)
{
if (params.size() > 2)
{
return;
}
if (params.size() <= 1)
{
final Stream<String> 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<CloudExpansion> expansion = plugin.getExpansionCloud().getCloudExpansion(params.get(0));
if (!expansion.isPresent())
{
return;
}
suggestByParameter(expansion.get().getAvailableVersions().stream(), suggestions, params.get(1));
}
}

View File

@ -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<String> 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<String> params, @NotNull final List<String> suggestions)
{
if (params.size() > 2)
{
return;
}
if (params.size() <= 1)
{
final Stream<String> 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<CloudExpansion> expansion = plugin.getExpansionCloud().getCloudExpansion(params.get(0));
if (!expansion.isPresent())
{
return;
}
suggestByParameter(expansion.get().getAvailableVersions().stream(), suggestions, params.get(1));
}
}

View File

@ -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<String> 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<String> params)
{
if (params.isEmpty())
{
Msg.msg(sender,
"&cYou must specify an option. [all, {author}, installed]");
return;
}
@Unmodifiable final Map<Integer, CloudExpansion> 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<CloudExpansion> 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<String> params, @NotNull final List<String> 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<Integer, CloudExpansion> 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<CloudExpansion> getPage(@NotNull final Map<Integer, CloudExpansion> 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<Integer, CloudExpansion> 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);
}
}
}

View File

@ -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<String> 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<String> placeholders = expansion.getPlaceholders();
if (placeholders == null || placeholders.isEmpty())
{
Msg.msg(sender,
"&cThat expansion does not have placeholders listed.");
return;
}
final List<List<String>> 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<String> params, @NotNull final List<String> suggestions)
{
if (params.size() > 1)
{
return;
}
final Stream<String> names = plugin.getExpansionCloud().getCloudExpansions().values().stream().map(CloudExpansion::getName).map(name -> name.replace(' ', '_'));
suggestByParameter(names, suggestions, params.isEmpty() ? null : params.get(0));
}
}

View File

@ -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<String> params)
{
plugin.getExpansionCloud().clean();
plugin.getExpansionCloud().fetch(plugin.getPlaceholderAPIConfig().cloudAllowUnverifiedExpansions());
Msg.msg(sender,
"&aThe ECloud Manager has been refreshed!");
}
}

View File

@ -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<String> 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());
}
}

View File

@ -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<String> 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"));
}
}

View File

@ -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<String> 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<String> params, @NotNull final List<String> 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));
}
}

View File

@ -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<String> 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<String> params, @NotNull final List<String> suggestions)
{
if (params.size() > 1)
{
return;
}
suggestByParameter(PlaceholderAPI.getRegisteredIdentifiers().stream(), suggestions, params.isEmpty() ? null : params.get(0));
}
}

View File

@ -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<String> 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<placeholder name>",
" &7&oView information for a specific expansion",
"&b/papi &fparse &9<me/player name> <message>",
" &7&oParse a message with placeholders",
"&b/papi &fbcparse &9<me/player name> <message>",
" &7&oParse a message with placeholders and broadcast it",
"&b/papi &fparserel &9<player one> <player two> <message>",
" &7&oParse a message with relational placeholders",
"&b/papi &fregister &9<file name>",
" &7&oRegister an expansion by the name of the file",
"&b/papi &funregister &9<expansion name>",
" &7&oUnregister an expansion by name");
}
}

View File

@ -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<String> 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<String> 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<String> params, @NotNull final List<String> suggestions)
{
if (params.size() > 1)
{
return;
}
suggestByParameter(PlaceholderAPI.getRegisteredIdentifiers().stream(), suggestions, params.isEmpty() ? null : params.get(0));
}
}

View File

@ -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<String> params)
{
final Set<String> identifiers = PlaceholderAPI.getRegisteredIdentifiers();
if (identifiers.isEmpty())
{
Msg.msg(sender, "&6There are no placeholder hooks active!");
return;
}
final List<List<String>> 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")));
}
}

View File

@ -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<String> 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<String> params, @NotNull final List<String> 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<String> 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<String> 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<String> params, @NotNull final List<String> suggestions)
{
if (sender instanceof Player && (params.isEmpty() || (params.size() == 1 && params.get(0).toLowerCase().startsWith("m"))))
{
suggestions.add("me");
}
final Stream<String> names = Bukkit.getOnlinePlayers().stream().map(Player::getName);
suggestByParameter(names, suggestions, params.isEmpty() ? null : params.get(0));
}
private void completeParseRelation(@NotNull @Unmodifiable final List<String> params, @NotNull final List<String> suggestions)
{
if (params.size() > 2)
{
return;
}
final Stream<String> 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;
}
}

View File

@ -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<String> params)
{
plugin.reloadConf(sender);
Msg.msg(sender, "&fPlaceholder&7API &bconfiguration reloaded!");
}
}

View File

@ -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<String> 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");
}
}

View File

@ -21,50 +21,69 @@
package me.clip.placeholderapi.configuration;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import org.jetbrains.annotations.NotNull;
public class PlaceholderAPIConfig {
public final class PlaceholderAPIConfig
{
private final PlaceholderAPIPlugin plugin;
@NotNull
private final PlaceholderAPIPlugin plugin;
public PlaceholderAPIConfig(PlaceholderAPIPlugin i) {
plugin = i;
}
public PlaceholderAPIConfig(@NotNull final PlaceholderAPIPlugin plugin)
{
this.plugin = plugin;
}
public void loadDefConfig() {
plugin.saveDefaultConfig();
plugin.reloadConfig();
}
public boolean checkUpdates() {
return plugin.getConfig().getBoolean("check_updates");
}
public boolean checkUpdates()
{
return plugin.getConfig().getBoolean("check_updates");
}
public boolean cloudAllowUnverifiedExpansions() {
return plugin.getConfig().getBoolean("cloud_allow_unverified_expansions");
}
public boolean cloudAllowUnverifiedExpansions()
{
return plugin.getConfig().getBoolean("cloud_allow_unverified_expansions");
}
public boolean isCloudEnabled() {
return plugin.getConfig().getBoolean("cloud_enabled");
}
public void setCloudEnabled(boolean b) {
plugin.getConfig().set("cloud_enabled", b);
plugin.reloadConfig();
}
public boolean isCloudEnabled()
{
return plugin.getConfig().getBoolean("cloud_enabled");
}
public boolean isDebugMode() {
return plugin.getConfig().getBoolean("debug", false);
}
public void setCloudEnabled(boolean state)
{
plugin.getConfig().set("cloud_enabled", state);
plugin.saveConfig();
}
public String booleanTrue() {
return plugin.getConfig().getString("boolean.true");
}
public String booleanFalse() {
return plugin.getConfig().getString("boolean.false");
}
public boolean isDebugMode()
{
return plugin.getConfig().getBoolean("debug", false);
}
@NotNull
public String dateFormat()
{
//noinspection ConstantConditions (bad spigot annotation)
return plugin.getConfig().getString("date_format", "MM/dd/yy HH:mm:ss");
}
@NotNull
public String booleanTrue()
{
//noinspection ConstantConditions (bad spigot annotation)
return plugin.getConfig().getString("boolean.true", "true");
}
@NotNull
public String booleanFalse()
{
//noinspection ConstantConditions (bad spigot annotation)
return plugin.getConfig().getString("boolean.false", "false");
}
public String dateFormat() {
return plugin.getConfig().getString("date_format");
}
}

View File

@ -24,38 +24,57 @@ import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
public class ExpansionRegisterEvent extends Event implements Cancellable {
public final class ExpansionRegisterEvent extends Event implements Cancellable
{
private static final HandlerList HANDLERS = new HandlerList();
private final PlaceholderExpansion expansion;
private boolean isCancelled;
@NotNull
private static final HandlerList HANDLERS = new HandlerList();
public ExpansionRegisterEvent(PlaceholderExpansion expansion) {
this.expansion = expansion;
}
private boolean cancelled;
@NotNull
private final PlaceholderExpansion expansion;
public static HandlerList getHandlerList() {
return HANDLERS;
}
public ExpansionRegisterEvent(@NotNull final PlaceholderExpansion expansion)
{
this.expansion = expansion;
}
@Override
public HandlerList getHandlers() {
return HANDLERS;
}
public PlaceholderExpansion getExpansion() {
return expansion;
}
@NotNull
public PlaceholderExpansion getExpansion()
{
return expansion;
}
@Override
public boolean isCancelled() {
return isCancelled;
}
@Override
public void setCancelled(boolean b) {
this.isCancelled = b;
}
@Override
public boolean isCancelled()
{
return cancelled;
}
@Override
public void setCancelled(boolean cancelled)
{
this.cancelled = cancelled;
}
@NotNull
@Override
public HandlerList getHandlers()
{
return HANDLERS;
}
@NotNull
public static HandlerList getHandlerList()
{
return HANDLERS;
}
}

View File

@ -23,26 +23,43 @@ package me.clip.placeholderapi.events;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
public class ExpansionUnregisterEvent extends Event {
public final class ExpansionUnregisterEvent extends Event
{
private static final HandlerList HANDLERS = new HandlerList();
private final PlaceholderExpansion expansion;
@NotNull
private static final HandlerList HANDLERS = new HandlerList();
public ExpansionUnregisterEvent(PlaceholderExpansion expansion) {
this.expansion = expansion;
}
public static HandlerList getHandlerList() {
return HANDLERS;
}
@NotNull
private final PlaceholderExpansion expansion;
@Override
public HandlerList getHandlers() {
return HANDLERS;
}
public ExpansionUnregisterEvent(@NotNull final PlaceholderExpansion expansion)
{
this.expansion = expansion;
}
@NotNull
public PlaceholderExpansion getExpansion()
{
return expansion;
}
@NotNull
@Override
public HandlerList getHandlers()
{
return HANDLERS;
}
@NotNull
public static HandlerList getHandlerList()
{
return HANDLERS;
}
public PlaceholderExpansion getExpansion() {
return expansion;
}
}

View File

@ -23,33 +23,55 @@ package me.clip.placeholderapi.events;
import me.clip.placeholderapi.PlaceholderHook;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
/**
* @deprecated This event is no longer used.
*/
@Deprecated
public class PlaceholderHookUnloadEvent extends Event {
public final class PlaceholderHookUnloadEvent extends Event
{
private static final HandlerList HANDLERS = new HandlerList();
private final String plugin;
private final PlaceholderHook hook;
@NotNull
private static final HandlerList HANDLERS = new HandlerList();
public PlaceholderHookUnloadEvent(String plugin, PlaceholderHook placeholderHook) {
this.plugin = plugin;
this.hook = placeholderHook;
}
public static HandlerList getHandlerList() {
return HANDLERS;
}
@NotNull
private final String plugin;
@NotNull
private final PlaceholderHook placeholderHook;
@Override
public HandlerList getHandlers() {
return HANDLERS;
}
public PlaceholderHookUnloadEvent(@NotNull final String plugin, @NotNull final PlaceholderHook placeholderHook)
{
this.plugin = plugin;
this.placeholderHook = placeholderHook;
}
public String getHookName() {
return plugin;
}
@NotNull
public String getHookName()
{
return plugin;
}
@NotNull
public PlaceholderHook getHook()
{
return placeholderHook;
}
@NotNull
@Override
public HandlerList getHandlers()
{
return HANDLERS;
}
@NotNull
public static HandlerList getHandlerList()
{
return HANDLERS;
}
public PlaceholderHook getHook() {
return hook;
}
}

View File

@ -56,6 +56,27 @@ public final class ExpansionManager
}
}
@NotNull
public File getFolder()
{
return folder;
}
public void initializeExpansions()
{
plugin.getLogger().info("Placeholder expansion registration initializing...");
final Map<String, PlaceholderHook> registered = PlaceholderAPI.getPlaceholders();
registerAllExpansions();
if (!registered.isEmpty()) {
registered.forEach(PlaceholderAPI::registerPlaceholderHook);
}
}
public PlaceholderExpansion getRegisteredExpansion(String name)
{
for (Entry<String, PlaceholderHook> hook : PlaceholderAPI.getPlaceholders().entrySet())
@ -151,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)
{

View File

@ -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<Integer, CloudExpansion> expansions = new TreeMap<>();
@NotNull
private final Map<CloudExpansion, CompletableFuture<File>> 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<Integer, CloudExpansion> getCloudExpansions()
{
return ImmutableMap.copyOf(expansions);
}
@NotNull
@Unmodifiable
public Set<String> 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<CloudExpansion> 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<Integer, CloudExpansion> 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<Integer, CloudExpansion> 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<String, CloudExpansion> data = new HashMap<>();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(API_URL).openStream())))
{
data.putAll(GSON.fromJson(reader, new TypeToken<Map<String, CloudExpansion>>()
{
}.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<CloudExpansion> 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<File> previous = downloading.get(expansion);
if (previous != null)
{
return previous;
}
final File file = new File(folder, "Expansion-" + expansion.getName() + ".jar");
final CompletableFuture<File> 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<String> downloading = new ArrayList<>();
private final Map<Integer, CloudExpansion> 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<Integer, CloudExpansion> 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<Integer, CloudExpansion> getAllByAuthor(String author) {
if (remote.isEmpty()) return new HashMap<>();
Map<Integer, CloudExpansion> byAuthor = new TreeMap<>();
for (CloudExpansion ex : remote.values()) {
if (!ex.getAuthor().equalsIgnoreCase(author)) continue;
byAuthor.put(byAuthor.size(), ex);
}
return byAuthor;
}
public Map<Integer, CloudExpansion> getAllInstalled() {
if (remote.isEmpty()) return new HashMap<>();
Map<Integer, CloudExpansion> has = new TreeMap<>();
for (CloudExpansion ex : remote.values()) {
if (!ex.hasExpansion()) continue;
has.put(has.size(), ex);
}
return has;
}
public int getPagesAvailable(Map<Integer, CloudExpansion> 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<Integer, CloudExpansion> getPage(Map<Integer, CloudExpansion> 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<Integer, CloudExpansion> 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<String, CloudExpansion> data = new HashMap<>();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(API_URL).openStream()))) {
data.putAll(GSON.fromJson(reader, new TypeToken<Map<String, CloudExpansion>>() {
}.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<CloudExpansion> 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!");
}
}
});
});
}
}

View File

@ -1,59 +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.external;
import me.clip.placeholderapi.PlaceholderAPI;
import me.clip.placeholderapi.PlaceholderHook;
import org.apache.commons.lang.Validate;
import org.bukkit.plugin.Plugin;
/**
* Use {@link me.clip.placeholderapi.expansion.PlaceholderExpansion} instead
*/
@Deprecated
public abstract class EZPlaceholderHook extends PlaceholderHook {
private final String identifier;
private final String plugin;
public EZPlaceholderHook(Plugin plugin, String identifier) {
Validate.notNull(plugin, "Plugin can not be null!");
Validate.notNull(identifier, "Placeholder name can not be null!");
this.identifier = identifier;
this.plugin = plugin.getName();
}
public boolean isHooked() {
return PlaceholderAPI.getRegisteredPlaceholderPlugins().contains(identifier);
}
public boolean hook() {
return PlaceholderAPI.registerPlaceholderHook(identifier, this);
}
public String getPlaceholderName() {
return identifier;
}
public String getPluginName() {
return plugin;
}
}

View File

@ -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);

View File

@ -20,43 +20,42 @@
*/
package me.clip.placeholderapi.listeners;
import me.clip.placeholderapi.PlaceholderAPI;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.PlaceholderHook;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.server.ServerLoadEvent;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
public final class ServerLoadEventListener implements Listener
{
public class ServerLoadEventListener implements Listener {
@NotNull
private final PlaceholderAPIPlugin plugin;
private final PlaceholderAPIPlugin plugin;
public ServerLoadEventListener(@NotNull final PlaceholderAPIPlugin plugin)
{
this.plugin = plugin;
public ServerLoadEventListener(PlaceholderAPIPlugin instance) {
plugin = instance;
Bukkit.getPluginManager().registerEvents(this, instance);
}
Bukkit.getPluginManager().registerEvents(this, plugin);
}
/**
* This method will be called when the server is first loaded
* <p>
* The goal of the method is to register all the expansions as soon as possible
* especially before players can join
* <p>
* This will ensure no issues with expanions and hooks.
*
* @param e the server load event
*/
@EventHandler
public void onServerLoad(ServerLoadEvent e) {
plugin.getLogger().info("Placeholder expansion registration initializing...");
final Map<String, PlaceholderHook> alreadyRegistered = PlaceholderAPI.getPlaceholders();
plugin.getExpansionManager().registerAllExpansions();
/**
* This method will be called when the server is first loaded
* <p>
* The goal of the method is to register all the expansions as soon as possible
* especially before players can join
* <p>
* This will ensure no issues with expansions and hooks.
*
* @param event the server load event
*/
@EventHandler
public void onServerLoad(@NotNull final ServerLoadEvent event)
{
HandlerList.unregisterAll(this);
plugin.getExpansionManager().initializeExpansions();
}
if (alreadyRegistered != null && !alreadyRegistered.isEmpty()) {
alreadyRegistered.forEach(PlaceholderAPI::registerPlaceholderHook);
}
}
}

View File

@ -1,6 +1,7 @@
package me.clip.placeholderapi.replacer;
import me.clip.placeholderapi.PlaceholderHook;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -34,15 +35,51 @@ public final class CharsReplacer implements Replacer
if (l == '&' && ++i < chars.length)
{
final char c = chars[i];
final char c = Character.toLowerCase(chars[i]);
if (c != '0' && c != '1' && c != '2' && c != '3' && c != '4' && c != '5' && c != '6' && c != '7' && c != '8' && c != '9' && c != 'a' && c != 'b' && c != 'c' && c != 'd' && c != 'e' && c != 'f' && c != 'k' && c != 'l' && c != 'm' && c != 'o' && c != 'r' && c != 'x')
{
builder.append(l).append(c);
builder.append(l).append(chars[i]);
}
else
{
builder.append('§').append(c);
builder.append(ChatColor.COLOR_CHAR);
if (c != 'x')
{
builder.append(chars[i]);
continue;
}
if ((i > 1 && chars[i - 2] == '\\') /*allow escaping &x*/)
{
builder.setLength(builder.length() - 2);
builder.append('&').append(chars[i]);
continue;
}
builder.append(c);
int j = 0;
while (++j <= 6)
{
if (i + j >= chars.length)
{
break;
}
final char x = chars[i + j];
builder.append(ChatColor.COLOR_CHAR).append(x);
}
if (j == 7)
{
i += 6;
}
else
{
builder.setLength(builder.length() - (j * 2)); // undo &x parsing
}
}
continue;
}
@ -54,20 +91,19 @@ public final class CharsReplacer implements Replacer
}
boolean identified = false;
boolean oopsitsbad = false;
boolean oopsitsbad = true;
while (++i < chars.length)
{
final char p = chars[i];
if (p == closure.tail)
if (p == ' ')
{
break;
}
if (p == ' ')
if (p == closure.tail)
{
oopsitsbad = true;
oopsitsbad = false;
break;
}
@ -109,14 +145,28 @@ public final class CharsReplacer implements Replacer
final PlaceholderHook placeholder = lookup.apply(identifierString);
if (placeholder == null)
{
builder.append(closure.head).append(identifierString).append('_').append(parametersString).append(closure.tail);
builder.append(closure.head).append(identifierString);
if (identified)
{
builder.append('_');
}
builder.append(parametersString).append(closure.tail);
continue;
}
final String replacement = placeholder.onRequest(player, parametersString);
if (replacement == null)
{
builder.append(closure.head).append(identifierString).append('_').append(parametersString).append(closure.tail);
builder.append(closure.head).append(identifierString);
if (identified)
{
builder.append('_');
}
builder.append(parametersString).append(closure.tail);
continue;
}

View File

@ -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";
}

View File

@ -71,9 +71,9 @@ public class FileUtil
return list;
}
catch (Throwable t)
catch (final Throwable ex)
{
// THIS SHOULD NOT BE EATEN LIKE THIS.
ex.printStackTrace();
}
return Collections.emptyList();
@ -92,11 +92,16 @@ public class FileUtil
continue;
}
final Class<?> loaded = loader.loadClass(name.substring(0, name.lastIndexOf('.')).replace('/', '.'));
if (clazz.isAssignableFrom(loaded))
try
{
list.add(loaded.asSubclass(clazz));
final Class<?> loaded = loader.loadClass(name.substring(0, name.lastIndexOf('.')).replace('/', '.'));
if (clazz.isAssignableFrom(loaded))
{
list.add(loaded.asSubclass(clazz));
}
}
catch (final NoClassDefFoundError ignored)
{ }
}
}
}

View File

@ -1,42 +1,98 @@
name: @name@
main: me.clip.placeholderapi.PlaceholderAPIPlugin
version: @version@
api-version: '1.13'
authors: [extended_clip, Glare]
description: @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: "@name@"
main: "me.clip.placeholderapi.PlaceholderAPIPlugin"
version: "@version@"
author: HelpChat
api-version: "1.13"
description: "@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"

View File

@ -64,4 +64,12 @@ public final class ReplacerUnitTester
assertEquals(text, Values.CHARS_REPLACER.apply(text, null, Values.PLACEHOLDERS::get));
}
@Test
void testCharsReplacerHandlesEscapedHex()
{
final String text = "\\&xFFFFFFThis should not change.";
assertEquals(text.substring(1), Values.CHARS_REPLACER.apply(text, null, Values.PLACEHOLDERS::get));
}
}