Skip to content

Commit

Permalink
Merge branch 'feature/permissions'
Browse files Browse the repository at this point in the history
  • Loading branch information
AitorAstorga committed Feb 28, 2024
2 parents d3be432 + cc5880f commit b470aef
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<li><a href="#player-join">Player Join</a></li>
<li><a href="#player-quit">Player Quit</a></li>
<li><a href="#commands">Commands</a></li>
<li><a href="#permissions">Permissions</a></li>
<li><a href="#configuration-files">Configuration Files</a></li>
</ul>
</li>
Expand Down Expand Up @@ -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.
<p align="right">(<a href="#readme-top">back to top</a>)</p>

Expand Down
22 changes: 22 additions & 0 deletions src/main/java/ovh/aichan/botblockerminecraft/CommandHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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"));
}

Expand All @@ -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]);
Expand All @@ -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.");
}

Expand All @@ -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++) {
Expand All @@ -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"));
}

Expand Down
26 changes: 25 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit b470aef

Please sign in to comment.