From 5157a764426c70683efd7ad86e0194ae446ecd9c Mon Sep 17 00:00:00 2001 From: Cloudburst <18114966+C10udburst@users.noreply.github.com> Date: Tue, 30 Aug 2022 15:57:40 +0200 Subject: [PATCH] fix crashes and bugs closes #156, #150 --- .../anticope/rejects/commands/SaveSkinCommand.java | 13 +++++++------ .../java/anticope/rejects/modules/AntiVanish.java | 2 +- .../rejects/modules/modifier/NoRenderModifier.java | 2 ++ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/anticope/rejects/commands/SaveSkinCommand.java b/src/main/java/anticope/rejects/commands/SaveSkinCommand.java index 46cc560..1a3b1fd 100644 --- a/src/main/java/anticope/rejects/commands/SaveSkinCommand.java +++ b/src/main/java/anticope/rejects/commands/SaveSkinCommand.java @@ -5,7 +5,7 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import meteordevelopment.meteorclient.systems.commands.Command; -import meteordevelopment.meteorclient.systems.commands.arguments.PlayerArgumentType; +import meteordevelopment.meteorclient.systems.commands.arguments.PlayerListEntryArgumentType; import meteordevelopment.meteorclient.utils.network.Http; import net.minecraft.command.CommandSource; import net.minecraft.entity.player.PlayerEntity; @@ -20,12 +20,13 @@ import java.io.*; import java.net.URL; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; +import java.util.UUID; import static com.mojang.brigadier.Command.SINGLE_SUCCESS; public class SaveSkinCommand extends Command { - private final static SimpleCommandExceptionType IO_EXCEPTION = new SimpleCommandExceptionType(Text.literal("An IOException occurred")); + private final static SimpleCommandExceptionType IO_EXCEPTION = new SimpleCommandExceptionType(Text.literal("An exception occurred")); private final PointerBuffer filters; private final Gson GSON = new Gson(); @@ -43,13 +44,13 @@ public class SaveSkinCommand extends Command { @Override public void build(LiteralArgumentBuilder builder) { - builder.then(argument("player", PlayerArgumentType.create()).executes(ctx -> { - PlayerEntity playerEntity = ctx.getArgument("player", PlayerEntity.class); + builder.then(argument("player", PlayerListEntryArgumentType.create()).executes(ctx -> { + UUID id = PlayerListEntryArgumentType.get(ctx).getProfile().getId(); String path = TinyFileDialogs.tinyfd_saveFileDialog("Save image", null, filters, null); if (path == null) IO_EXCEPTION.create(); if (path != null) { if (!path.endsWith(".png")) path += ".png"; - saveSkin(playerEntity.getUuidAsString(),path); + saveSkin(id.toString(),path); } return SINGLE_SUCCESS; @@ -90,7 +91,7 @@ public class SaveSkinCommand extends Command { FileOutputStream fos = new FileOutputStream(file.getPath()); fos.write(response); fos.close(); - } catch (IOException e) { + } catch (IOException | NullPointerException e) { throw IO_EXCEPTION.create(); } } diff --git a/src/main/java/anticope/rejects/modules/AntiVanish.java b/src/main/java/anticope/rejects/modules/AntiVanish.java index 826ea1e..b5084a2 100644 --- a/src/main/java/anticope/rejects/modules/AntiVanish.java +++ b/src/main/java/anticope/rejects/modules/AntiVanish.java @@ -111,7 +111,7 @@ public class AntiVanish extends Module { final String url = "https://api.mojang.com/user/profiles/" + uuidstr.replace("-", "") + "/names"; try { JsonArray res = Http.get(url).sendJson(JsonArray.class); - return res.get(0).getAsJsonObject().get("name").getAsString(); + return res.get(res.size() - 1).getAsJsonObject().get("name").getAsString(); } catch (Exception e) { return uuidstr; } diff --git a/src/main/java/anticope/rejects/modules/modifier/NoRenderModifier.java b/src/main/java/anticope/rejects/modules/modifier/NoRenderModifier.java index c09f401..6209e03 100644 --- a/src/main/java/anticope/rejects/modules/modifier/NoRenderModifier.java +++ b/src/main/java/anticope/rejects/modules/modifier/NoRenderModifier.java @@ -14,10 +14,12 @@ public class NoRenderModifier { public static Setting disableToasts; public static boolean noCommandSuggestions() { + if (noCommandSuggestions == null || Modules.get() == null || Modules.get().get(NoRender.class) == null) return false; return Modules.get().get(NoRender.class).isActive() && noCommandSuggestions.get(); } public static boolean disableToasts() { + if (disableToasts == null || Modules.get() == null || Modules.get().get(NoRender.class) == null) return false; return Modules.get().get(NoRender.class).isActive() && disableToasts.get(); }