Implement basic permissions system
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
6298697169
commit
cf11743a44
@ -2,7 +2,9 @@ package wtf.beatrice.nounspicker.commands.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import wtf.beatrice.nounspicker.objects.Permission;
|
||||
import wtf.beatrice.nounspicker.utils.Cache;
|
||||
import wtf.beatrice.nounspicker.utils.PermissionManager;
|
||||
|
||||
public class NounsCreateSubCommand
|
||||
{
|
||||
@ -11,6 +13,12 @@ public class NounsCreateSubCommand
|
||||
@NotNull String[] args)
|
||||
{
|
||||
|
||||
if(!PermissionManager.hasPermission(sender, Permission.NOUNS_CREATE))
|
||||
{
|
||||
sender.sendMessage("No permission!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(args.length < 3)
|
||||
{
|
||||
sender.sendMessage("usage: /nouns create <pronoun> <format>");
|
||||
|
@ -2,7 +2,9 @@ package wtf.beatrice.nounspicker.commands.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import wtf.beatrice.nounspicker.objects.Permission;
|
||||
import wtf.beatrice.nounspicker.utils.Cache;
|
||||
import wtf.beatrice.nounspicker.utils.PermissionManager;
|
||||
|
||||
public class NounsDeleteSubCommand
|
||||
{
|
||||
@ -10,6 +12,12 @@ public class NounsDeleteSubCommand
|
||||
public static boolean run(@NotNull CommandSender sender,
|
||||
@NotNull String[] args)
|
||||
{
|
||||
if(!PermissionManager.hasPermission(sender, Permission.NOUNS_DELETE))
|
||||
{
|
||||
sender.sendMessage("No permission!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(args.length < 2) {
|
||||
sender.sendMessage("usage: /nouns delete <pronoun>");
|
||||
return true;
|
||||
|
@ -2,7 +2,9 @@ package wtf.beatrice.nounspicker.commands.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import wtf.beatrice.nounspicker.objects.Permission;
|
||||
import wtf.beatrice.nounspicker.utils.Cache;
|
||||
import wtf.beatrice.nounspicker.utils.PermissionManager;
|
||||
|
||||
public class NounsListSubCommand
|
||||
{
|
||||
@ -12,6 +14,12 @@ public class NounsListSubCommand
|
||||
public static boolean run(@NotNull CommandSender sender)
|
||||
{
|
||||
|
||||
if(!PermissionManager.hasPermission(sender, Permission.NOUNS_LIST))
|
||||
{
|
||||
sender.sendMessage("No permission!");
|
||||
return false;
|
||||
}
|
||||
|
||||
sender.sendMessage("Pronouns List:");
|
||||
for(int i = 0; i < Cache.pronouns.size(); i++) {
|
||||
String pronoun = Cache.pronouns.get(i);
|
||||
|
@ -2,7 +2,9 @@ package wtf.beatrice.nounspicker.commands.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import wtf.beatrice.nounspicker.objects.Permission;
|
||||
import wtf.beatrice.nounspicker.utils.Cache;
|
||||
import wtf.beatrice.nounspicker.utils.PermissionManager;
|
||||
|
||||
public class NounsSetSubCommand
|
||||
{
|
||||
@ -10,6 +12,12 @@ public class NounsSetSubCommand
|
||||
@NotNull String[] args)
|
||||
{
|
||||
|
||||
if(!PermissionManager.hasPermission(sender, Permission.NOUNS_SET))
|
||||
{
|
||||
sender.sendMessage("No permission!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(args.length < 3)
|
||||
{
|
||||
sender.sendMessage("usage: /nouns set <main> <secondary>");
|
||||
|
@ -2,7 +2,9 @@ package wtf.beatrice.nounspicker.commands.subcommands;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import wtf.beatrice.nounspicker.objects.Permission;
|
||||
import wtf.beatrice.nounspicker.utils.Cache;
|
||||
import wtf.beatrice.nounspicker.utils.PermissionManager;
|
||||
|
||||
public class NounsUpdateSubCmd
|
||||
{
|
||||
@ -10,6 +12,12 @@ public class NounsUpdateSubCmd
|
||||
|
||||
public static boolean run(@NotNull CommandSender sender,
|
||||
@NotNull String[] args) {
|
||||
|
||||
if(!PermissionManager.hasPermission(sender, Permission.NOUNS_UPDATE))
|
||||
{
|
||||
sender.sendMessage("No permission!");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (args.length < 3) {
|
||||
|
@ -0,0 +1,21 @@
|
||||
package wtf.beatrice.nounspicker.objects;
|
||||
|
||||
public enum Permission {
|
||||
|
||||
NOUNS_SET("nouns.set"),
|
||||
NOUNS_LIST("nouns.list"),
|
||||
NOUNS_CREATE("nouns.create"),
|
||||
NOUNS_DELETE("nouns.delete"),
|
||||
NOUNS_UPDATE("nouns.update");
|
||||
|
||||
|
||||
private String perm;
|
||||
Permission(String perm) {
|
||||
this.perm = perm;
|
||||
}
|
||||
|
||||
public String getPerm() {
|
||||
return perm;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package wtf.beatrice.nounspicker.utils;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import wtf.beatrice.nounspicker.objects.Permission;
|
||||
|
||||
public class PermissionManager
|
||||
{
|
||||
|
||||
public static boolean hasPermission(CommandSender sender, Permission permission)
|
||||
{
|
||||
return sender.hasPermission(permission.getPerm());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user