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