Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
<version>v1.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>23.0.0</version>
<scope>provided</scope>
</dependency>

</dependencies>

Expand Down
42 changes: 26 additions & 16 deletions src/main/java/dansplugins/rpsystem/commands/roll/RollCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.bukkit.entity.Player;

public class RollCommand {
private static final int DEFAULT_DIE_SIZE = 20;

private final MedievalRoleplayEngine medievalRoleplayEngine;

public RollCommand(MedievalRoleplayEngine medievalRoleplayEngine) {
Expand All @@ -14,25 +16,33 @@ public RollCommand(MedievalRoleplayEngine medievalRoleplayEngine) {

public boolean rollDice(CommandSender sender, String[] args) {

if (sender instanceof Player) {
Player player = (Player) sender;
if (player.hasPermission("rp.roll") || player.hasPermission("rp.dice") || player.hasPermission("rp.default")) {
if (args.length > 0) {
try {
int max = Integer.parseInt(args[0]);
medievalRoleplayEngine.messenger.sendRPMessageToPlayersWithinDistance(player, medievalRoleplayEngine.colorChecker.getNeutralAlertColor() + "" + ChatColor.ITALIC + player.getName() + " has rolled a " + rollDice(max) + " out of " + max + ".", 25);
}
catch(Exception ignored) {

}
if (!(sender instanceof Player)) {
return false;
}

Player player = (Player) sender;

if (!(player.hasPermission("rp.roll") || player.hasPermission("rp.dice") || player.hasPermission("rp.default"))) {
player.sendMessage(medievalRoleplayEngine.colorChecker.getNegativeAlertColor() + "Sorry! In order to use this command, you need one of the following permissions: 'rp.roll', 'rp.dice', 'rp.default'");
return true;
}

int max = DEFAULT_DIE_SIZE;
if (args.length > 0) {
try {
max = Integer.parseInt(args[0]);
if (max < 1) {
player.sendMessage(medievalRoleplayEngine.colorChecker.getNegativeAlertColor() + "Please provide a positive number to roll.");
return true;
}
Comment on lines +34 to 37
Copy link

Copilot AI Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With usage now defined in plugin.yml, returning false here will make Bukkit print the usage line in addition to this custom message. If you want to show only your own validation message, return true after sending it (or remove the custom message and rely on Bukkit usage instead).

Copilot uses AI. Check for mistakes.
} catch (NumberFormatException e) {
player.sendMessage(medievalRoleplayEngine.colorChecker.getNegativeAlertColor() + "'" + args[0] + "' is not a valid number.");
return true;
}
else {
player.sendMessage(medievalRoleplayEngine.colorChecker.getNegativeAlertColor() + "Sorry! In order to use this command, you need one the following permissions: 'rp.roll', 'rp.dice'");
}

}
return false;

medievalRoleplayEngine.messenger.sendRPMessageToPlayersWithinDistance(player, medievalRoleplayEngine.colorChecker.getNeutralAlertColor() + "" + ChatColor.ITALIC + player.getName() + " has rolled a " + rollDice(max) + " out of " + max + ".", 25);
return true;
}

private int rollDice(int max) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ commands:
emote:
me:
roll:
description: Roll a die. Defaults to a d20 if no max is specified.
usage: /roll [max]
dice:
description: Roll a die. Defaults to a d20 if no max is specified.
usage: /dice [max]
title:
yell:
whisper:
Expand Down
Loading