Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions src/main/java/world/bentobox/aoneblock/AOneBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import world.bentobox.aoneblock.dataobjects.OneBlockIslands;
import world.bentobox.aoneblock.generators.ChunkGeneratorWorld;
import world.bentobox.aoneblock.listeners.BlockListener;
import world.bentobox.aoneblock.listeners.FinaleListener;
import world.bentobox.aoneblock.listeners.BlockProtect;
import world.bentobox.aoneblock.listeners.BossBarListener;
import world.bentobox.aoneblock.listeners.HoloListener;
Expand Down Expand Up @@ -195,6 +196,7 @@ public void onEnable() {
// Initialize and register listeners
blockListener = new BlockListener(this);
registerListener(blockListener);
registerListener(blockListener.getFinaleListener());
registerListener(new NoBlockHandler(this));
registerListener(new BlockProtect(this));
registerListener(new JoinLeaveListener(this));
Expand Down Expand Up @@ -243,6 +245,11 @@ public void onDisable() {
blockListener.saveCacheNow();
}

// Remove any bosses
if (blockListener != null) {
blockListener.getFinaleListener().onDisable();
}

// Clear holograms
if (holoListener != null) {
holoListener.onDisable();
Expand Down Expand Up @@ -402,6 +409,13 @@ public BlockListener getBlockListener() {
return blockListener;
}

/**
* @return the listener that runs phase finales
*/
public FinaleListener getFinaleListener() {
return blockListener == null ? null : blockListener.getFinaleListener();
}

/**
* Get the placeholder manager
*
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/world/bentobox/aoneblock/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,12 @@ public class Settings implements WorldSettings {
@ConfigEntry(path = "island.drop-on-top") // , since = "1.3.0")
private boolean dropOnTop = true;

@ConfigComment("Phase finales")
@ConfigComment("A phase whose file has a finale section ends with a boss that must be defeated")
@ConfigComment("before the magic block moves on to the next phase. Set to false to turn all finales off.")
@ConfigEntry(path = "island.phase-finales")
private boolean phaseFinales = true;

@ConfigComment("Magic block mob warning")
@ConfigComment("Players might be able to hear hostile mobs up to this many blocks away")
@ConfigComment("Minimum is 0 (no warning), max is 5")
Expand Down Expand Up @@ -1871,6 +1877,20 @@ public int getMobWarning() {
return mobWarning;
}

/**
* @return true if phase finales are enabled
*/
public boolean isPhaseFinales() {
return phaseFinales;
}

/**
* @param phaseFinales true to enable phase finales
*/
public void setPhaseFinales(boolean phaseFinales) {
this.phaseFinales = phaseFinales;
}

/**
* @param mobWarning the mobWarning to set
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public boolean execute(User user, String label, List<String> args) {
user.sendMessage("aoneblock.commands.admin.setcount.set-lifetime", TextVariables.NUMBER, String.valueOf(count), TextVariables.NAME, getPlayers().getName(targetUUID));
} else {
i.setBlockNumber(count);
addon.getFinaleListener().clear(island, i);
i.clearQueue();
user.sendMessage("aoneblock.commands.admin.setcount.set", TextVariables.NUMBER, String.valueOf(count), TextVariables.NAME, getPlayers().getName(targetUUID));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public boolean execute(User user, String label, List<String> args) {
}
i.setBlockNumber(count);
i.clearQueue();
addon.getFinaleListener().clear(island, i);
user.sendMessage("aoneblock.commands.island.setcount.set", TextVariables.NUMBER, String.valueOf(i.getBlockNumber()));
setCooldown(user.getUniqueId(), addon.getSettings().getSetCountCooldown() * 60);
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package world.bentobox.aoneblock.dataobjects;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.Set;
import java.util.List;
import java.util.Queue;

Expand Down Expand Up @@ -50,6 +52,23 @@ public class OneBlockIslands implements DataObject {
@Expose
private long lastPhaseChangeTime = 0;

/**
* Name of the phase whose finale boss must be defeated before the island can
* move on. Empty if no finale is pending.
*/
@Expose
private String finalePending = "";
/**
* How many times in a row the pending finale has been lost.
*/
@Expose
private int finaleFails = 0;
/**
* Names of the phases whose finale this island has defeated at least once.
*/
@Expose
private Set<String> defeatedFinales = new HashSet<>();

private Queue<OneBlockObject> queue = new LinkedList<>();

/**
Expand Down Expand Up @@ -227,4 +246,49 @@ public long getLastPhaseChangeTime() {
public void setLastPhaseChangeTime(long lastPhaseChangeTime) {
this.lastPhaseChangeTime = lastPhaseChangeTime;
}

/**
* @return name of the phase whose finale is pending, or an empty string
*/
public String getFinalePending() {
return finalePending == null ? "" : finalePending;
}

/**
* @param finalePending name of the phase whose finale is pending, or empty for none
*/
public void setFinalePending(String finalePending) {
this.finalePending = finalePending == null ? "" : finalePending;
}

/**
* @return how many times in a row the pending finale has been lost
*/
public int getFinaleFails() {
return finaleFails;
}

/**
* @param finaleFails how many times in a row the pending finale has been lost
*/
public void setFinaleFails(int finaleFails) {
this.finaleFails = finaleFails;
}

/**
* @return names of the phases whose finale has been defeated at least once
*/
public Set<String> getDefeatedFinales() {
if (defeatedFinales == null) {
defeatedFinales = new HashSet<>();
}
return defeatedFinales;
}

/**
* @param defeatedFinales names of the phases whose finale has been defeated
*/
public void setDefeatedFinales(Set<String> defeatedFinales) {
this.defeatedFinales = defeatedFinales;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package world.bentobox.aoneblock.events;

import java.util.UUID;

import org.bukkit.block.Block;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;

import world.bentobox.bentobox.database.objects.Island;

/**
* Fired when a phase finale ends, either because the boss was defeated or
* because it left (everyone died or went away, or the boss was removed).
* @author tastybento
*/
public class PhaseFinaleEndEvent extends AbstractMagicBlockEvent {

private static final HandlerList handlers = new HandlerList();
private final String phase;
private final boolean defeated;
private final boolean firstTime;

@Override
public HandlerList getHandlers() {
return getHandlerList();
}

public static HandlerList getHandlerList() {

Check warning on line 29 in src/main/java/world/bentobox/aoneblock/events/PhaseFinaleEndEvent.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this method; it hides "getHandlerList" in "BentoBoxEvent".

See more on https://sonarcloud.io/project/issues?id=BentoBoxWorld_AOneBlock&issues=AaHLohB4MTHYKDZflEuU&open=AaHLohB4MTHYKDZflEuU&pullRequest=566
return handlers;
}

/**
* @param island - island
* @param playerUUID - player who killed the boss, if any
* @param block - the magic block
* @param phase - name of the phase that is ending
* @param defeated - true if the boss was defeated
* @param firstTime - true if this is the first time this island defeated this boss
*/
public PhaseFinaleEndEvent(@NonNull Island island, @Nullable UUID playerUUID, @NonNull Block block,
@NonNull String phase, boolean defeated, boolean firstTime) {
super(island, playerUUID, block);
this.phase = phase;
this.defeated = defeated;
this.firstTime = firstTime;
}

/**
* @return the name of the phase that is ending
*/
@NonNull
public String getPhase() {
return phase;
}

/**
* @return true if the boss was defeated, false if the finale was abandoned
*/
public boolean isDefeated() {
return defeated;
}

/**
* @return true if this is the first time the island defeated this boss
*/
public boolean isFirstTime() {
return firstTime;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package world.bentobox.aoneblock.events;

import java.util.UUID;

import org.bukkit.block.Block;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;

import world.bentobox.aoneblock.oneblocks.PhaseFinale;
import world.bentobox.bentobox.database.objects.Island;

/**
* Fired when a phase finale is about to start, before the boss spawns.
* Cancelling it waives the finale: no boss spawns and the island may move on
* to the next phase.
* @author tastybento
*/
public class PhaseFinaleStartEvent extends AbstractMagicBlockEvent implements Cancellable {

private static final HandlerList handlers = new HandlerList();
private final String phase;
private final PhaseFinale finale;
private boolean cancelled;

@Override
public HandlerList getHandlers() {
return getHandlerList();
}

public static HandlerList getHandlerList() {

Check warning on line 32 in src/main/java/world/bentobox/aoneblock/events/PhaseFinaleStartEvent.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this method; it hides "getHandlerList" in "BentoBoxEvent".

See more on https://sonarcloud.io/project/issues?id=BentoBoxWorld_AOneBlock&issues=AaHLohB2MTHYKDZflEuT&open=AaHLohB2MTHYKDZflEuT&pullRequest=566
return handlers;
}

/**
* @param island - island
* @param playerUUID - player who triggered the finale
* @param block - the magic block
* @param phase - name of the phase that is ending
* @param finale - the finale definition
*/
public PhaseFinaleStartEvent(@NonNull Island island, @Nullable UUID playerUUID, @NonNull Block block,
@NonNull String phase, @NonNull PhaseFinale finale) {
super(island, playerUUID, block);
this.phase = phase;
this.finale = finale;
}

/**
* @return the name of the phase that is ending
*/
@NonNull
public String getPhase() {
return phase;
}

/**
* @return the finale definition
*/
@NonNull
public PhaseFinale getFinale() {
return finale;
}

@Override
public boolean isCancelled() {
return cancelled;
}

@Override
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ private record BrushSession(BukkitTask task, Block block) {}
*/
private final WarningSounder warningSounder;

/**
* Runs the boss fights that end phases.
*/
private final FinaleListener finaleListener;

/**
* How many blocks ahead the queue should look when populating.
*/
Expand Down Expand Up @@ -171,6 +176,7 @@ public BlockListener(@NonNull AOneBlock addon) {
oneBlocksManager = addon.getOneBlockManager();
check = new CheckPhase(addon, this);
warningSounder = new WarningSounder(addon);
finaleListener = new FinaleListener(addon);
}

/**
Expand Down Expand Up @@ -483,6 +489,11 @@ private ProcessPhaseResult processPhase(Cancellable e, Island i, OneBlockIslands

boolean isCurrPhaseNew = !is.getPhaseName().equalsIgnoreCase(currPhaseName);
if (isCurrPhaseNew) {
// The old phase's boss, if it has one, must be defeated first.
if (finaleListener.gate(i, is, player, block)) {
e.setCancelled(true);
return new ProcessPhaseResult(phase, true, 0);
}
// Check if the player meets the requirements for the new phase.
if (check.phaseRequirementsFail(player, i, is, phase, world)) {
e.setCancelled(true);
Expand Down Expand Up @@ -566,6 +577,9 @@ private void processHologramAndWarnings(Island i, OneBlockIslands is, OneBlockPh
if (addon.getSettings().getMobWarning() > 0) {
warningSounder.play(is, block);
}
if (addon.getSettings().isPhaseFinales() && phase.getFinale() != null) {
warningSounder.omen(block, phase.getFinale(), oneBlocksManager.getNextPhaseBlocks(is));
}
}

/**
Expand All @@ -589,6 +603,8 @@ private void processNextBlock(Cancellable e, Island i, Player player, Block bloc
}

is.incrementBlockNumber();
// If that was the last block of the phase, its boss is next
finaleListener.arm(is, phaseResult.phase);
handleBlockBreak(e, i, player, block, nextBlock);
}

Expand Down Expand Up @@ -1086,6 +1102,20 @@ public OneBlocksManager getOneBlocksManager() {
return oneBlocksManager;
}

/**
* @return the phase checker
*/
CheckPhase getCheckPhase() {
return check;
}

/**
* @return the listener that runs phase finales
*/
public FinaleListener getFinaleListener() {
return finaleListener;
}

/**
* Saves the island progress to the database async
*
Expand Down
Loading
Loading