|
| 1 | +package com.dark.zewo2.commands; |
| 2 | + |
| 3 | +import com.google.gson.JsonArray; |
| 4 | +import com.google.gson.JsonElement; |
| 5 | +import com.google.gson.JsonObject; |
| 6 | +import com.google.gson.JsonParser; |
| 7 | +import com.mojang.brigadier.arguments.StringArgumentType; |
| 8 | +import com.mojang.brigadier.builder.LiteralArgumentBuilder; |
| 9 | +import io.netty.util.Signal; |
| 10 | +import meteordevelopment.meteorclient.commands.Command; |
| 11 | +import meteordevelopment.meteorclient.commands.arguments.PlayerArgumentType; |
| 12 | +import meteordevelopment.meteorclient.utils.Utils; |
| 13 | +import meteordevelopment.meteorclient.utils.network.Http; |
| 14 | +import meteordevelopment.meteorclient.utils.player.ChatUtils; |
| 15 | +import meteordevelopment.meteorclient.utils.player.PlayerUtils; |
| 16 | +import net.minecraft.client.gui.screen.ingame.InventoryScreen; |
| 17 | +import net.minecraft.command.CommandSource; |
| 18 | +import net.minecraft.command.argument.TextArgumentType; |
| 19 | +import net.minecraft.text.Text; |
| 20 | + |
| 21 | +import java.util.HashMap; |
| 22 | +import java.util.concurrent.CompletableFuture; |
| 23 | + |
| 24 | +import static com.mojang.brigadier.Command.SINGLE_SUCCESS; |
| 25 | + |
| 26 | +public class MinefortJoin extends Command { |
| 27 | + |
| 28 | + public MinefortJoin() { |
| 29 | + super("minefort", "Join another player on minefort >> @just_jakob", "mf"); |
| 30 | + } |
| 31 | + |
| 32 | + @Override |
| 33 | + public void build(LiteralArgumentBuilder<CommandSource> builder) { |
| 34 | + builder.then(literal("join").then(argument("player", StringArgumentType.string()).executes(context -> { |
| 35 | + String player = StringArgumentType.getString(context, "player"); |
| 36 | + |
| 37 | + info("Searching..."); |
| 38 | + |
| 39 | + find(player).thenAccept((ser) -> { |
| 40 | + if(ser == null) |
| 41 | + error("Player not found!"); |
| 42 | + else { |
| 43 | + info(Text.literal(player + " found on " + ser + ", attempting server switch!")); |
| 44 | + ChatUtils.sendPlayerMsg("/server " + ser); |
| 45 | + } |
| 46 | + }); |
| 47 | + |
| 48 | + return SINGLE_SUCCESS; |
| 49 | + }))); |
| 50 | + |
| 51 | + builder.then(literal("find").then(argument("player", StringArgumentType.string()).executes(context -> { |
| 52 | + String player = StringArgumentType.getString(context, "player"); |
| 53 | + |
| 54 | + info("Searching..."); |
| 55 | + |
| 56 | + find(player).thenAccept((ser) -> { |
| 57 | + if(ser == null) |
| 58 | + error("Player not found!"); |
| 59 | + else |
| 60 | + info(player + " is on " + ser); |
| 61 | + }); |
| 62 | + |
| 63 | + return SINGLE_SUCCESS; |
| 64 | + }))); |
| 65 | + } |
| 66 | + |
| 67 | + public CompletableFuture<String> find(String player) { |
| 68 | + return CompletableFuture.supplyAsync(() -> { |
| 69 | + try { |
| 70 | + |
| 71 | + String uuid = JsonParser.parseString(Http.get("https://playerdb.co/api/player/minecraft/" + player).sendString()).getAsJsonObject() |
| 72 | + .getAsJsonObject("data").getAsJsonObject("player").get("id").getAsString(); |
| 73 | + |
| 74 | + String str = Http.post("https://api.minefort.com/v1/servers/list").bodyJson("{\"pagination\": { \"skip\": 0, \"limit\": 500 }, \"sort\": { \"field\": \"players.online\", \"order\": \"desc\" }}").sendString(); |
| 75 | + |
| 76 | + JsonArray obj = JsonParser.parseString(str).getAsJsonObject().get("result").getAsJsonArray(); |
| 77 | + |
| 78 | + for (JsonElement jsonElement : obj) { |
| 79 | + for (JsonElement p : jsonElement.getAsJsonObject().getAsJsonObject("players").getAsJsonArray("list")) { |
| 80 | + if(p.getAsJsonObject().get("uuid").getAsString().equalsIgnoreCase(uuid)) { |
| 81 | + return jsonElement.getAsJsonObject().get("serverName").getAsString(); |
| 82 | + } |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + return null; |
| 87 | + } catch (Exception e) { |
| 88 | + error("Something went wrong! " + e.getMessage()); |
| 89 | + return null; |
| 90 | + } |
| 91 | + }); |
| 92 | + } |
| 93 | +} |
0 commit comments