mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2025-09-06 17:27:05 +02:00
Changed command system (#304)
* Save Cacheable expansions data on shutdown * Prepare for 1.16 * 1.16.1 is out apparently * Further fixes, still not done * Inline JSONMessages & fix for 1.16 * Done :O * Done for real now, (hopefully) * Changed to static instead of DI for plugin instance * Cleanup * Modified tab completions. Removed extra command. * Apparently this is needed * Started cleaning stuff up basically just pushing so I can continue on laptop * did more cleaning, probs like half way done * more cleaning. reverted back to a min arg system somewhat similar to what frosty had, but less boilerplate. * Started debugging and fixing runtime/compile errors * Fixed bugs, still needs thorough testing * Re-enable metrics * relocated stuff again * - Remove json message relocation - uncomment other relocations - reformat pom - remove useless scope declaration - Fix metrics constructor - Switch commands to use inline json message Co-authored-by: iGabyTM <contactgabytm@gmail.com> Co-authored-by: darbyjack <admin@glaremasters.me> Co-authored-by: PiggyPiglet <noreply@piggypiglet.me>
This commit is contained in:
82
src/main/java/me/clip/placeholderapi/commands/Command.java
Normal file
82
src/main/java/me/clip/placeholderapi/commands/Command.java
Normal file
@@ -0,0 +1,82 @@
|
||||
package me.clip.placeholderapi.commands;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class Command {
|
||||
private static final Options EMPTY_OPTIONS = new Options(null, 0, null);
|
||||
|
||||
private final String match;
|
||||
private final String usage;
|
||||
private final int minimumArguments;
|
||||
private final Set<String> permissions;
|
||||
|
||||
protected Command(@NotNull final String match) {
|
||||
this(match, EMPTY_OPTIONS);
|
||||
}
|
||||
|
||||
protected Command(@NotNull final String match, @NotNull final Options options) {
|
||||
this.match = match;
|
||||
this.usage = options.usage == null ? "/papi " + match + " <required args> [optional args]" : options.usage;
|
||||
this.permissions = options.permissions == null ? Collections.emptySet() : ImmutableSet.copyOf(options.permissions);
|
||||
this.minimumArguments = options.minimumArguments;
|
||||
}
|
||||
|
||||
protected static Options usage(@NotNull final String usage, final int minimumArguments) {
|
||||
return new Options(usage, minimumArguments, null);
|
||||
}
|
||||
|
||||
protected static Options permissions(@NotNull final String... permissions) {
|
||||
return new Options(null, 0, permissions);
|
||||
}
|
||||
|
||||
protected static Options options(@NotNull final String usage, final int minimumArguments,
|
||||
@NotNull final String... permissions) {
|
||||
return new Options(usage, minimumArguments, permissions);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getMatch() {
|
||||
return match;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getUsage() {
|
||||
return usage;
|
||||
}
|
||||
|
||||
public int getMinimumArguments() {
|
||||
return minimumArguments;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<String> getPermissions() {
|
||||
return permissions;
|
||||
}
|
||||
|
||||
public abstract void execute(@NotNull final CommandSender sender, @NotNull final String[] args);
|
||||
|
||||
@NotNull
|
||||
public List<String> handleCompletion(@NotNull final CommandSender sender, @NotNull final String[] args) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
private static class Options {
|
||||
private final String usage;
|
||||
private final int minimumArguments;
|
||||
private final String[] permissions;
|
||||
|
||||
private Options(@Nullable final String usage, final int minimumArguments,
|
||||
@Nullable final String[] permissions) {
|
||||
this.usage = usage;
|
||||
this.minimumArguments = minimumArguments;
|
||||
this.permissions = permissions;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user