diff --git a/README.md b/README.md index 20f9c0e..b883a35 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@
  • Player Join
  • Player Quit
  • Commands
  • +
  • Permissions
  • Configuration Files
  • @@ -112,10 +113,20 @@ When a player quits, BotBlocker calculates the duration of their connection. If * `/BotBlocker setBanMessage [message]` - Set the ban message. * `/BotBlocker getBanMessage` - Display the configured ban message. +### Permissions +* `botblocker.enable` - Allows the user to enable the BotBlocker plugin +* `botblocker.disable` - Allows the user to disable the BotBlocker plugin. +* `botblocker.status` - Allows the user to see whether BotBlocker is enabled or disabled. +* `botblocker.settimelimit` - Allows the user to set the time limit for detecting bots. +* `botblocker.gettimelimit` - Allows the user to display the configured time limit for detecting bots. +* `botblocker.setbanmessage` - Allows the user to set the ban message. +* `botblocker.getbanmessage` - Allows the user to display the configured ban message. + ### Configuration Files BotBlocker maintains its configuration and the list of player UUIDs in `config.yml` and `players.yml` files, respectively. -Note: Players identified as legitimate are marked as such in the `players.yml` file and are not checked again in the future. If BotBlocker is disabled, it stops checking players for potential bot activity. +> [!NOTE] +> Players identified as legitimate are marked as such in the `players.yml` file and are not checked again in the future. If BotBlocker is disabled, it stops checking players for potential bot activity.

    (back to top)

    diff --git a/src/main/java/ovh/aichan/botblockerminecraft/CommandHandler.java b/src/main/java/ovh/aichan/botblockerminecraft/CommandHandler.java index 70a747d..17316ae 100644 --- a/src/main/java/ovh/aichan/botblockerminecraft/CommandHandler.java +++ b/src/main/java/ovh/aichan/botblockerminecraft/CommandHandler.java @@ -14,11 +14,27 @@ public CommandHandler(BotBlocker plugin) { this.plugin = plugin; } + /** + * Handle the command. + * @param sender Command sender + * @param permission Permission as defined in plugin.yml + * @return true if the command was handled, false otherwise + */ + private boolean hasPermission(CommandSender sender, String permission) { + if(sender.hasPermission(permission)) { + return true; + } else { + sender.sendMessage("You don't have permission to use this command."); + return false; + } + } + /** * Enable the BotBlocker plugin. * @param sender Command sender */ public void enable(CommandSender sender) { + if (!hasPermission(sender, "botblocker.enable")) return; plugin.setPluginEnabled(true); sender.sendMessage("BotBlocker enabled."); plugin.saveConfig(); @@ -29,6 +45,7 @@ public void enable(CommandSender sender) { * @param sender Command sender */ public void disable(CommandSender sender) { + if (!hasPermission(sender, "botblocker.disable")) return; plugin.setPluginEnabled(false); sender.sendMessage("BotBlocker disabled."); plugin.saveConfig(); @@ -39,6 +56,7 @@ public void disable(CommandSender sender) { * @param sender Command sender */ public void status(CommandSender sender) { + if (!hasPermission(sender, "botblocker.status")) return; sender.sendMessage("BotBlocker status: " + (plugin.isEnabled() ? "§a§lENABLED" : "§c§lDISABLED")); } @@ -48,6 +66,7 @@ public void status(CommandSender sender) { * @param args Command arguments */ public void setTimeLimit(CommandSender sender, String[] args) { + if (!hasPermission(sender, "botblocker.settimelimit")) return; if(args.length > 1) { try { int timeLimit = Integer.parseInt(args[1]); @@ -66,6 +85,7 @@ public void setTimeLimit(CommandSender sender, String[] args) { * @param sender Command sender */ public void getTimeLimit(CommandSender sender) { + if (!hasPermission(sender, "botblocker.gettimelimit")) return; sender.sendMessage("Time limit set to " + plugin.getTimeLimit() + " seconds."); } @@ -75,6 +95,7 @@ public void getTimeLimit(CommandSender sender) { * @param args Command arguments */ public void setBanMessage(CommandSender sender, String[] args) { + if (!hasPermission(sender, "botblocker.setbanmessage")) return; if(args.length > 1) { StringBuilder message = new StringBuilder(); for(int i = 1; i < args.length; i++) { @@ -93,6 +114,7 @@ public void setBanMessage(CommandSender sender, String[] args) { * @param sender Command sender */ public void getBanMessage(CommandSender sender) { + if (!hasPermission(sender, "botblocker.getbanmessage")) return; sender.sendMessage("Ban message: " + plugin.getConfig().getString("ban-message")); } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index d51878b..58e57c7 100755 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,9 +1,33 @@ name: BotBlocker main: ovh.aichan.botblockerminecraft.BotBlocker -version: 1.3.0 +version: 1.4.0 api-version: '1.20' author: aichan description: A plugin to ban users who connect for the first time and disconnect within a certain time limit. + +permissions: + botblocker.enable: + description: Allows the user to enable the BotBlocker plugin. + default: op + botblocker.disable: + description: Allows the user to disable the BotBlocker plugin. + default: op + botblocker.status: + description: Allows the user to see whether BotBlocker is enabled or disabled. + default: true + botblocker.settimelimit: + description: Allows the user to set the time limit for detecting bots. + default: op + botblocker.gettimelimit: + description: Allows the user to display the configured time limit for detecting bots. + default: true + botblocker.setbanmessage: + description: Allows the user to set the ban message. + default: op + botblocker.getbanmessage: + description: Allows the user to display the configured ban message. + default: true + commands: botblocker: description: Manages the BotBlocker plugin