Skip to content

Commit 89666b6

Browse files
cryptobenchclaude
andcommitted
Fix optional positional args for admin claim and pvp commands
The Hytale command system treats withOptionalArg as flag-style arguments (--name=value) rather than positional arguments. This caused errors like "Expected: 0, actual: 1" when users typed "/easyclaims admin claim Spawn". Fix by using setAllowsExtraArguments(true) and parsing the raw input string to extract the optional positional argument after the command name. Commands now work as expected: - /easyclaims admin claim (creates claim with default "Server" name) - /easyclaims admin claim Spawn (creates claim named "Spawn") - /easyclaims admin pvp (toggles PvP) - /easyclaims admin pvp on (enables PvP) - /easyclaims admin pvp off (disables PvP) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 3f74c73 commit 89666b6

2 files changed

Lines changed: 27 additions & 11 deletions

File tree

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import com.hypixel.hytale.component.Store;
55
import com.hypixel.hytale.math.vector.Vector3d;
66
import com.hypixel.hytale.server.core.command.system.CommandContext;
7-
import com.hypixel.hytale.server.core.command.system.arguments.system.OptionalArg;
8-
import com.hypixel.hytale.server.core.command.system.arguments.types.ArgTypes;
97
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractPlayerCommand;
108
import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
119
import com.hypixel.hytale.server.core.universe.PlayerRef;
@@ -23,15 +21,15 @@
2321
/**
2422
* Admin command to create server-owned admin claims.
2523
* Admin claims have PvP disabled by default and bypass buffer zones.
24+
* Usage: /easyclaims admin claim [name]
2625
*/
2726
public class AdminClaimSubcommand extends AbstractPlayerCommand {
2827
private final EasyClaims plugin;
29-
private final OptionalArg<String> displayNameArg;
3028

3129
public AdminClaimSubcommand(EasyClaims plugin) {
3230
super("claim", "Create an admin claim at your location");
3331
this.plugin = plugin;
34-
this.displayNameArg = withOptionalArg("name", "Display name for the claim (e.g., Spawn)", ArgTypes.STRING);
32+
setAllowsExtraArguments(true); // Allow optional positional name argument
3533
requirePermission("easyclaims.admin");
3634
}
3735

@@ -60,8 +58,18 @@ protected void execute(@Nonnull CommandContext ctx,
6058
return;
6159
}
6260

63-
// Get optional display name
64-
String displayName = displayNameArg.get(ctx);
61+
// Get optional display name from raw input (everything after "claim")
62+
String displayName = null;
63+
String input = ctx.getInputString();
64+
// Input format: "easyclaims admin claim [name]" or just "claim [name]" depending on context
65+
// Look for any extra arguments after command parsing
66+
int claimIndex = input.toLowerCase().lastIndexOf("claim");
67+
if (claimIndex >= 0) {
68+
String afterClaim = input.substring(claimIndex + 5).trim();
69+
if (!afterClaim.isEmpty()) {
70+
displayName = afterClaim;
71+
}
72+
}
6573

6674
// Register admin name for map display
6775
plugin.getClaimStorage().setPlayerName(AdminClaims.ADMIN_UUID,

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import com.hypixel.hytale.component.Store;
55
import com.hypixel.hytale.math.vector.Vector3d;
66
import com.hypixel.hytale.server.core.command.system.CommandContext;
7-
import com.hypixel.hytale.server.core.command.system.arguments.system.OptionalArg;
8-
import com.hypixel.hytale.server.core.command.system.arguments.types.ArgTypes;
97
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractPlayerCommand;
108
import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
119
import com.hypixel.hytale.server.core.universe.PlayerRef;
@@ -21,15 +19,15 @@
2119
/**
2220
* Admin command to toggle PvP in any claim.
2321
* Admins can override PvP settings regardless of server mode.
22+
* Usage: /easyclaims admin pvp [on/off]
2423
*/
2524
public class AdminPvpSubcommand extends AbstractPlayerCommand {
2625
private final EasyClaims plugin;
27-
private final OptionalArg<String> stateArg;
2826

2927
public AdminPvpSubcommand(EasyClaims plugin) {
3028
super("pvp", "Toggle PvP in the current claim");
3129
this.plugin = plugin;
32-
this.stateArg = withOptionalArg("state", "on/off (omit to toggle)", ArgTypes.STRING);
30+
setAllowsExtraArguments(true); // Allow optional positional on/off argument
3331
requirePermission("easyclaims.admin");
3432
}
3533

@@ -50,8 +48,18 @@ protected void execute(@Nonnull CommandContext ctx,
5048
return;
5149
}
5250

51+
// Get optional state from raw input (everything after "pvp")
52+
String state = null;
53+
String input = ctx.getInputString();
54+
int pvpIndex = input.toLowerCase().lastIndexOf("pvp");
55+
if (pvpIndex >= 0) {
56+
String afterPvp = input.substring(pvpIndex + 3).trim();
57+
if (!afterPvp.isEmpty()) {
58+
state = afterPvp.split("\\s+")[0]; // Take first word only
59+
}
60+
}
61+
5362
// Determine new state
54-
String state = stateArg.get(ctx);
5563
boolean newPvpEnabled;
5664

5765
if (state == null || state.isEmpty()) {

0 commit comments

Comments
 (0)