mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2026-02-07 12:37:14 +01:00
Commands rewrite (#357)
* began rewriting command system * began rewriting command system * updated formatting * added new info command * added new reload command * updated new parse command to support all three parsing types * added new commands to command router * deleted old unused commands * removed parserel * added new expansion register and unregister commands * deleted unused commands * fixed annotation order * added labels helper to command * updated alias method to return an immutable view * updated params param with unmodifiable annotation * updated router to build an immutable map of the commands * began rewriting command system * updated formatting * added new info command * added new reload command * updated new parse command to support all three parsing types * added new commands to command router * deleted old unused commands * removed parserel * added new expansion register and unregister commands * deleted unused commands * fixed annotation order * added labels helper to command * updated alias method to return an immutable view * updated params param with unmodifiable annotation * updated router to build an immutable map of the commands * updated plugin class to use new command router * updated switch to break on parse match * updated register completions to suggest file names * updated router to allow entering labels in any case * updated parse command to send message to players as components * added command dispatching parsing * moved new commands into local package * added helper functions for filtering and suggesting * updated imports, updated tab completion to use helper functions * added start of ecloud commands * replace ecloud enable and disable commands with single toggle command evaluator * deleted unused commands * updated commands to use helper functions for suggesting * updated downloading to use completablefuture, updated all methods to use streams exclusively * updated to use the config instead of a null check * deleted old commands system * finished new command system * updated to use new method from cloud manager * fixed annotation ordering and added missing annotations * updated ecloud subcommands to have a more specific permission * updated plugin.yml with the new permissions, (and also fixed its formatting) * fixed annotations intellij missed * this should probably be there...
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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")));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user