fix: fix most OOBs, and also fix maxY in WorldPlugin

This commit is contained in:
Chayapak 2024-11-02 18:18:47 +07:00
parent 3ad8b11494
commit b3615770dc
Signed by: ChomeNS
SSH key fingerprint: SHA256:0YoxhdyXsgbc0nfeB2N6FYE60mxMU7DS4uCUMaw2mvA
9 changed files with 24 additions and 5 deletions

View file

@ -56,7 +56,8 @@ public class ConsoleCommand extends Command {
// servers.find(server => server.toLowerCase().includes(args.join(' '))) in js i guess // servers.find(server => server.toLowerCase().includes(args.join(' '))) in js i guess
eachBot.console.consoleServer = servers.stream() eachBot.console.consoleServer = servers.stream()
.filter(eachServer -> eachServer.toLowerCase().contains(server)) .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))); context.sendOutput(Component.text("Set the console server to " + bot.console.consoleServer).color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor)));
} catch (ArrayIndexOutOfBoundsException e) { } catch (ArrayIndexOutOfBoundsException e) {

View file

@ -24,7 +24,11 @@ public class ValidateCommand extends Command {
public Component execute(CommandContext context) throws CommandException { public Component execute(CommandContext context) throws CommandException {
final Bot bot = context.bot; 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); 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); else if (bot.hashing.isCorrectOwnerHash(hash, context.userInputCommandName, context.sender)) return Component.text("Valid OwnerHash").color(NamedTextColor.GREEN);

View file

@ -10,6 +10,8 @@ public class ChatFunction extends EvalFunction {
@Override @Override
public Output execute(Object... args) { public Output execute(Object... args) {
if (args.length == 0) return null;
final String message = (String) args[0]; final String message = (String) args[0];
bot.chat.send(message); bot.chat.send(message);

View file

@ -10,6 +10,8 @@ public class CoreFunction extends EvalFunction {
@Override @Override
public Output execute(Object... args) { public Output execute(Object... args) {
if (args.length == 0) return null;
final String command = (String) args[0]; final String command = (String) args[0];
bot.core.run(command); bot.core.run(command);

View file

@ -10,6 +10,8 @@ public class CorePlaceBlockFunction extends EvalFunction {
@Override @Override
public Output execute(Object... args) { public Output execute(Object... args) {
if (args.length == 0) return null;
final String command = (String) args[0]; final String command = (String) args[0];
bot.core.runPlaceBlock(command); bot.core.runPlaceBlock(command);

View file

@ -94,6 +94,8 @@ public class CommandHandlerPlugin {
final String[] splitInput = input.trim().split("\\s+"); final String[] splitInput = input.trim().split("\\s+");
if (splitInput.length == 0) return null;
final String commandName = splitInput[0]; final String commandName = splitInput[0];
final Command command = findCommand(commands, commandName); final Command command = findCommand(commands, commandName);

View file

@ -70,6 +70,8 @@ public class EvalPlugin {
} }
socket.on("codeOutput", (args) -> { socket.on("codeOutput", (args) -> {
if (args.length < 3) return;
final int id = (int) args[0]; final int id = (int) args[0];
final boolean isError = (boolean) args[1]; final boolean isError = (boolean) args[1];
final String output = (String) args[2]; final String output = (String) args[2];

View file

@ -34,14 +34,17 @@ public class WorldPlugin extends Bot.Listener {
private void worldChanged (String dimension) { private void worldChanged (String dimension) {
final RegistryEntry currentDimension = registry.stream() final RegistryEntry currentDimension = registry.stream()
.filter(eachDimension -> eachDimension.getId().asString().equals(dimension)) .filter(eachDimension -> eachDimension.getId().asString().equals(dimension))
.toArray(RegistryEntry[]::new)[0]; .findFirst()
.orElse(null);
if (currentDimension == null) return;
final NbtMap data = currentDimension.getData(); final NbtMap data = currentDimension.getData();
if (data == null) return; if (data == null) return;
minY = data.getInt("min_y"); minY = data.getInt("min_y");
maxY = data.getInt("height"); maxY = data.getInt("height") + minY;
for (Listener listener : listeners) listener.worldChanged(dimension); for (Listener listener : listeners) listener.worldChanged(dimension);
} }

View file

@ -215,7 +215,8 @@ public class MidiConverter implements Converter {
shiftedInstrument = Arrays.stream(instrumentList) shiftedInstrument = Arrays.stream(instrumentList)
.filter(ins -> ins.offset == closest) .filter(ins -> ins.offset == closest)
.toArray(Instrument[]::new)[0]; .findFirst()
.orElse(null);
} }
} }