Skip to content

Commit

Permalink
goToBlock fixes (#362)
Browse files Browse the repository at this point in the history
* - Fixed `goToBlock` that was not working correctly after introducing `cooldown` requirement.

* Removed debug print. Opsie..
  • Loading branch information
Baterka authored Nov 29, 2023
1 parent 072fd0b commit d7101b9
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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());
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit d7101b9

Please sign in to comment.