diff --git a/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java b/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java index 4ba143dc..90ee62ad 100644 --- a/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java +++ b/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java @@ -49,6 +49,7 @@ import world.bentobox.aoneblock.oneblocks.OneBlockObject; import world.bentobox.aoneblock.oneblocks.OneBlockPhase; import world.bentobox.aoneblock.oneblocks.OneBlocksManager; +import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.api.events.island.IslandCreatedEvent; import world.bentobox.bentobox.api.events.island.IslandDeleteEvent; import world.bentobox.bentobox.api.events.island.IslandResettedEvent; @@ -274,9 +275,9 @@ private void process(@NonNull Cancellable e, @NonNull Island i, @Nullable Player // Save previous processing phase name String prevPhaseName = is.getPhaseName(); - // Check for a goto - if (Objects.requireNonNull(phase).getGotoBlock() != null) { - handleGoto(is, phase); + // Check if phase contains `gotoBlock` + if(Objects.requireNonNull(phase).getGotoBlock() != null){ + phase = handleGoto(is, phase.getGotoBlock()); } // Get current phase name @@ -285,9 +286,14 @@ private void process(@NonNull Cancellable e, @NonNull Island i, @Nullable Player // Get the phase for next block number OneBlockPhase nextPhase = oneBlocksManager.getPhase(is.getBlockNumber() + 1); + // Check if nextPhase contains `gotoBlock` and override `nextPhase` + if (Objects.requireNonNull(nextPhase).getGotoBlock() != null) { + nextPhase = oneBlocksManager.getPhase(nextPhase.getGotoBlock()); + } + // Get next phase name String nextPhaseName = nextPhase == null || nextPhase.getPhaseName() == null ? "" : nextPhase.getPhaseName(); - + // If next phase is new, log break time of the last block of this phase if (!currPhaseName.equalsIgnoreCase(nextPhaseName)) { is.setLastPhaseChangeTime(System.currentTimeMillis()); @@ -296,10 +302,11 @@ private void process(@NonNull Cancellable e, @NonNull Island i, @Nullable Player boolean isCurrPhaseNew = !is.getPhaseName().equalsIgnoreCase(currPhaseName); if (isCurrPhaseNew) { + // Check if requirements for new phase are met if (check.phaseRequirementsFail(player, i, is, phase, world)) { - e.setCancelled(true); - return; + e.setCancelled(true); + return; } check.setNewPhase(player, i, is, phase); @@ -379,13 +386,12 @@ 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 OneBlockPhase handleGoto(OneBlockIslands is, int gotoBlock) { + // Store lifetime + is.setLifetime(is.getLifetime() + gotoBlock); + // Set current block + is.setBlockNumber(gotoBlock); + return oneBlocksManager.getPhase(gotoBlock); } private void setBiome(@NonNull Block block, @Nullable Biome biome) {