Add bbox admin perms command and adjust perms for commands
Made some admin commands have their own perm so that they can be controlled individually by permissions.
This commit is contained in:
parent
b64015e3b6
commit
e9067cfb28
4
pom.xml
4
pom.xml
|
@ -73,10 +73,10 @@
|
|||
<postgresql.version>42.2.18</postgresql.version>
|
||||
<hikaricp.version>5.0.1</hikaricp.version>
|
||||
<!-- More visible way to change dependency versions -->
|
||||
<spigot.version>1.20-R0.1-SNAPSHOT</spigot.version>
|
||||
<spigot.version>1.20.1-R0.1-SNAPSHOT</spigot.version>
|
||||
<!-- Might differ from the last Spigot release for short periods
|
||||
of time -->
|
||||
<paper.version>1.20-R0.1-SNAPSHOT</paper.version>
|
||||
<paper.version>1.20.1-R0.1-SNAPSHOT</paper.version>
|
||||
<bstats.version>3.0.0</bstats.version>
|
||||
<vault.version>1.7.1</vault.version>
|
||||
<placeholderapi.version>2.10.9</placeholderapi.version>
|
||||
|
|
|
@ -48,6 +48,13 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
|||
*/
|
||||
private boolean onlyPlayer = false;
|
||||
|
||||
/**
|
||||
* True if the command is only for the console
|
||||
* @since 1.24.0
|
||||
*/
|
||||
private boolean onlyConsole = false;
|
||||
|
||||
|
||||
/**
|
||||
* True if command is a configurable rank
|
||||
*/
|
||||
|
@ -257,10 +264,14 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
|||
*/
|
||||
public boolean call(User user, String cmdLabel, List<String> cmdArgs) {
|
||||
// Check for console and permissions
|
||||
if (onlyPlayer && !user.isPlayer()) {
|
||||
if (isOnlyPlayer() && !user.isPlayer()) {
|
||||
user.sendMessage("general.errors.use-in-game");
|
||||
return false;
|
||||
}
|
||||
if (isOnlyConsole() && user.isPlayer()) {
|
||||
user.sendMessage("general.errors.use-in-console");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this.runPermissionCheck(user))
|
||||
{
|
||||
|
@ -513,6 +524,14 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
|||
return onlyPlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this command is only for consoles.
|
||||
* @return true or false
|
||||
*/
|
||||
public boolean isOnlyConsole() {
|
||||
return onlyConsole;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether this command should only be run by players.
|
||||
* If this is set to {@code true}, this command will only be runnable by objects implementing {@link Player}.
|
||||
|
@ -525,6 +544,18 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
|||
this.onlyPlayer = onlyPlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether this command should only be run in the console.
|
||||
* This is for commands that dump a lot of data or are for debugging.
|
||||
* The default value provided when instantiating this CompositeCommand is {@code false}.
|
||||
* Therefore, this method should only be used in case you want to explicitly edit the value.
|
||||
* @param onlyConsole {@code true} if this command should only be run in the console.
|
||||
* @since 1.24.0
|
||||
*/
|
||||
public void setOnlyConsole(boolean onlyConsole) {
|
||||
this.onlyConsole = onlyConsole;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets locale reference to this command's description.
|
||||
* It is used to display the help of this command.
|
||||
|
@ -623,16 +654,17 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
|||
@Override
|
||||
@NonNull
|
||||
public List<String> tabComplete(final @NonNull CommandSender sender, final @NonNull String alias, final String[] args) {
|
||||
List<String> options = new ArrayList<>();
|
||||
// Get command object based on args entered so far
|
||||
CompositeCommand command = getCommandFromArgs(args);
|
||||
// Check for console and permissions
|
||||
if (command.isOnlyPlayer() && !(sender instanceof Player)) {
|
||||
return options;
|
||||
if ((command.isOnlyPlayer() && !(sender instanceof Player))
|
||||
|| (command.isOnlyConsole() && sender instanceof Player)) {
|
||||
return List.of();
|
||||
}
|
||||
if (command.getPermission() != null && !command.getPermission().isEmpty() && !sender.hasPermission(command.getPermission()) && !sender.isOp()) {
|
||||
return options;
|
||||
return List.of();
|
||||
}
|
||||
List<String> options = new ArrayList<>();
|
||||
// Add any tab completion from the subcommand
|
||||
options.addAll(command.tabComplete(User.getInstance(sender), alias, new LinkedList<>(Arrays.asList(args))).orElseGet(ArrayList::new));
|
||||
if (command.hasSubCommands()) {
|
||||
|
@ -654,17 +686,26 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns a list containing all the labels of the subcommands for the provided CompositeCommand excluding any hidden commands
|
||||
* Returns a list containing all the labels of the subcommands for the provided
|
||||
* CompositeCommand excluding any hidden commands
|
||||
* @param sender the CommandSender
|
||||
* @param command the CompositeCommand to get the subcommands from
|
||||
* @return a list of subcommands labels or an empty list.
|
||||
*/
|
||||
@NonNull
|
||||
private List<String> getSubCommandLabels(@NonNull CommandSender sender, @NonNull CompositeCommand command) {
|
||||
return command.getSubCommands().values().stream()
|
||||
.filter(cmd -> !cmd.isHidden())
|
||||
.filter(cmd -> !cmd.isOnlyPlayer() || sender.isOp() || (sender instanceof Player && cmd.getPermission() != null && (cmd.getPermission().isEmpty() || sender.hasPermission(cmd.getPermission()))) )
|
||||
.map(CompositeCommand::getLabel).toList();
|
||||
List<String> result = new ArrayList<>();
|
||||
for (CompositeCommand cc: command.getSubCommands().values()) {
|
||||
// Player or not
|
||||
if (sender instanceof Player) {
|
||||
if (!cc.isHidden() && !cc.isOnlyConsole() && (cc.getPermission().isEmpty() || sender.hasPermission(cc.getPermission()))) {
|
||||
result.add(cc.getLabel());
|
||||
}
|
||||
} else if (!cc.isOnlyPlayer()) {
|
||||
result.add(cc.getLabel());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,7 +19,7 @@ public class AdminBlueprintCopyCommand extends CompositeCommand
|
|||
@Override
|
||||
public void setup()
|
||||
{
|
||||
inheritPermission();
|
||||
setPermission("admin.blueprint.copy");
|
||||
setParametersHelp("commands.admin.blueprint.copy.parameters");
|
||||
setDescription("commands.admin.blueprint.copy.description");
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public class AdminBlueprintCopyCommand extends CompositeCommand
|
|||
AdminBlueprintCommand parent = (AdminBlueprintCommand) getParent();
|
||||
|
||||
BlueprintClipboard clipboard =
|
||||
parent.getClipboards().computeIfAbsent(user.getUniqueId(), v -> new BlueprintClipboard());
|
||||
parent.getClipboards().computeIfAbsent(user.getUniqueId(), v -> new BlueprintClipboard());
|
||||
|
||||
boolean copyAir = args.stream().anyMatch(key -> key.equalsIgnoreCase("air"));
|
||||
boolean copyBiome = args.stream().anyMatch(key -> key.equalsIgnoreCase("biome"));
|
||||
|
|
|
@ -26,7 +26,7 @@ public class AdminBlueprintDeleteCommand extends ConfirmableCommand
|
|||
@Override
|
||||
public void setup()
|
||||
{
|
||||
this.inheritPermission();
|
||||
setPermission("admin.blueprint.delete");
|
||||
this.setParametersHelp("commands.admin.blueprint.delete.parameters");
|
||||
this.setDescription("commands.admin.blueprint.delete.description");
|
||||
}
|
||||
|
@ -47,10 +47,10 @@ public class AdminBlueprintDeleteCommand extends ConfirmableCommand
|
|||
if (this.getPlugin().getBlueprintsManager().getBlueprints(this.getAddon()).containsKey(blueprintName))
|
||||
{
|
||||
this.askConfirmation(user, user.getTranslation("commands.admin.blueprint.delete.confirmation"),
|
||||
() -> {
|
||||
this.getPlugin().getBlueprintsManager().deleteBlueprint(this.getAddon(), blueprintName);
|
||||
user.sendMessage("commands.admin.blueprint.delete.success", TextVariables.NAME, blueprintName);
|
||||
});
|
||||
() -> {
|
||||
this.getPlugin().getBlueprintsManager().deleteBlueprint(this.getAddon(), blueprintName);
|
||||
user.sendMessage("commands.admin.blueprint.delete.success", TextVariables.NAME, blueprintName);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -22,7 +22,7 @@ public class AdminBlueprintListCommand extends CompositeCommand
|
|||
@Override
|
||||
public void setup()
|
||||
{
|
||||
this.inheritPermission();
|
||||
setPermission("admin.blueprint.list");
|
||||
this.setDescription("commands.admin.blueprint.list.description");
|
||||
}
|
||||
|
||||
|
@ -54,8 +54,8 @@ public class AdminBlueprintListCommand extends CompositeCommand
|
|||
FilenameFilter blueprintFilter = (File dir, String name) -> name.endsWith(BlueprintsManager.BLUEPRINT_SUFFIX);
|
||||
|
||||
List<String> blueprintList = Arrays.stream(Objects.requireNonNull(blueprints.list(blueprintFilter))).
|
||||
map(name -> name.substring(0, name.length() - BlueprintsManager.BLUEPRINT_SUFFIX.length())).
|
||||
toList();
|
||||
map(name -> name.substring(0, name.length() - BlueprintsManager.BLUEPRINT_SUFFIX.length())).
|
||||
toList();
|
||||
|
||||
if (blueprintList.isEmpty())
|
||||
{
|
||||
|
|
|
@ -17,7 +17,7 @@ public class AdminBlueprintLoadCommand extends CompositeCommand {
|
|||
|
||||
@Override
|
||||
public void setup() {
|
||||
inheritPermission();
|
||||
setPermission("admin.blueprint.load");
|
||||
setParametersHelp("commands.admin.blueprint.load.parameters");
|
||||
setDescription("commands.admin.blueprint.load.description");
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ public class AdminBlueprintOriginCommand extends CompositeCommand {
|
|||
|
||||
@Override
|
||||
public void setup() {
|
||||
inheritPermission();
|
||||
setPermission("admin.blueprint.origin");
|
||||
setParametersHelp("commands.admin.blueprint.origin.parameters");
|
||||
setDescription("commands.admin.blueprint.origin.description");
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ public class AdminBlueprintPasteCommand extends CompositeCommand {
|
|||
|
||||
@Override
|
||||
public void setup() {
|
||||
inheritPermission();
|
||||
setPermission("admin.blueprint.paste");
|
||||
setParametersHelp("commands.admin.blueprint.paste.parameters");
|
||||
setDescription("commands.admin.blueprint.paste.description");
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ public class AdminBlueprintPos1Command extends CompositeCommand {
|
|||
|
||||
@Override
|
||||
public void setup() {
|
||||
inheritPermission();
|
||||
setPermission("admin.blueprint.pos1");
|
||||
setParametersHelp("commands.admin.blueprint.pos1.parameters");
|
||||
setDescription("commands.admin.blueprint.pos1.description");
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ public class AdminBlueprintPos2Command extends CompositeCommand {
|
|||
|
||||
@Override
|
||||
public void setup() {
|
||||
inheritPermission();
|
||||
setPermission("admin.blueprint.pos2");
|
||||
setParametersHelp("commands.admin.blueprint.pos2.parameters");
|
||||
setDescription("commands.admin.blueprint.pos2.description");
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ public class AdminBlueprintRenameCommand extends ConfirmableCommand
|
|||
@Override
|
||||
public void setup()
|
||||
{
|
||||
this.inheritPermission();
|
||||
setPermission("admin.blueprint.rename");
|
||||
this.setParametersHelp("commands.admin.blueprint.rename.parameters");
|
||||
this.setDescription("commands.admin.blueprint.rename.description");
|
||||
}
|
||||
|
@ -83,8 +83,8 @@ public class AdminBlueprintRenameCommand extends ConfirmableCommand
|
|||
{
|
||||
// Ask for confirmation to overwrite
|
||||
this.askConfirmation(user,
|
||||
user.getTranslation("commands.admin.blueprint.file-exists"),
|
||||
() -> this.rename(user, from, to, args.get(1)));
|
||||
user.getTranslation("commands.admin.blueprint.file-exists"),
|
||||
() -> this.rename(user, from, to, args.get(1)));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -102,11 +102,11 @@ public class AdminBlueprintRenameCommand extends ConfirmableCommand
|
|||
this.getPlugin().getBlueprintsManager().renameBlueprint(this.getAddon(), blueprint, fileName, displayName);
|
||||
|
||||
user.sendMessage("commands.admin.blueprint.rename.success",
|
||||
"[old]",
|
||||
blueprintName,
|
||||
TextVariables.NAME,
|
||||
blueprint.getName(),
|
||||
"[display]",
|
||||
blueprint.getDisplayName());
|
||||
"[old]",
|
||||
blueprintName,
|
||||
TextVariables.NAME,
|
||||
blueprint.getName(),
|
||||
"[display]",
|
||||
blueprint.getDisplayName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ public class AdminBlueprintSaveCommand extends ConfirmableCommand
|
|||
@Override
|
||||
public void setup()
|
||||
{
|
||||
this.inheritPermission();
|
||||
setPermission("admin.blueprint.save");
|
||||
this.setParametersHelp("commands.admin.blueprint.save.parameters");
|
||||
this.setDescription("commands.admin.blueprint.save.description");
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public class AdminDeathsAddCommand extends CompositeCommand {
|
|||
|
||||
@Override
|
||||
public void setup() {
|
||||
inheritPermission();
|
||||
setPermission("admin.deaths.add");
|
||||
setDescription("commands.admin.deaths.add.description");
|
||||
setParametersHelp("commands.admin.deaths.add.parameters");
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public class AdminDeathsRemoveCommand extends CompositeCommand {
|
|||
|
||||
@Override
|
||||
public void setup() {
|
||||
inheritPermission();
|
||||
setPermission("admin.deaths.remove");
|
||||
setDescription("commands.admin.deaths.remove.description");
|
||||
setParametersHelp("commands.admin.deaths.remove.parameters");
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ public class AdminDeathsResetCommand extends CompositeCommand {
|
|||
|
||||
@Override
|
||||
public void setup() {
|
||||
inheritPermission();
|
||||
setPermission("admin.deaths.reset");
|
||||
setDescription("commands.admin.deaths.reset.description");
|
||||
setParametersHelp("commands.admin.deaths.reset.parameters");
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ public class AdminDeathsSetCommand extends CompositeCommand {
|
|||
|
||||
@Override
|
||||
public void setup() {
|
||||
inheritPermission();
|
||||
setPermission("admin.deaths.set");
|
||||
setDescription("commands.admin.deaths.set.description");
|
||||
setParametersHelp("commands.admin.deaths.set.parameters");
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ public class AdminPurgeProtectCommand extends CompositeCommand {
|
|||
|
||||
@Override
|
||||
public void setup() {
|
||||
inheritPermission();
|
||||
setPermission("admin.purge.protect");
|
||||
setOnlyPlayer(true);
|
||||
setDescription("commands.admin.purge.protect.description");
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ public class AdminPurgeStatusCommand extends CompositeCommand {
|
|||
|
||||
@Override
|
||||
public void setup() {
|
||||
inheritPermission();
|
||||
setPermission("admin.purge.status");
|
||||
setOnlyPlayer(false);
|
||||
setParametersHelp("commands.admin.purge.status.parameters");
|
||||
setDescription("commands.admin.purge.status.description");
|
||||
|
|
|
@ -13,7 +13,7 @@ public class AdminPurgeStopCommand extends CompositeCommand {
|
|||
|
||||
@Override
|
||||
public void setup() {
|
||||
inheritPermission();
|
||||
setPermission("admin.purge.stop");
|
||||
setOnlyPlayer(false);
|
||||
setDescription("commands.admin.purge.stop.description");
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ public class AdminPurgeUnownedCommand extends ConfirmableCommand {
|
|||
|
||||
@Override
|
||||
public void setup() {
|
||||
inheritPermission();
|
||||
setPermission("admin.purge.unowned");
|
||||
setOnlyPlayer(false);
|
||||
setParametersHelp("commands.admin.purge.unowned.parameters");
|
||||
setDescription("commands.admin.purge.unowned.description");
|
||||
|
|
|
@ -25,7 +25,7 @@ public class AdminRangeAddCommand extends CompositeCommand {
|
|||
|
||||
@Override
|
||||
public void setup() {
|
||||
inheritPermission();
|
||||
setPermission("admin.range.add");
|
||||
setDescription("commands.admin.range.add.description");
|
||||
setParametersHelp("commands.admin.range.add.parameters");
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ public class AdminRangeRemoveCommand extends CompositeCommand {
|
|||
|
||||
@Override
|
||||
public void setup() {
|
||||
inheritPermission();
|
||||
setPermission("admin.range.remove");
|
||||
setDescription("commands.admin.range.remove.description");
|
||||
setParametersHelp("commands.admin.range.remove.parameters");
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public class AdminResetsAddCommand extends CompositeCommand {
|
|||
|
||||
@Override
|
||||
public void setup() {
|
||||
inheritPermission();
|
||||
setPermission("admin.resets.add");
|
||||
setDescription("commands.admin.resets.add.description");
|
||||
setParametersHelp("commands.admin.resets.add.parameters");
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public class AdminResetsRemoveCommand extends CompositeCommand {
|
|||
|
||||
@Override
|
||||
public void setup() {
|
||||
inheritPermission();
|
||||
setPermission("admin.resets.remove");
|
||||
setDescription("commands.admin.resets.remove.description");
|
||||
setParametersHelp("commands.admin.resets.remove.parameters");
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public class AdminResetsResetCommand extends ConfirmableCommand {
|
|||
|
||||
@Override
|
||||
public void setup() {
|
||||
inheritPermission();
|
||||
setPermission("admin.resets.remove");
|
||||
setDescription("commands.admin.resets.reset.description");
|
||||
setParametersHelp("commands.admin.resets.reset.parameters");
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ public class AdminResetsSetCommand extends CompositeCommand {
|
|||
|
||||
@Override
|
||||
public void setup() {
|
||||
inheritPermission();
|
||||
setPermission("admin.resets.set");
|
||||
setDescription("commands.admin.resets.set.description");
|
||||
setParametersHelp("commands.admin.resets.set.parameters");
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ public class AdminTeamAddCommand extends CompositeCommand {
|
|||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("mod.team");
|
||||
setPermission("mod.team.add");
|
||||
setParametersHelp("commands.admin.team.add.parameters");
|
||||
setDescription("commands.admin.team.add.description");
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ public class AdminTeamDisbandCommand extends CompositeCommand {
|
|||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("mod.team");
|
||||
setPermission("mod.team.disband");
|
||||
setParametersHelp("commands.admin.team.disband.parameters");
|
||||
setDescription("commands.admin.team.disband.description");
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ public class AdminTeamFixCommand extends CompositeCommand {
|
|||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("mod.team");
|
||||
setPermission("mod.team.fix");
|
||||
setDescription("commands.admin.team.fix.description");
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ public class AdminTeamKickCommand extends CompositeCommand {
|
|||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("mod.team");
|
||||
setPermission("mod.team.kick");
|
||||
setParametersHelp("commands.admin.team.kick.parameters");
|
||||
setDescription("commands.admin.team.kick.description");
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ public class AdminTeamSetownerCommand extends CompositeCommand {
|
|||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("mod.team");
|
||||
setPermission("mod.team.setowner");
|
||||
setParametersHelp("commands.admin.team.setowner.parameters");
|
||||
setDescription("commands.admin.team.setowner.description");
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public class BentoBoxAboutCommand extends CompositeCommand {
|
|||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
user.sendRawMessage("About " + BentoBox.getInstance().getDescription().getName() + " v" + BentoBox.getInstance().getDescription().getVersion() + ":");
|
||||
user.sendRawMessage("Copyright (c) 2017 - 2021 Tastybento, Poslovitch and the BentoBoxWorld contributors");
|
||||
user.sendRawMessage("Copyright (c) 2017 - 2023 Tastybento, Poslovitch and the BentoBoxWorld contributors");
|
||||
user.sendRawMessage("See https://www.eclipse.org/legal/epl-2.0/ for license information.");
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ public class BentoBoxCommand extends CompositeCommand {
|
|||
new BentoBoxReloadCommand(this);
|
||||
new BentoBoxLocaleCommand(this);
|
||||
new BentoBoxHelpCommand(this);
|
||||
new BentoBoxPermsCommand(this);
|
||||
// Database names with a 2 in them are migration databases
|
||||
if (getPlugin().getSettings().getDatabaseType().name().contains("2")) {
|
||||
new BentoBoxMigrateCommand(this);
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
package world.bentobox.bentobox.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.permissions.Permission;
|
||||
|
||||
import world.bentobox.bentobox.api.addons.GameModeAddon;
|
||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
|
||||
/**
|
||||
* Displays permissions that have been set by BentoBox.
|
||||
*
|
||||
* @author tastybento
|
||||
*/
|
||||
public class BentoBoxPermsCommand extends CompositeCommand {
|
||||
|
||||
/**
|
||||
* Info command
|
||||
* @param parent - command parent
|
||||
*/
|
||||
public BentoBoxPermsCommand(CompositeCommand parent) {
|
||||
super(parent, "perms");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
setPermission("bentobox.perms");
|
||||
this.isOnlyConsole();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
// Loop all the known top-level commands
|
||||
getPlugin().getCommandsManager().getCommands().values().stream().distinct().forEach(cc -> {
|
||||
if (cc.getAddon() == null) {
|
||||
user.sendMessage("*** BentoBox effective perms:");
|
||||
} else if (cc.getAddon() instanceof GameModeAddon gma) {
|
||||
user.sendRawMessage("**** " + gma.getDescription().getName() + " effective perms:");
|
||||
} else {
|
||||
user.sendRawMessage("**** " + cc.getAddon().getDescription().getName() + " effective perms:");
|
||||
}
|
||||
user.sendRawMessage("permissions:");
|
||||
printData(user, cc, cc.getLabel());
|
||||
printSubCommandData(user, cc, cc.getLabel());
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
private void printData(User user, CompositeCommand cc, String label) {
|
||||
if (cc.getPermission().isBlank()) return;
|
||||
String desc = user.getTranslation(cc.getWorld(), cc.getDescription());
|
||||
user.sendRawMessage(" " + cc.getPermission() + ":");
|
||||
user.sendRawMessage(" description: Allow use of '/" + label + "' command - " + desc);
|
||||
Permission p = Bukkit.getPluginManager().getPermission(cc.getPermission());
|
||||
if (p != null) {
|
||||
user.sendRawMessage(" default: " + p.getDefault().name());
|
||||
} else {
|
||||
user.sendRawMessage(" default: OP"); // If not def
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterates over sub-commands
|
||||
* @param user user
|
||||
* @param parent parent command
|
||||
* @param label
|
||||
*/
|
||||
private void printSubCommandData(User user, CompositeCommand parent, String label) {
|
||||
for (CompositeCommand cc : parent.getSubCommands().values()) {
|
||||
if (cc.getLabel().equalsIgnoreCase("help")) continue; // Ignore the help command
|
||||
String newLabel = label + " " + cc.getLabel();
|
||||
printData(user, cc, newLabel);
|
||||
printSubCommandData(user, cc, newLabel);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -21,6 +21,7 @@ general:
|
|||
no-permission: "&c You don't have the permission to execute this command (&7 [permission]&c )."
|
||||
insufficient-rank: "&c Your rank is not high enough to do that! (&7 [rank]&c )"
|
||||
use-in-game: "&c This command is only available in-game."
|
||||
use-in-console: "&c This command is only available in the console."
|
||||
no-team: "&c You do not have a team!"
|
||||
no-island: "&c You do not have an island!"
|
||||
player-has-island: "&c Player already has an island!"
|
||||
|
@ -428,6 +429,8 @@ commands:
|
|||
success: "&a Successfully reset [name]'s island name."
|
||||
bentobox:
|
||||
description: "BentoBox admin command"
|
||||
perms:
|
||||
description: "displays the effective perms for BentoBox and Addons in a YAML format"
|
||||
about:
|
||||
description: "displays copyright and license information"
|
||||
reload:
|
||||
|
|
Loading…
Reference in New Issue