Skip to content

Commit

Permalink
Merge pull request #164 from dmccoystephenson/permissions
Browse files Browse the repository at this point in the history
Implemented permission handling in CommandInterpreter.java and added permission defaults to the plugin.yml file
  • Loading branch information
dmccoystephenson authored Aug 2, 2021
2 parents d53af64 + 88f61e2 commit a21dd02
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/main/java/dansplugins/wildpets/CommandInterpreter.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,56 +17,67 @@ public boolean interpretCommand(CommandSender sender, String label, String[] arg
String[] arguments = getArguments(args);

if (secondaryLabel.equalsIgnoreCase("help")) {
checkPermission(sender, "wp.help");
HelpCommand command = new HelpCommand();
return command.execute(sender);
}

if (secondaryLabel.equalsIgnoreCase("tame")) {
checkPermission(sender, "wp.tame");
TameCommand command = new TameCommand();
return command.execute(sender, arguments);
}

if (secondaryLabel.equalsIgnoreCase("select")) {
checkPermission(sender, "wp.select");
SelectCommand command = new SelectCommand();
return command.execute(sender, arguments);
}

if (secondaryLabel.equalsIgnoreCase("rename")) {
checkPermission(sender, "wp.rename");
RenameCommand command = new RenameCommand();
return command.execute(sender, arguments);
}

if (secondaryLabel.equalsIgnoreCase("info")) {
checkPermission(sender, "wp.info");
InfoCommand command = new InfoCommand();
return command.execute(sender);
}

if (secondaryLabel.equalsIgnoreCase("stay")) {
checkPermission(sender, "wp.stay");
StayCommand command = new StayCommand();
return command.execute(sender);
}

if (secondaryLabel.equalsIgnoreCase("wander")) {
checkPermission(sender, "wp.wander");
WanderCommand command = new WanderCommand();
return command.execute(sender);
}

if (secondaryLabel.equalsIgnoreCase("list")) {
checkPermission(sender, "wp.list");
ListCommand command = new ListCommand();
return command.execute(sender);
}

if (secondaryLabel.equalsIgnoreCase("call")) {
checkPermission(sender, "wp.call");
CallCommand command = new CallCommand();
return command.execute(sender);
}

if (secondaryLabel.equalsIgnoreCase("setfree")) {
checkPermission(sender, "wp.setfree");
SetFreeCommand command = new SetFreeCommand();
return command.execute(sender);
}

if (secondaryLabel.equalsIgnoreCase("locate")) {
checkPermission(sender, "wp.locate");
LocateCommand command = new LocateCommand();
return command.execute(sender);
}
Expand All @@ -87,4 +98,10 @@ private String[] getArguments(String[] args) {
return toReturn;
}

private void checkPermission(CommandSender sender, String permission) {
if (!sender.hasPermission(permission)) {
sender.sendMessage(ChatColor.RED + "In order to use this command, you need the following permission: '" + permission + "'");
}
}

}
26 changes: 25 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,28 @@ api-version: 1.13

commands:
wildpets:
wp:
wp:

permissions:
wp.help:
default: true
wp.tame:
default: true
wp.select:
default: true
wp.rename:
default: true
wp.info:
default: true
wp.stay:
default: true
wp.wander:
default: true
wp.list:
default: true
wp.call:
default: true
wp.setfree:
default: true
wp.locate:
default: true

0 comments on commit a21dd02

Please sign in to comment.