Skip to content

Commit d7101b9

Browse files
authored
goToBlock fixes (#362)
* - Fixed `goToBlock` that was not working correctly after introducing `cooldown` requirement. * Removed debug print. Opsie..
1 parent 072fd0b commit d7101b9

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import world.bentobox.aoneblock.oneblocks.OneBlockObject;
5050
import world.bentobox.aoneblock.oneblocks.OneBlockPhase;
5151
import world.bentobox.aoneblock.oneblocks.OneBlocksManager;
52+
import world.bentobox.bentobox.BentoBox;
5253
import world.bentobox.bentobox.api.events.island.IslandCreatedEvent;
5354
import world.bentobox.bentobox.api.events.island.IslandDeleteEvent;
5455
import world.bentobox.bentobox.api.events.island.IslandResettedEvent;
@@ -274,9 +275,9 @@ private void process(@NonNull Cancellable e, @NonNull Island i, @Nullable Player
274275
// Save previous processing phase name
275276
String prevPhaseName = is.getPhaseName();
276277

277-
// Check for a goto
278-
if (Objects.requireNonNull(phase).getGotoBlock() != null) {
279-
handleGoto(is, phase);
278+
// Check if phase contains `gotoBlock`
279+
if(Objects.requireNonNull(phase).getGotoBlock() != null){
280+
phase = handleGoto(is, phase.getGotoBlock());
280281
}
281282

282283
// Get current phase name
@@ -285,9 +286,14 @@ private void process(@NonNull Cancellable e, @NonNull Island i, @Nullable Player
285286
// Get the phase for next block number
286287
OneBlockPhase nextPhase = oneBlocksManager.getPhase(is.getBlockNumber() + 1);
287288

289+
// Check if nextPhase contains `gotoBlock` and override `nextPhase`
290+
if (Objects.requireNonNull(nextPhase).getGotoBlock() != null) {
291+
nextPhase = oneBlocksManager.getPhase(nextPhase.getGotoBlock());
292+
}
293+
288294
// Get next phase name
289295
String nextPhaseName = nextPhase == null || nextPhase.getPhaseName() == null ? "" : nextPhase.getPhaseName();
290-
296+
291297
// If next phase is new, log break time of the last block of this phase
292298
if (!currPhaseName.equalsIgnoreCase(nextPhaseName)) {
293299
is.setLastPhaseChangeTime(System.currentTimeMillis());
@@ -296,10 +302,11 @@ private void process(@NonNull Cancellable e, @NonNull Island i, @Nullable Player
296302
boolean isCurrPhaseNew = !is.getPhaseName().equalsIgnoreCase(currPhaseName);
297303

298304
if (isCurrPhaseNew) {
305+
299306
// Check if requirements for new phase are met
300307
if (check.phaseRequirementsFail(player, i, is, phase, world)) {
301-
e.setCancelled(true);
302-
return;
308+
e.setCancelled(true);
309+
return;
303310
}
304311

305312
check.setNewPhase(player, i, is, phase);
@@ -379,13 +386,12 @@ private void process(@NonNull Cancellable e, @NonNull Island i, @Nullable Player
379386
is.incrementBlockNumber();
380387
}
381388

382-
private void handleGoto(OneBlockIslands is, OneBlockPhase phase) {
383-
int gotoBlock = phase.getGotoBlock();
384-
phase = oneBlocksManager.getPhase(gotoBlock);
385-
// Store lifetime
386-
is.setLifetime(is.getLifetime() + gotoBlock);
387-
// Set current block
388-
is.setBlockNumber(gotoBlock);
389+
private OneBlockPhase handleGoto(OneBlockIslands is, int gotoBlock) {
390+
// Store lifetime
391+
is.setLifetime(is.getLifetime() + gotoBlock);
392+
// Set current block
393+
is.setBlockNumber(gotoBlock);
394+
return oneBlocksManager.getPhase(gotoBlock);
389395
}
390396

391397
private void setBiome(@NonNull Block block, @Nullable Biome biome) {

0 commit comments

Comments
 (0)