From b3615770dcabbbb249f01ea0df765e58ab81089e Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sat, 2 Nov 2024 18:18:47 +0700 Subject: [PATCH] fix: fix most OOBs, and also fix maxY in WorldPlugin --- .../me/chayapak1/chomens_bot/commands/ConsoleCommand.java | 3 ++- .../me/chayapak1/chomens_bot/commands/ValidateCommand.java | 6 +++++- .../chayapak1/chomens_bot/evalFunctions/ChatFunction.java | 2 ++ .../chayapak1/chomens_bot/evalFunctions/CoreFunction.java | 2 ++ .../chomens_bot/evalFunctions/CorePlaceBlockFunction.java | 2 ++ .../chomens_bot/plugins/CommandHandlerPlugin.java | 2 ++ .../java/me/chayapak1/chomens_bot/plugins/EvalPlugin.java | 2 ++ .../java/me/chayapak1/chomens_bot/plugins/WorldPlugin.java | 7 +++++-- .../java/me/chayapak1/chomens_bot/song/MidiConverter.java | 3 ++- 9 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/main/java/me/chayapak1/chomens_bot/commands/ConsoleCommand.java b/src/main/java/me/chayapak1/chomens_bot/commands/ConsoleCommand.java index 3d11bbf..4bcf19b 100644 --- a/src/main/java/me/chayapak1/chomens_bot/commands/ConsoleCommand.java +++ b/src/main/java/me/chayapak1/chomens_bot/commands/ConsoleCommand.java @@ -56,7 +56,8 @@ public class ConsoleCommand extends Command { // servers.find(server => server.toLowerCase().includes(args.join(' '))) in js i guess eachBot.console.consoleServer = servers.stream() .filter(eachServer -> eachServer.toLowerCase().contains(server)) - .toArray(String[]::new)[0]; + .findFirst() + .orElse("all"); context.sendOutput(Component.text("Set the console server to " + bot.console.consoleServer).color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor))); } catch (ArrayIndexOutOfBoundsException e) { diff --git a/src/main/java/me/chayapak1/chomens_bot/commands/ValidateCommand.java b/src/main/java/me/chayapak1/chomens_bot/commands/ValidateCommand.java index a89e096..451e75b 100644 --- a/src/main/java/me/chayapak1/chomens_bot/commands/ValidateCommand.java +++ b/src/main/java/me/chayapak1/chomens_bot/commands/ValidateCommand.java @@ -24,7 +24,11 @@ public class ValidateCommand extends Command { public Component execute(CommandContext context) throws CommandException { final Bot bot = context.bot; - final String hash = context.fullArgs[0]; + final String[] fullArgs = context.fullArgs; + + if (fullArgs.length == 0) return null; + + final String hash = fullArgs[0]; if (bot.hashing.isCorrectHash(hash, context.userInputCommandName, context.sender)) return Component.text("Valid hash").color(NamedTextColor.GREEN); else if (bot.hashing.isCorrectOwnerHash(hash, context.userInputCommandName, context.sender)) return Component.text("Valid OwnerHash").color(NamedTextColor.GREEN); diff --git a/src/main/java/me/chayapak1/chomens_bot/evalFunctions/ChatFunction.java b/src/main/java/me/chayapak1/chomens_bot/evalFunctions/ChatFunction.java index e764ecc..475a3f9 100644 --- a/src/main/java/me/chayapak1/chomens_bot/evalFunctions/ChatFunction.java +++ b/src/main/java/me/chayapak1/chomens_bot/evalFunctions/ChatFunction.java @@ -10,6 +10,8 @@ public class ChatFunction extends EvalFunction { @Override public Output execute(Object... args) { + if (args.length == 0) return null; + final String message = (String) args[0]; bot.chat.send(message); diff --git a/src/main/java/me/chayapak1/chomens_bot/evalFunctions/CoreFunction.java b/src/main/java/me/chayapak1/chomens_bot/evalFunctions/CoreFunction.java index 46c0029..e0733ec 100644 --- a/src/main/java/me/chayapak1/chomens_bot/evalFunctions/CoreFunction.java +++ b/src/main/java/me/chayapak1/chomens_bot/evalFunctions/CoreFunction.java @@ -10,6 +10,8 @@ public class CoreFunction extends EvalFunction { @Override public Output execute(Object... args) { + if (args.length == 0) return null; + final String command = (String) args[0]; bot.core.run(command); diff --git a/src/main/java/me/chayapak1/chomens_bot/evalFunctions/CorePlaceBlockFunction.java b/src/main/java/me/chayapak1/chomens_bot/evalFunctions/CorePlaceBlockFunction.java index 9078208..f59fc6c 100644 --- a/src/main/java/me/chayapak1/chomens_bot/evalFunctions/CorePlaceBlockFunction.java +++ b/src/main/java/me/chayapak1/chomens_bot/evalFunctions/CorePlaceBlockFunction.java @@ -10,6 +10,8 @@ public class CorePlaceBlockFunction extends EvalFunction { @Override public Output execute(Object... args) { + if (args.length == 0) return null; + final String command = (String) args[0]; bot.core.runPlaceBlock(command); diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/CommandHandlerPlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/CommandHandlerPlugin.java index 43991a9..0d74489 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/CommandHandlerPlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/CommandHandlerPlugin.java @@ -94,6 +94,8 @@ public class CommandHandlerPlugin { final String[] splitInput = input.trim().split("\\s+"); + if (splitInput.length == 0) return null; + final String commandName = splitInput[0]; final Command command = findCommand(commands, commandName); diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/EvalPlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/EvalPlugin.java index 6e5ab51..43b8d42 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/EvalPlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/EvalPlugin.java @@ -70,6 +70,8 @@ public class EvalPlugin { } socket.on("codeOutput", (args) -> { + if (args.length < 3) return; + final int id = (int) args[0]; final boolean isError = (boolean) args[1]; final String output = (String) args[2]; diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/WorldPlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/WorldPlugin.java index cbc3a24..5dcfa83 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/WorldPlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/WorldPlugin.java @@ -34,14 +34,17 @@ public class WorldPlugin extends Bot.Listener { private void worldChanged (String dimension) { final RegistryEntry currentDimension = registry.stream() .filter(eachDimension -> eachDimension.getId().asString().equals(dimension)) - .toArray(RegistryEntry[]::new)[0]; + .findFirst() + .orElse(null); + + if (currentDimension == null) return; final NbtMap data = currentDimension.getData(); if (data == null) return; minY = data.getInt("min_y"); - maxY = data.getInt("height"); + maxY = data.getInt("height") + minY; for (Listener listener : listeners) listener.worldChanged(dimension); } diff --git a/src/main/java/me/chayapak1/chomens_bot/song/MidiConverter.java b/src/main/java/me/chayapak1/chomens_bot/song/MidiConverter.java index 6d66547..0bf47a2 100644 --- a/src/main/java/me/chayapak1/chomens_bot/song/MidiConverter.java +++ b/src/main/java/me/chayapak1/chomens_bot/song/MidiConverter.java @@ -215,7 +215,8 @@ public class MidiConverter implements Converter { shiftedInstrument = Arrays.stream(instrumentList) .filter(ins -> ins.offset == closest) - .toArray(Instrument[]::new)[0]; + .findFirst() + .orElse(null); } }