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
4 changes: 4 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ mvn verify + SonarCloud), Jenkins at ci.codemc.org builds release jars on master
finds the aimed locked chunk).
- `listeners/LevelListener.java` — Level addon integration: credit announcements,
LIFO re-locks on level loss, claim celebrations, island create/reset handling.
- `listeners/FinaleListener.java` — phase finales: the boss (from a phase file's `finale:`
section) that seals the magic block at the end of a phase until it is killed. Shared with
AOneBlock; the only ChunkBlock-specific part is the leash that keeps the boss out of
locked chunks.
- `oneblocks/`, `listeners/BlockListener.java`, phases under `src/main/resources/phases/`
— the magic-block engine copied from AOneBlock; avoid diverging from upstream so fixes
can be ported.
Expand Down
16 changes: 5 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<mock-bukkit.version>4.110.0</mock-bukkit.version>
<!-- More visible way how to change dependency versions -->
<bentobox.version>3.22.0</bentobox.version>
<items-adder.version>4.0.10</items-adder.version>
<items-adder.version>4.0.17</items-adder.version>
<nexo.version>1.8.0</nexo.version>
<craftengine.version>0.0.67</craftengine.version>
<level.version>2.6.2</level.version>
Expand All @@ -67,7 +67,7 @@
<!-- Do not change unless you want different name for local builds. -->
<build.number>-LOCAL</build.number>
<!-- This allows to change between versions. -->
<build.version>1.4.1</build.version>
<build.version>1.5.0</build.version>
<!-- SonarCloud -->
<sonar.projectKey>BentoBoxWorld_ChunkBlock</sonar.projectKey>
<sonar.organization>bentobox-world</sonar.organization>
Expand Down Expand Up @@ -147,13 +147,6 @@
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<!-- ItemsAdder API -->
<repository>
<id>matteodev</id>
<url>https://maven.devs.beer/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</repository>
<!-- Nexo API -->
<repository>
<id>nexomc</id>
Expand Down Expand Up @@ -269,8 +262,9 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>dev.lone</groupId>
<artifactId>api-itemsadder</artifactId>
<!-- Published to Maven Central -->
<groupId>beer.devs</groupId>
<artifactId>itemsadder-api</artifactId>
<version>${items-adder.version}</version>
<scope>provided</scope>
</dependency>
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/world/bentobox/chunkblock/ChunkBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import world.bentobox.chunkblock.dataobjects.OneBlockIslands;
import world.bentobox.chunkblock.generators.ChunkGeneratorWorld;
import world.bentobox.chunkblock.listeners.BlockListener;
import world.bentobox.chunkblock.listeners.FinaleListener;
import world.bentobox.chunkblock.listeners.BlockProtect;
import world.bentobox.chunkblock.listeners.ChunkClaimListener;
import world.bentobox.chunkblock.listeners.ChunkGuardListener;
Expand Down Expand Up @@ -263,6 +264,7 @@ public void onEnable() {
// Initialize and register listeners
blockListener = new BlockListener(this);
registerListener(blockListener);
registerListener(blockListener.getFinaleListener());
chunkGuardListener = new ChunkGuardListener(this);
registerListener(chunkGuardListener);
registerListener(new LockedChunkProtect(this));
Expand Down Expand Up @@ -331,6 +333,11 @@ public void onDisable() {
borderDisplay.stop();
}

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

// Clear holograms
if (holoListener != null) {
holoListener.onDisable();
Expand Down Expand Up @@ -548,6 +555,13 @@ public OneBlocksManager getOneBlockManager() {
return oneBlockManager;
}

/**
* @return the blockListener
*/
public FinaleListener getFinaleListener() {
return blockListener == null ? null : blockListener.getFinaleListener();
}

/**
* @return the blockListener
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ public String getNextRingRemaining(User user) {
}

/**
* Get the user's owned island. Returns the island owned by the user, not a team
* island they may be visiting as a member. If the user owns more than one island,
* one is picked.
* Get the user's island. Prefers an island the user owns; if they own none,
* falls back to the team island they are a member of. If the user owns more
* than one island, one is picked.
* @param user user
* @return island owned by the user, or empty if they own none
* @return island owned by the user, or their team island, or empty if neither exists
*/
private Optional<Island> getUsersIsland(User user) {
// Get the active island for the user
Expand All @@ -201,8 +201,14 @@ private Optional<Island> getUsersIsland(User user) {
return Optional.of(i);
}

// Find an island the user actually owns (not just a team island they are visiting)
return addon.getIslands().getOwnedIslands(addon.getOverWorld(), user).stream().findFirst();
// Prefer an island the user actually owns (not just a team island they are a member of)
Optional<Island> owned = addon.getIslands().getOwnedIslands(addon.getOverWorld(), user).stream().findFirst();
if (owned.isPresent()) {
return owned;
}

// Fall back to the team island the user is a member of, if any
return Optional.ofNullable(i);
}

public String getPhaseBlocksNames(User user) {
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/world/bentobox/chunkblock/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,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 @@ -1969,6 +1975,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("chunkblock.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("chunkblock.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("chunkblock.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
Expand Up @@ -95,6 +95,23 @@ public class OneBlockIslands implements DataObject {
/** Fast membership view of {@link #unlockedChunks}; rebuilt lazily after loads/edits */
private Set<Long> unlockedSet;

/**
* 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<>();

private static long chunkKey(int dx, int dz) {
Expand Down Expand Up @@ -423,4 +440,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.chunkblock.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() {
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;
}
}
Loading
Loading