|
| 1 | +package com.nxyi.addon.commands; |
| 2 | + |
| 3 | +import com.mojang.brigadier.arguments.IntegerArgumentType; |
| 4 | +import com.mojang.brigadier.arguments.StringArgumentType; |
| 5 | +import com.mojang.brigadier.builder.LiteralArgumentBuilder; |
| 6 | +import com.nxyi.addon.Addon; |
| 7 | +import com.nxyi.addon.gui.settings.SetSession; |
| 8 | +import com.nxyi.addon.login.easymc.AltTokenResponse; |
| 9 | +import com.nxyi.addon.login.easymc.EasyMCRequest; |
| 10 | +import meteordevelopment.meteorclient.systems.commands.Command; |
| 11 | +import net.minecraft.client.gui.screen.ConnectScreen; |
| 12 | +import net.minecraft.client.gui.screen.TitleScreen; |
| 13 | +import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen; |
| 14 | +import net.minecraft.client.network.ServerAddress; |
| 15 | +import net.minecraft.client.network.ServerInfo; |
| 16 | +import net.minecraft.command.CommandSource; |
| 17 | +import net.minecraft.text.Text; |
| 18 | + |
| 19 | +import java.io.IOException; |
| 20 | +import java.net.URISyntaxException; |
| 21 | + |
| 22 | +public class Reconnect extends Command { |
| 23 | + public Reconnect() { |
| 24 | + super("rejoin", "Reconnect you with different things", "Reconnect"); |
| 25 | + } |
| 26 | + |
| 27 | + @Override |
| 28 | + public void build(LiteralArgumentBuilder<CommandSource> builder) { |
| 29 | + builder.then(literal("easymc") |
| 30 | + .then(argument("token", StringArgumentType.greedyString()).executes(ctx -> { |
| 31 | + String TOKEN = StringArgumentType.getString(ctx ,"token"); |
| 32 | + new Thread(() -> { |
| 33 | + if (TOKEN.isEmpty()) return; |
| 34 | + |
| 35 | + EasyMCRequest request = new EasyMCRequest(); |
| 36 | + AltTokenResponse response = null; |
| 37 | + try { |
| 38 | + response = request.getResponse(TOKEN); |
| 39 | + } catch (URISyntaxException | InterruptedException | IOException e) { |
| 40 | + //error |
| 41 | + } |
| 42 | + |
| 43 | + SetSession.username = response.getMcName(); |
| 44 | + SetSession.UUID = response.getUuid(); |
| 45 | + SetSession.accessToken = response.getSession(); |
| 46 | + |
| 47 | + SetSession.sessionid = "token:" + SetSession.accessToken + ":" + SetSession.UUID; |
| 48 | + SetSession.originalSession = false; |
| 49 | + }).start(); |
| 50 | + rejoin(); |
| 51 | + |
| 52 | + return 0; |
| 53 | + }))); |
| 54 | + |
| 55 | + builder.then(literal("return").executes(context -> { |
| 56 | + SetSession.username = Addon.BOOTNAME; |
| 57 | + SetSession.UUID = Addon.BOOTUUID; |
| 58 | + SetSession.accessToken = Addon.BOOTSESSION; |
| 59 | + |
| 60 | + SetSession.sessionid = "token:" + SetSession.accessToken + ":" + SetSession.UUID; |
| 61 | + SetSession.originalSession = true; |
| 62 | + rejoin(); |
| 63 | + return 0; |
| 64 | + })); |
| 65 | + } |
| 66 | + |
| 67 | + private void rejoin(){ |
| 68 | + ServerInfo lastServerInfo = mc.isInSingleplayer() ? null : mc.getCurrentServerEntry(); |
| 69 | + mc.player.networkHandler.getConnection().disconnect(Text.literal("")); |
| 70 | + ConnectScreen.connect(null, mc, ServerAddress.parse(lastServerInfo.address), lastServerInfo); |
| 71 | + } |
| 72 | +} |
0 commit comments