From 7310537cf604a950027b9218eeeffd279f2f1b64 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 23 Jul 2023 11:48:18 -0700 Subject: [PATCH 1/2] Small refactor to reduce complexity --- .../aoneblock/listeners/BlockListener.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java b/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java index ded058a..bc11b62 100644 --- a/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java +++ b/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java @@ -278,13 +278,7 @@ private void process(@NonNull Cancellable e, @NonNull Island i, @Nullable Player String originalPhase = is.getPhaseName(); // Check for a goto if (Objects.requireNonNull(phase).getGotoBlock() != null) { - int gotoBlock = phase.getGotoBlock(); - phase = oneBlocksManager.getPhase(gotoBlock); - // Store lifetime - is.setLifetime(is.getLifetime() + gotoBlock); - // Set current block - is.setBlockNumber(gotoBlock); - + handleGoto(is, phase); } // Check for new phase and run commands if required boolean newPhase = check.checkPhase(player, i, is, Objects.requireNonNull(phase)); @@ -355,6 +349,15 @@ private void process(@NonNull Cancellable e, @NonNull Island i, @Nullable Player is.incrementBlockNumber(); } + private void handleGoto(OneBlockIslands is, OneBlockPhase phase) { + int gotoBlock = phase.getGotoBlock(); + phase = oneBlocksManager.getPhase(gotoBlock); + // Store lifetime + is.setLifetime(is.getLifetime() + gotoBlock); + // Set current block + is.setBlockNumber(gotoBlock); + } + private void setBiome(@NonNull Block block, @Nullable Biome biome) { if (biome == null) { return; From 53783f503291f606f79c031948b404ce570d45b2 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 23 Jul 2023 12:11:36 -0700 Subject: [PATCH 2/2] Do not generate multiple listeners https://github.com/BentoBoxWorld/AOneBlock/issues/326 --- .../world/bentobox/aoneblock/AOneBlock.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/world/bentobox/aoneblock/AOneBlock.java b/src/main/java/world/bentobox/aoneblock/AOneBlock.java index ca46ae7..e87660e 100644 --- a/src/main/java/world/bentobox/aoneblock/AOneBlock.java +++ b/src/main/java/world/bentobox/aoneblock/AOneBlock.java @@ -88,8 +88,13 @@ private boolean loadSettings() { @Override public void onEnable() { - loadData(); - + oneBlockManager = new OneBlocksManager(this); + if (loadData()) { + // Failed to load - don't register anything + return; + } + blockListener = new BlockListener(this); + registerListener(blockListener); registerListener(new NoBlockHandler(this)); registerListener(new BlockProtect(this)); registerListener(new JoinLeaveListener(this)); @@ -106,20 +111,18 @@ public void onEnable() { registerListener(holoListener); } - //Load some of Manager - public void loadData() { + // Load phase data + public boolean loadData() { try { - oneBlockManager = new OneBlocksManager(this); oneBlockManager.loadPhases(); - blockListener = new BlockListener(this); } catch (IOException e) { // Disable logError("AOneBlock settings could not load (oneblock.yml error)! Addon disabled."); logError(e.getMessage()); setState(State.DISABLED); - return; + return true; } - registerListener(blockListener); + return false; } private void registerPlaceholders() {