From ce173298d8ce6ca1c50bc9cbde9a97e139d9eba9 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Fri, 5 May 2023 20:33:29 +0700 Subject: [PATCH] make core start and end configurable --- .../chayapak/chomens_bot/Configuration.java | 9 +++- .../chomens_bot/plugins/CorePlugin.java | 47 +++++++++++++++---- src/main/resources/default-config.yml | 9 +++- 3 files changed, 54 insertions(+), 11 deletions(-) diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/Configuration.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/Configuration.java index dd0ee1d2..3398061b 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/Configuration.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/Configuration.java @@ -32,11 +32,18 @@ public class Configuration { @Getter public BotOption[] bots = new BotOption[]{}; public static class Core { - @Getter public int layers = 3; + @Getter public Position start = new Position(); + @Getter public Position end = new Position(); @Getter public int refillInterval = (60 * 5) * 1000; // 5 minutes @Getter public String customName = "[{\"text\":\"ChomeNS \",\"color\":\"yellow\"},{\"text\":\"Core\",\"color\":\"green\"},{\"text\":\"™\",\"color\":\"gold\"}]"; } + public static class Position { + @Getter public int x = 0; + @Getter public int y = 0; + @Getter public int z = 0; + } + public static class Discord { @Getter public String prefix = "default!"; @Getter public String token; diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CorePlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CorePlugin.java index 385b5724..efca6339 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CorePlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CorePlugin.java @@ -41,13 +41,13 @@ public class CorePlugin extends PositionPlugin.Listener { private ScheduledFuture refillTask; - public final Vector3i coreStart = Vector3i.from(0, 0, 0); - public Vector3i coreEnd; + public final Vector3i coreStart; + public final Vector3i coreEnd; public Vector3i origin; public Vector3i originEnd; - public Vector3i relativeCorePosition = Vector3i.from(coreStart); + public Vector3i relativeCorePosition; private int nextTransactionId = 0; private final Map> transactions = new HashMap<>(); @@ -58,6 +58,19 @@ public class CorePlugin extends PositionPlugin.Listener { this.bot = bot; this.kaboom = bot.options().kaboom(); + this.coreStart = Vector3i.from( + bot.config().core().start().x(), + bot.config().core().start().y(), + bot.config().core().start().z() + ); + this.coreEnd = Vector3i.from( + bot.config().core().end().x(), + bot.config().core().end().y(), + bot.config().core().end().z() + ); + + this.relativeCorePosition = Vector3i.from(coreStart); + bot.position().addListener(this); bot.addListener(new Bot.Listener() { @@ -241,12 +254,28 @@ public class CorePlugin extends PositionPlugin.Listener { @Override public void positionChange (Vector3i position) { - coreEnd = Vector3i.from(15, bot.config().core().layers() - 1, 15); - origin = Vector3i.from( - Math.floor((double) bot.position().position().getX() / 16) * 16, - 0, - Math.floor((double) bot.position().position().getZ() / 16) * 16 - ); + // hm? + if ( + coreStart.getX() == 0 && + coreStart.getY() == 0 && + coreStart.getZ() == 0 && + + coreEnd.getX() == 15 && + coreEnd.getY() == 2 && + coreEnd.getZ() == 15 + ) { + origin = Vector3i.from( + Math.floor((double) bot.position().position().getX() / 16) * 16, + 0, + Math.floor((double) bot.position().position().getZ() / 16) * 16 + ); + } else { + origin = Vector3i.from( + bot.position().position().getX(), + 0, + bot.position().position().getZ() + ); + } originEnd = origin.add(coreEnd); refill(); diff --git a/src/main/resources/default-config.yml b/src/main/resources/default-config.yml index 376afe95..0aeceb32 100644 --- a/src/main/resources/default-config.yml +++ b/src/main/resources/default-config.yml @@ -35,7 +35,14 @@ keys: weatherApiKey: 'key here' # weatherapi.com key core: - layers: 3 + start: + x: 0 + y: 0 + z: 0 + end: + x: 15 + y: 2 + z: 15 refillInterval: 300000 # (60 * 5) * 1000 (5 minutes) # PLEASE give valid JSON component here else the core don't refill at all customName: '[{"text":"ChomeNS ","color":"yellow"},{"text":"Core","color":"green"},{"text":"™","color":"gold"}]'