refactor: make .username set <username> only a string instead of a greedy string so we can set our username to an empty string for the funnies

This commit is contained in:
Chayapak Supasakul 2025-03-21 17:51:51 +07:00
parent 88cca61fe2
commit c5fbd67510
Signed by: ChomeNS
SSH key fingerprint: SHA256:0YoxhdyXsgbc0nfeB2N6FYE60mxMU7DS4uCUMaw2mvA

View file

@ -4,8 +4,7 @@ import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import static com.mojang.brigadier.arguments.StringArgumentType.greedyString;
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
import static com.mojang.brigadier.arguments.StringArgumentType.*;
import static land.chipmunk.chipmunkmod.command.CommandManager.literal;
import static land.chipmunk.chipmunkmod.command.CommandManager.argument;
@ -35,8 +34,8 @@ public class UsernameCommand {
.then(
literal("set")
.then(
argument("username", greedyString())
.executes(c -> updateUsername(c))
argument("username", string())
.executes(UsernameCommand::updateUsername)
)
)
.then(
@ -53,7 +52,7 @@ public class UsernameCommand {
return updateSession(context, session);
}
public static int updateSession(CommandContext<FabricClientCommandSource> context, Session session) throws CommandSyntaxException {
public static int updateSession(CommandContext<FabricClientCommandSource> context, Session session) {
final FabricClientCommandSource source = context.getSource();
final MinecraftClient client = source.getClient();
@ -62,7 +61,7 @@ public class UsernameCommand {
// TODO: Put this in a separate class
final ServerInfo info = client.getCurrentServerEntry();
client.world.disconnect();
if (client.world != null) client.world.disconnect();
client.disconnect();
ConnectScreen.connect(new TitleScreen(), client, ServerAddress.parse(info.address), info, false, null);