From cf11743a446e7f98f22385563660f278369382dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beatrice=20Dellac=C3=A0?= Date: Mon, 24 Oct 2022 22:48:16 +0200 Subject: [PATCH] Implement basic permissions system --- .../subcommands/NounsCreateSubCommand.java | 8 +++++++ .../subcommands/NounsDeleteSubCommand.java | 8 +++++++ .../subcommands/NounsListSubCommand.java | 8 +++++++ .../subcommands/NounsSetSubCommand.java | 8 +++++++ .../subcommands/NounsUpdateSubCmd.java | 8 +++++++ .../nounspicker/objects/Permission.java | 21 +++++++++++++++++++ .../nounspicker/utils/PermissionManager.java | 13 ++++++++++++ 7 files changed, 74 insertions(+) create mode 100644 src/main/java/wtf/beatrice/nounspicker/objects/Permission.java create mode 100644 src/main/java/wtf/beatrice/nounspicker/utils/PermissionManager.java diff --git a/src/main/java/wtf/beatrice/nounspicker/commands/subcommands/NounsCreateSubCommand.java b/src/main/java/wtf/beatrice/nounspicker/commands/subcommands/NounsCreateSubCommand.java index 8066a36..896b026 100644 --- a/src/main/java/wtf/beatrice/nounspicker/commands/subcommands/NounsCreateSubCommand.java +++ b/src/main/java/wtf/beatrice/nounspicker/commands/subcommands/NounsCreateSubCommand.java @@ -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 "); diff --git a/src/main/java/wtf/beatrice/nounspicker/commands/subcommands/NounsDeleteSubCommand.java b/src/main/java/wtf/beatrice/nounspicker/commands/subcommands/NounsDeleteSubCommand.java index 2a2be1f..514a7bf 100644 --- a/src/main/java/wtf/beatrice/nounspicker/commands/subcommands/NounsDeleteSubCommand.java +++ b/src/main/java/wtf/beatrice/nounspicker/commands/subcommands/NounsDeleteSubCommand.java @@ -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 "); return true; diff --git a/src/main/java/wtf/beatrice/nounspicker/commands/subcommands/NounsListSubCommand.java b/src/main/java/wtf/beatrice/nounspicker/commands/subcommands/NounsListSubCommand.java index 3a29aa1..14872c6 100644 --- a/src/main/java/wtf/beatrice/nounspicker/commands/subcommands/NounsListSubCommand.java +++ b/src/main/java/wtf/beatrice/nounspicker/commands/subcommands/NounsListSubCommand.java @@ -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); diff --git a/src/main/java/wtf/beatrice/nounspicker/commands/subcommands/NounsSetSubCommand.java b/src/main/java/wtf/beatrice/nounspicker/commands/subcommands/NounsSetSubCommand.java index b5c0aef..11d47b3 100644 --- a/src/main/java/wtf/beatrice/nounspicker/commands/subcommands/NounsSetSubCommand.java +++ b/src/main/java/wtf/beatrice/nounspicker/commands/subcommands/NounsSetSubCommand.java @@ -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
"); diff --git a/src/main/java/wtf/beatrice/nounspicker/commands/subcommands/NounsUpdateSubCmd.java b/src/main/java/wtf/beatrice/nounspicker/commands/subcommands/NounsUpdateSubCmd.java index 5335900..9ba66ee 100644 --- a/src/main/java/wtf/beatrice/nounspicker/commands/subcommands/NounsUpdateSubCmd.java +++ b/src/main/java/wtf/beatrice/nounspicker/commands/subcommands/NounsUpdateSubCmd.java @@ -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) { diff --git a/src/main/java/wtf/beatrice/nounspicker/objects/Permission.java b/src/main/java/wtf/beatrice/nounspicker/objects/Permission.java new file mode 100644 index 0000000..2be3d06 --- /dev/null +++ b/src/main/java/wtf/beatrice/nounspicker/objects/Permission.java @@ -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; + } + +} diff --git a/src/main/java/wtf/beatrice/nounspicker/utils/PermissionManager.java b/src/main/java/wtf/beatrice/nounspicker/utils/PermissionManager.java new file mode 100644 index 0000000..4ad071a --- /dev/null +++ b/src/main/java/wtf/beatrice/nounspicker/utils/PermissionManager.java @@ -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()); + } +}