Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

goToBlock fixes #362

Merged
merged 3 commits into from
Nov 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading