Skip to content

Commit

Permalink
Automatically generate permissions for subcommands
Browse files Browse the repository at this point in the history
This commit changed permissions for EnableCommand and DisableCommand
from enable and disable to on and off respectively.
  • Loading branch information
voidpointer0x00 committed Apr 15, 2023
1 parent b9dd14f commit d7d0f93
Show file tree
Hide file tree
Showing 13 changed files with 6 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@

public final class AddCommand extends Command {
public static final String NAME = "add";
public static final String PERMISSION = "whitelist.add";
public static final int MIN_ARGS = 1;

@AutowiredLocale private static LocaleLog locale;
Expand All @@ -57,7 +56,6 @@ public final class AddCommand extends Command {
public AddCommand() {
super(NAME);
super.setRequiredArgsNumber(MIN_ARGS);
super.setPermission(PERMISSION);
super.addOptions(UuidOptions.values());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@

public final class DisableCommand extends Command {
public static final String NAME = "off";
public static final String PERMISSION = "whitelist.disable";

@AutowiredLocale private static Locale locale;
@Autowired private static WhitelistConfig whitelistConfig;
@Autowired private static EventManager eventManager;

public DisableCommand() {
super(NAME);
super.setPermission(PERMISSION);
}

@Override public void execute(final Args args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@

public final class EnableCommand extends Command {
public static final String NAME = "on";
public static final String PERMISSION = "whitelist.enable";

@AutowiredLocale private static Locale locale;
@Autowired private static WhitelistConfig whitelistConfig;
@Autowired private static EventManager eventManager;

public EnableCommand() {
super(NAME);
super.setPermission(PERMISSION);
}

@Override public void execute(final Args args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

public class ExportCommand extends Command {
public static final String NAME = "export-db";
public static final String PERMISSION = "whitelist.export";

@AutowiredLocale private static LocaleLog localeLog;
@Autowired(mapId="plugin") private static Plugin plugin;
Expand All @@ -31,7 +30,6 @@ public class ExportCommand extends Command {

public ExportCommand() {
super(NAME);
super.setPermission(PERMISSION);
}

@Override public void execute(final Args args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@

public final class GuiCommand extends Command {
private static final String NAME = "gui";
private static final String PERMISSION = "whitelist.gui";

@AutowiredLocale private static Locale locale;
@Autowired(mapId="whitelistService")
private static WhitelistService whitelistService;

public GuiCommand() {
super(NAME);
super.setPermission(PERMISSION);
}

@Override public void execute(final Args args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@

final class HelpCommand extends Command {
public static final String NAME = "help";
public static final String PERMISSION = "whitelist.help";

@AutowiredLocale private static Locale locale;

public HelpCommand() {
super(NAME);
setPermission(PERMISSION);
}

@Override public void execute(final Args args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@

public class ImportJsonCommand extends Command {
public static final String NAME = "import-json";
public static final String PERMISSION = "whitelist.import";

@AutowiredLocale private static Locale locale;
@Autowired private static EventManager eventManager;
Expand All @@ -54,7 +53,6 @@ public class ImportJsonCommand extends Command {

public ImportJsonCommand() {
super(NAME);
super.setPermission(PERMISSION);
super.addOptions(ImportOptions.values());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,13 @@

public final class InfoCommand extends Command {
public static final String NAME = "info";
public static final String PERMISSION = "whitelist.info";

@AutowiredLocale private static LocaleLog locale;
@Autowired(mapId="whitelistService")
private static WhitelistService whitelistService;

public InfoCommand() {
super(NAME);
super.setPermission(PERMISSION);
super.addOptions(UuidOptions.values());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

public final class ReconnectCommand extends Command {
public static final String NAME = "reconnect";
public static final String PERMISSION = "whitelist.reconnect";

@AutowiredLocale private static Locale locale;
@Autowired(mapId="whitelistService")
Expand All @@ -23,7 +22,6 @@ public final class ReconnectCommand extends Command {

public ReconnectCommand() {
super(NAME);
super.setPermission(PERMISSION);
}

@Override public void execute(final Args args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

public final class ReloadCommand extends Command {
public static final String NAME = "reload";
public static final String PERMISSION = "whitelist.reload";

@AutowiredLocale private static Locale locale;
@Autowired private static LocaleLog guiLocale;
Expand All @@ -38,7 +37,6 @@ public final class ReloadCommand extends Command {

public ReloadCommand() {
super(NAME);
setPermission(PERMISSION);
}

@Override public void execute(final Args args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
public class RemoveCommand extends Command {
public static final String NAME = "remove";
public static final List<String> ALIASES = singletonList("rem");
public static final String PERMISSION = "whitelist.remove";
public static final Integer MIN_ARGS = 1;

@AutowiredLocale private static LocaleLog locale;
Expand All @@ -54,7 +53,6 @@ public class RemoveCommand extends Command {

public RemoveCommand() {
super(NAME);
super.setPermission(PERMISSION);
super.setRequiredArgsNumber(MIN_ARGS);
super.addOptions(UuidOptions.values());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@

public final class StatusCommand extends Command {
public static final String NAME = "status";
public static final String PERMISSION = "whitelist.status";

@AutowiredLocale private static Locale locale;
@Autowired private static WhitelistConfig config;

public StatusCommand() {
super(NAME);
setPermission(PERMISSION);
}

@Override public void execute(final Args args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public final class WhitelistCommand extends Command {
public WhitelistCommand() {
super(NAME);

super.setPermission("voidwhitelist." + NAME);
super.setRequiredArgsNumber(MIN_REQUIRED_ARGS);

whitelistCommands.addCommand(new AddCommand());
whitelistCommands.addCommand(new RemoveCommand());
whitelistCommands.addCommand(new EnableCommand());
Expand All @@ -47,7 +50,9 @@ public WhitelistCommand() {
whitelistCommands.addCommand(new HelpCommand());
whitelistCommands.addCommand(new ReloadCommand());
whitelistCommands.addCommand(new ReconnectCommand());
super.setRequiredArgsNumber(MIN_REQUIRED_ARGS);

whitelistCommands.getCommands().values()
.forEach(cmd -> cmd.setPermission(getPermission() + "." + cmd.getName()));
}

@Override public void execute(final Args args) {
Expand Down

0 comments on commit d7d0f93

Please sign in to comment.