added exceptions
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package cloudburst.rejects.commands;
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||
import minegame159.meteorclient.systems.commands.Command;
|
||||
import minegame159.meteorclient.utils.player.InvUtils;
|
||||
import net.minecraft.command.CommandSource;
|
||||
@@ -9,6 +10,7 @@ import net.minecraft.item.Items;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.network.packet.c2s.play.BookUpdateC2SPacket;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.util.Hand;
|
||||
|
||||
import static com.mojang.brigadier.Command.SINGLE_SUCCESS;
|
||||
@@ -17,6 +19,7 @@ import static com.mojang.brigadier.Command.SINGLE_SUCCESS;
|
||||
public class BookDupeCommand extends Command {
|
||||
|
||||
private final ItemStack DUPE_BOOK = new ItemStack(Items.WRITABLE_BOOK, 1);
|
||||
private final static SimpleCommandExceptionType NO_BOOK_EXCEPTION = new SimpleCommandExceptionType(new LiteralText("No book found"));
|
||||
|
||||
public BookDupeCommand() {
|
||||
super("dupe", "Dupes using a held, writable book.");
|
||||
@@ -45,8 +48,9 @@ public class BookDupeCommand extends Command {
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<CommandSource> builder) {
|
||||
builder.executes(context -> {
|
||||
if (InvUtils.getHand(Items.WRITABLE_BOOK) != Hand.MAIN_HAND) error("No book found, you must be holding a writable book!");
|
||||
else mc.player.networkHandler.sendPacket(new BookUpdateC2SPacket(DUPE_BOOK, true, mc.player.inventory.selectedSlot));
|
||||
if (InvUtils.getHand(Items.WRITABLE_BOOK) != Hand.MAIN_HAND) throw NO_BOOK_EXCEPTION.create();
|
||||
|
||||
mc.player.networkHandler.sendPacket(new BookUpdateC2SPacket(DUPE_BOOK, true, mc.player.inventory.selectedSlot));
|
||||
|
||||
return SINGLE_SUCCESS;
|
||||
});
|
||||
|
||||
@@ -3,6 +3,8 @@ package cloudburst.rejects.commands;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.item.*;
|
||||
import net.minecraft.nbt.*;
|
||||
@@ -26,6 +28,8 @@ public class GiveCommand extends Command {
|
||||
super("give", "Gives items in creative", "item", "kit");
|
||||
}
|
||||
|
||||
private final static SimpleCommandExceptionType NOT_IN_CREATIVE = new SimpleCommandExceptionType(new LiteralText("You must be in creative mode to use this."));
|
||||
private final static SimpleCommandExceptionType NO_SPACE = new SimpleCommandExceptionType(new LiteralText("No space in hotbar"));
|
||||
private final Collection<String> PRESETS = Arrays.asList("forceop", "negs", "stacked", "spawners", "bookban",
|
||||
"test", "eggs");
|
||||
private final Collection<String> CONTAINERS = Arrays.asList("chest", "shulker", "trapped_chest", "barrel",
|
||||
@@ -34,6 +38,7 @@ public class GiveCommand extends Command {
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<CommandSource> builder) {
|
||||
builder.then(literal("egg").executes(ctx -> {
|
||||
if (!mc.player.abilities.creativeMode) throw NOT_IN_CREATIVE.create();
|
||||
ItemStack inHand = mc.player.getMainHandStack();
|
||||
ItemStack item = new ItemStack(Items.STRIDER_SPAWN_EGG);
|
||||
CompoundTag ct = new CompoundTag();
|
||||
@@ -67,10 +72,7 @@ public class GiveCommand extends Command {
|
||||
}));
|
||||
|
||||
builder.then(literal("holo").then(argument("message", StringArgumentType.greedyString()).executes(ctx -> {
|
||||
if (!mc.player.abilities.creativeMode) {
|
||||
error("Not In Creative Mode!");
|
||||
return SINGLE_SUCCESS;
|
||||
}
|
||||
if (!mc.player.abilities.creativeMode) throw NOT_IN_CREATIVE.create();
|
||||
String message = ctx.getArgument("message", String.class);
|
||||
message = message.replace("&", "\247");
|
||||
ItemStack stack = new ItemStack(Items.ARMOR_STAND);
|
||||
@@ -92,10 +94,7 @@ public class GiveCommand extends Command {
|
||||
})));
|
||||
|
||||
builder.then(literal("firework").executes(ctx -> {
|
||||
if (!mc.player.abilities.creativeMode) {
|
||||
error("Not In Creative Mode!");
|
||||
return SINGLE_SUCCESS;
|
||||
}
|
||||
if (!mc.player.abilities.creativeMode) throw NOT_IN_CREATIVE.create();
|
||||
ItemStack firework = new ItemStack(Items.FIREWORK_ROCKET);
|
||||
CompoundTag baseCompound = new CompoundTag();
|
||||
CompoundTag tagCompound = new CompoundTag();
|
||||
@@ -124,10 +123,7 @@ public class GiveCommand extends Command {
|
||||
}));
|
||||
|
||||
builder.then(literal("head").then(argument("owner",StringArgumentType.greedyString()).executes(ctx -> {
|
||||
if (!mc.player.abilities.creativeMode) {
|
||||
error("Not In Creative Mode!");
|
||||
return SINGLE_SUCCESS;
|
||||
}
|
||||
if (!mc.player.abilities.creativeMode) throw NOT_IN_CREATIVE.create();
|
||||
String playerName = ctx.getArgument("owner",String.class);
|
||||
ItemStack itemStack = new ItemStack(Items.PLAYER_HEAD);
|
||||
CompoundTag tag = new CompoundTag();
|
||||
@@ -139,10 +135,7 @@ public class GiveCommand extends Command {
|
||||
|
||||
builder.then(literal("preset").then(argument("name", new EnumStringArgumentType(PRESETS))
|
||||
.then(argument("container", new EnumStringArgumentType(CONTAINERS)).executes(context -> {
|
||||
if (!mc.player.abilities.creativeMode) {
|
||||
error("Not In Creative Mode!");
|
||||
return SINGLE_SUCCESS;
|
||||
}
|
||||
if (!mc.player.abilities.creativeMode) throw NOT_IN_CREATIVE.create();
|
||||
String name = context.getArgument("name", String.class);
|
||||
String container = context.getArgument("container", String.class);
|
||||
addItem(createPreset(name, container));
|
||||
@@ -150,13 +143,13 @@ public class GiveCommand extends Command {
|
||||
}))));
|
||||
}
|
||||
|
||||
private void addItem(ItemStack item) {
|
||||
private void addItem(ItemStack item) throws CommandSyntaxException {
|
||||
for(int i = 0; i < 36; i++) {
|
||||
ItemStack stack = mc.player.inventory.getStack(SlotUtils.indexToId(i));
|
||||
if (!stack.isEmpty()) continue;
|
||||
mc.player.networkHandler.sendPacket(new CreativeInventoryActionC2SPacket(SlotUtils.indexToId(i), item));
|
||||
return;
|
||||
}
|
||||
error("No space in inventory.");
|
||||
throw NO_SPACE.create();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,14 @@ package cloudburst.rejects.commands;
|
||||
|
||||
import com.google.gson.*;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||
import minegame159.meteorclient.systems.commands.Command;
|
||||
import minegame159.meteorclient.systems.commands.arguments.PlayerArgumentType;
|
||||
import minegame159.meteorclient.utils.network.HttpUtils;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.PointerBuffer;
|
||||
@@ -22,6 +25,8 @@ import static com.mojang.brigadier.Command.SINGLE_SUCCESS;
|
||||
|
||||
public class SaveSkinCommand extends Command {
|
||||
|
||||
private final static SimpleCommandExceptionType IO_EXCEPTION = new SimpleCommandExceptionType(new LiteralText("An IOException occurred"));
|
||||
|
||||
private final PointerBuffer filters;
|
||||
private final Gson GSON = new Gson();
|
||||
|
||||
@@ -41,13 +46,14 @@ public class SaveSkinCommand extends Command {
|
||||
builder.then(argument("player", PlayerArgumentType.player()).executes(ctx -> {
|
||||
PlayerEntity playerEntity = ctx.getArgument("player", PlayerEntity.class);
|
||||
String path = TinyFileDialogs.tinyfd_saveFileDialog("Save image", null, filters, null);
|
||||
if (path == null) IO_EXCEPTION.create();
|
||||
if (!path.endsWith(".png")) path += ".png";
|
||||
saveSkin(playerEntity.getUuidAsString(),path);
|
||||
return SINGLE_SUCCESS;
|
||||
}));
|
||||
}
|
||||
|
||||
private void saveSkin(String uuid, String path) {
|
||||
private void saveSkin(String uuid, String path) throws CommandSyntaxException {
|
||||
try {
|
||||
//going to explain what happens so I don't forget
|
||||
//request their minecraft profile, all so we can get a base64 encoded string that contains ANOTHER json that then has the skin URL
|
||||
@@ -82,7 +88,7 @@ public class SaveSkinCommand extends Command {
|
||||
fos.write(response);
|
||||
fos.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw IO_EXCEPTION.create();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,11 @@ package cloudburst.rejects.commands;
|
||||
|
||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||
import minegame159.meteorclient.systems.commands.Command;
|
||||
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.text.LiteralText;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
@@ -22,6 +24,8 @@ public class TerrainExport extends Command {
|
||||
|
||||
private final PointerBuffer filters;
|
||||
|
||||
private final static SimpleCommandExceptionType IO_EXCEPTION = new SimpleCommandExceptionType(new LiteralText("An IOException occurred"));
|
||||
|
||||
public TerrainExport() {
|
||||
super("terrain-export", "Export an area to the c++ terrain finder format (very popbob command).");
|
||||
|
||||
@@ -51,8 +55,7 @@ public class TerrainExport extends Command {
|
||||
}
|
||||
|
||||
String path = TinyFileDialogs.tinyfd_saveFileDialog("Save data", null, filters, null);
|
||||
if (path == null)
|
||||
return SINGLE_SUCCESS;
|
||||
if (path == null) throw IO_EXCEPTION.create();
|
||||
if (!path.endsWith(".txt"))
|
||||
path += ".txt";
|
||||
try {
|
||||
@@ -60,7 +63,7 @@ public class TerrainExport extends Command {
|
||||
file.write(stringBuilder.toString().trim());
|
||||
file.close();
|
||||
} catch (IOException e) {
|
||||
error("IOException");
|
||||
throw IO_EXCEPTION.create();
|
||||
}
|
||||
|
||||
return SINGLE_SUCCESS;
|
||||
|
||||
Reference in New Issue
Block a user