Skip to content

Commit c1e3da7

Browse files
cryptobenchclaude
andcommitted
Fix command arguments to use positional args
Change commands to use RequiredArg for positional arguments: - AdminSetSubcommand: setting and value are now positional - TrustSubcommand: player is now positional, level remains optional - UntrustSubcommand: player is now positional This fixes "wrong number of required arguments" errors when users type commands like "/easyclaims admin set starting 4" Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent e83ed71 commit c1e3da7

3 files changed

Lines changed: 13 additions & 44 deletions

File tree

src/main/java/com/easyclaims/commands/subcommands/TrustSubcommand.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.hypixel.hytale.server.core.NameMatching;
77
import com.hypixel.hytale.server.core.command.system.CommandContext;
88
import com.hypixel.hytale.server.core.command.system.arguments.system.OptionalArg;
9+
import com.hypixel.hytale.server.core.command.system.arguments.system.RequiredArg;
910
import com.hypixel.hytale.server.core.command.system.arguments.types.ArgTypes;
1011
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractPlayerCommand;
1112
import com.hypixel.hytale.server.core.universe.PlayerRef;
@@ -21,7 +22,7 @@
2122

2223
public class TrustSubcommand extends AbstractPlayerCommand {
2324
private final EasyClaims plugin;
24-
private final OptionalArg<String> playerArg;
25+
private final RequiredArg<String> playerArg;
2526
private final OptionalArg<String> levelArg;
2627

2728
private static final Color GREEN = new Color(85, 255, 85);
@@ -31,7 +32,7 @@ public class TrustSubcommand extends AbstractPlayerCommand {
3132
public TrustSubcommand(EasyClaims plugin) {
3233
super("trust", "Trust a player to interact with your claims");
3334
this.plugin = plugin;
34-
this.playerArg = withOptionalArg("player", "Player name to trust", ArgTypes.STRING);
35+
this.playerArg = withRequiredArg("player", "Player name to trust", ArgTypes.STRING);
3536
this.levelArg = withOptionalArg("level", "Trust level (use/container/workstation/build)", ArgTypes.STRING);
3637
requirePermission("easyclaims.use");
3738
}
@@ -45,12 +46,6 @@ protected void execute(@Nonnull CommandContext ctx,
4546
String playerInput = playerArg.get(ctx);
4647
String levelInput = levelArg.get(ctx);
4748

48-
if (playerInput == null || playerInput.isEmpty()) {
49-
playerData.sendMessage(Message.raw("Usage: /easyclaims trust <player> [level]").color(RED));
50-
playerData.sendMessage(Message.raw("Levels: use, container, workstation, build").color(GRAY));
51-
return;
52-
}
53-
5449
TrustLevel level = TrustLevel.BUILD;
5550
if (levelInput != null && !levelInput.isEmpty()) {
5651
level = TrustLevel.fromString(levelInput);

src/main/java/com/easyclaims/commands/subcommands/UntrustSubcommand.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import com.hypixel.hytale.server.core.Message;
66
import com.hypixel.hytale.server.core.NameMatching;
77
import com.hypixel.hytale.server.core.command.system.CommandContext;
8-
import com.hypixel.hytale.server.core.command.system.arguments.system.OptionalArg;
8+
import com.hypixel.hytale.server.core.command.system.arguments.system.RequiredArg;
99
import com.hypixel.hytale.server.core.command.system.arguments.types.ArgTypes;
1010
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractPlayerCommand;
1111
import com.hypixel.hytale.server.core.universe.PlayerRef;
@@ -24,7 +24,7 @@
2424

2525
public class UntrustSubcommand extends AbstractPlayerCommand {
2626
private final EasyClaims plugin;
27-
private final OptionalArg<String> playerArg;
27+
private final RequiredArg<String> playerArg;
2828

2929
private static final Color GREEN = new Color(85, 255, 85);
3030
private static final Color RED = new Color(255, 85, 85);
@@ -33,7 +33,7 @@ public class UntrustSubcommand extends AbstractPlayerCommand {
3333
public UntrustSubcommand(EasyClaims plugin) {
3434
super("untrust", "Remove trust from a player");
3535
this.plugin = plugin;
36-
this.playerArg = withOptionalArg("player", "Player name to untrust", ArgTypes.STRING);
36+
this.playerArg = withRequiredArg("player", "Player name to untrust", ArgTypes.STRING);
3737
requirePermission("easyclaims.use");
3838
}
3939

@@ -45,11 +45,6 @@ protected void execute(@Nonnull CommandContext ctx,
4545
@Nonnull World world) {
4646
String playerInput = playerArg.get(ctx);
4747

48-
if (playerInput == null || playerInput.isEmpty()) {
49-
playerData.sendMessage(Message.raw("Usage: /easyclaims untrust <player>").color(RED));
50-
return;
51-
}
52-
5348
PlayerClaims claims = plugin.getClaimManager().getPlayerClaims(playerData.getUuid());
5449
UUID targetId = null;
5550
String targetName = playerInput;

src/main/java/com/easyclaims/commands/subcommands/admin/AdminSetSubcommand.java

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import com.hypixel.hytale.component.Store;
55
import com.hypixel.hytale.server.core.Message;
66
import com.hypixel.hytale.server.core.command.system.CommandContext;
7-
import com.hypixel.hytale.server.core.command.system.arguments.system.OptionalArg;
7+
import com.hypixel.hytale.server.core.command.system.arguments.system.RequiredArg;
88
import com.hypixel.hytale.server.core.command.system.arguments.types.ArgTypes;
99
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractPlayerCommand;
1010
import com.hypixel.hytale.server.core.universe.PlayerRef;
@@ -18,8 +18,8 @@
1818

1919
public class AdminSetSubcommand extends AbstractPlayerCommand {
2020
private final EasyClaims plugin;
21-
private final OptionalArg<String> keyArg;
22-
private final OptionalArg<String> valueArg;
21+
private final RequiredArg<String> keyArg;
22+
private final RequiredArg<Integer> valueArg;
2323

2424
private static final Color GOLD = new Color(255, 170, 0);
2525
private static final Color GREEN = new Color(85, 255, 85);
@@ -28,10 +28,10 @@ public class AdminSetSubcommand extends AbstractPlayerCommand {
2828
private static final Color GRAY = new Color(170, 170, 170);
2929

3030
public AdminSetSubcommand(EasyClaims plugin) {
31-
super("set", "Change a server claim setting");
31+
super("set", "Change a server claim setting (starting/perhour/max/buffer)");
3232
this.plugin = plugin;
33-
this.keyArg = withOptionalArg("key", "Setting name (starting/perhour/max/buffer)", ArgTypes.STRING);
34-
this.valueArg = withOptionalArg("value", "New value", ArgTypes.STRING);
33+
this.keyArg = withRequiredArg("setting", "Setting name (starting/perhour/max/buffer)", ArgTypes.STRING);
34+
this.valueArg = withRequiredArg("value", "New value", ArgTypes.INTEGER);
3535
requirePermission("easyclaims.admin");
3636
}
3737

@@ -42,28 +42,7 @@ protected void execute(@Nonnull CommandContext ctx,
4242
@Nonnull PlayerRef playerData,
4343
@Nonnull World world) {
4444
String key = keyArg.get(ctx);
45-
String valueStr = valueArg.get(ctx);
46-
47-
if (key == null || valueStr == null) {
48-
playerData.sendMessage(Message.raw("How to change settings:").color(GOLD));
49-
playerData.sendMessage(Message.raw(" /easyclaims admin set starting <number>").color(YELLOW));
50-
playerData.sendMessage(Message.raw(" How many claims new players start with").color(GRAY));
51-
playerData.sendMessage(Message.raw(" /easyclaims admin set perhour <number>").color(YELLOW));
52-
playerData.sendMessage(Message.raw(" Extra claims earned per hour played").color(GRAY));
53-
playerData.sendMessage(Message.raw(" /easyclaims admin set max <number>").color(YELLOW));
54-
playerData.sendMessage(Message.raw(" Maximum claims any player can have").color(GRAY));
55-
playerData.sendMessage(Message.raw(" /easyclaims admin set buffer <number>").color(YELLOW));
56-
playerData.sendMessage(Message.raw(" Buffer zone in chunks around claims (0 = disabled)").color(GRAY));
57-
return;
58-
}
59-
60-
int value;
61-
try {
62-
value = Integer.parseInt(valueStr);
63-
} catch (NumberFormatException e) {
64-
playerData.sendMessage(Message.raw("Please enter a number! Example: /easyclaims admin set max 100").color(RED));
65-
return;
66-
}
45+
int value = valueArg.get(ctx);
6746

6847
PluginConfig config = plugin.getPluginConfig();
6948
switch (key.toLowerCase()) {

0 commit comments

Comments
 (0)