Implement basic permissions system
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Bea 2022-10-24 22:48:16 +02:00
parent 6298697169
commit cf11743a44
7 changed files with 74 additions and 0 deletions

View File

@ -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>");

View File

@ -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;

View File

@ -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);

View File

@ -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>");

View File

@ -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
{
@ -11,6 +13,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) {
sender.sendMessage("usage: /nouns update <pronoun> <format>");

View File

@ -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;
}
}

View File

@ -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());
}
}