From 1c4690329c1b935e95ceb06f839394b7183c7bb3 Mon Sep 17 00:00:00 2001 From: Baterka Date: Wed, 29 Nov 2023 16:54:39 +0100 Subject: [PATCH 1/2] - Fixed `goToBlock` that was not working correctly after introducing `cooldown` requirement. --- .../aoneblock/listeners/BlockListener.java | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java b/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java index 663c1205..05f527a3 100644 --- a/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java +++ b/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java @@ -50,6 +50,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; @@ -275,9 +276,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 @@ -286,9 +287,16 @@ 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(); + BentoBox.getInstance().logWarning("Block number = " + is.getBlockNumber() + ", PrevPhase = " + prevPhaseName + ", CurrPhase = " + currPhaseName + ", NextPhase = " + nextPhaseName); + // If next phase is new, log break time of the last block of this phase if (!currPhaseName.equalsIgnoreCase(nextPhaseName)) { is.setLastPhaseChangeTime(System.currentTimeMillis()); @@ -297,10 +305,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); @@ -380,13 +389,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) { From 9ea672e0a3964c2bbdaf2ade287c6c71ac9c8605 Mon Sep 17 00:00:00 2001 From: Baterka Date: Wed, 29 Nov 2023 16:58:46 +0100 Subject: [PATCH 2/2] Removed debug print. Opsie.. --- .../world/bentobox/aoneblock/listeners/BlockListener.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java b/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java index 6fddf8c7..90ee62ad 100644 --- a/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java +++ b/src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java @@ -293,9 +293,7 @@ private void process(@NonNull Cancellable e, @NonNull Island i, @Nullable Player // Get next phase name String nextPhaseName = nextPhase == null || nextPhase.getPhaseName() == null ? "" : nextPhase.getPhaseName(); - - BentoBox.getInstance().logWarning("Block number = " + is.getBlockNumber() + ", PrevPhase = " + prevPhaseName + ", CurrPhase = " + currPhaseName + ", NextPhase = " + nextPhaseName); - + // If next phase is new, log break time of the last block of this phase if (!currPhaseName.equalsIgnoreCase(nextPhaseName)) { is.setLastPhaseChangeTime(System.currentTimeMillis());