package com.rtxbb.lts_auth.command; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.context.CommandContext; import com.rtxbb.lts_auth.LtsAuthMod; import com.rtxbb.lts_auth.manager.AuthManager; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerPlayer; public class LoginCommand { public static void register(CommandDispatcher dispatcher) { dispatcher.register( Commands.m_82127_("login") .then(Commands.m_82129_("password", StringArgumentType.string()) .executes(LoginCommand::execute) ) ); } private static int execute(CommandContext ctx) { try { ServerPlayer player = ctx.getSource().m_81375_(); String password = StringArgumentType.getString(ctx, "password"); if (!AuthManager.getInstance().isRegistered(player.m_20148_())) { ctx.getSource().m_81352_(Component.m_237113_(LtsAuthMod.messages().getColored("messages.not_registered"))); return 0; } if (AuthManager.getInstance().isAuthenticated(player.m_20148_())) { ctx.getSource().m_81352_(Component.m_237113_(LtsAuthMod.messages().getColored("messages.already_logged_in"))); return 0; } if (AuthManager.getInstance().login(player, password)) { player.m_6842_(false); return 1; } else { ctx.getSource().m_81352_(Component.m_237113_(LtsAuthMod.messages().getColored("messages.invalid_password"))); return 0; } } catch (Exception e) { return 0; } } }