From 06804850959261b5b97ee120d17593621f7090bd Mon Sep 17 00:00:00 2001 From: Pedro <3602279+Doc94@users.noreply.github.com> Date: Wed, 12 Feb 2025 19:24:46 -0300 Subject: [PATCH] Expand TrialSpawner API (#12025) --- build-data/paper.at | 2 + .../java/org/bukkit/block/TrialSpawner.java | 69 +++++++++++++------ .../craftbukkit/block/CraftTrialSpawner.java | 20 ++++++ 3 files changed, 70 insertions(+), 21 deletions(-) diff --git a/build-data/paper.at b/build-data/paper.at index 8e27f7157..d1158d474 100644 --- a/build-data/paper.at +++ b/build-data/paper.at @@ -625,8 +625,10 @@ public net.minecraft.world.level.block.entity.TheEndGatewayBlockEntity exitPorta public net.minecraft.world.level.block.entity.TrialSpawnerBlockEntity trialSpawner public net.minecraft.world.level.block.entity.trialspawner.TrialSpawner isOminous public net.minecraft.world.level.block.entity.trialspawner.TrialSpawner stateAccessor +public net.minecraft.world.level.block.entity.trialspawner.TrialSpawnerData cooldownEndsAt public net.minecraft.world.level.block.entity.trialspawner.TrialSpawnerData currentMobs public net.minecraft.world.level.block.entity.trialspawner.TrialSpawnerData detectedPlayers +public net.minecraft.world.level.block.entity.trialspawner.TrialSpawnerData nextMobSpawnsAt public net.minecraft.world.level.block.entity.trialspawner.TrialSpawnerData nextSpawnData public net.minecraft.world.level.block.entity.vault.VaultBlockEntity serverData public net.minecraft.world.level.block.entity.vault.VaultServerData getRewardedPlayers()Ljava/util/Set; diff --git a/paper-api/src/main/java/org/bukkit/block/TrialSpawner.java b/paper-api/src/main/java/org/bukkit/block/TrialSpawner.java index 6c1e3b5f3..03263a270 100644 --- a/paper-api/src/main/java/org/bukkit/block/TrialSpawner.java +++ b/paper-api/src/main/java/org/bukkit/block/TrialSpawner.java @@ -4,26 +4,57 @@ import java.util.Collection; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.spawner.TrialSpawnerConfiguration; -import org.jetbrains.annotations.NotNull; +import org.jspecify.annotations.NullMarked; /** * Represents a captured state of a trial spawner. */ +@NullMarked public interface TrialSpawner extends TileState { + /** + * Gets the game time in ticks when the cooldown ends. 0 if not currently in cooldown. + * + * @return the game time in ticks + * @see org.bukkit.World#getGameTime() + */ + long getCooldownEnd(); + + /** + * Sets the game time in ticks when the cooldown ends. + * + * @param ticks the game time in ticks for the new cooldown + */ + void setCooldownEnd(long ticks); + + /** + * Gets the game time in ticks when the next spawn attempt happens. 0 if not currently active. + * + * @return the game time in ticks + * @see org.bukkit.World#getGameTime() + */ + long getNextSpawnAttempt(); + + /** + * Sets the game time in ticks when the next spawn attempt happens. + * + * @param ticks the game time in ticks for the next mob spawn + */ + void setNextSpawnAttempt(long ticks); + /** * Gets the length in ticks the spawner will stay in cooldown for. * * @return the number of ticks */ - public int getCooldownLength(); + int getCooldownLength(); /** * Sets the length in ticks the spawner will stay in cooldown for. * * @param ticks the number of ticks */ - public void setCooldownLength(int ticks); + void setCooldownLength(int ticks); /** * Get the maximum distance(squared) a player can be in order for this @@ -37,7 +68,7 @@ public interface TrialSpawner extends TileState { * @return the maximum distance(squared) a player can be in order for this * spawner to be active. */ - public int getRequiredPlayerRange(); + int getRequiredPlayerRange(); /** * Set the maximum distance (squared) a player can be in order for this @@ -49,7 +80,7 @@ public interface TrialSpawner extends TileState { * @param requiredPlayerRange the maximum distance (squared) a player can be * in order for this spawner to be active. */ - public void setRequiredPlayerRange(int requiredPlayerRange); + void setRequiredPlayerRange(int requiredPlayerRange); /** * Gets the players this spawner is currently tracking. @@ -61,8 +92,7 @@ public interface TrialSpawner extends TileState { * @return a collection of players this spawner is tracking or an empty * collection if there aren't any */ - @NotNull - public Collection getTrackedPlayers(); + Collection getTrackedPlayers(); /** * Checks if this spawner is currently tracking the provided player. @@ -70,7 +100,7 @@ public interface TrialSpawner extends TileState { * @param player the player * @return true if this spawner is tracking the provided player */ - public boolean isTrackingPlayer(@NotNull Player player); + boolean isTrackingPlayer(final Player player); /** * Force this spawner to start tracking the provided player. @@ -80,7 +110,7 @@ public interface TrialSpawner extends TileState { * * @param player the player */ - public void startTrackingPlayer(@NotNull Player player); + void startTrackingPlayer(final Player player); /** * Force this spawner to stop tracking the provided player. @@ -90,7 +120,7 @@ public interface TrialSpawner extends TileState { * * @param player the player */ - public void stopTrackingPlayer(@NotNull Player player); + void stopTrackingPlayer(final Player player); /** * Gets a list of entities this spawner is currently tracking. @@ -102,8 +132,7 @@ public interface TrialSpawner extends TileState { * @return a collection of entities this spawner is tracking or an empty * collection if there aren't any */ - @NotNull - public Collection getTrackedEntities(); + Collection getTrackedEntities(); /** * Checks if this spawner is currently tracking the provided entity. @@ -111,7 +140,7 @@ public interface TrialSpawner extends TileState { * @param entity the entity * @return true if this spawner is tracking the provided entity */ - public boolean isTrackingEntity(@NotNull Entity entity); + boolean isTrackingEntity(final Entity entity); /** * Force this spawner to start tracking the provided entity. @@ -121,7 +150,7 @@ public interface TrialSpawner extends TileState { * * @param entity the entity */ - public void startTrackingEntity(@NotNull Entity entity); + void startTrackingEntity(final Entity entity); /** * Force this spawner to stop tracking the provided entity. @@ -131,7 +160,7 @@ public interface TrialSpawner extends TileState { * * @param entity the entity */ - public void stopTrackingEntity(@NotNull Entity entity); + void stopTrackingEntity(final Entity entity); /** * Checks if this spawner is using the ominous @@ -139,7 +168,7 @@ public interface TrialSpawner extends TileState { * * @return true is using the ominous configuration */ - public boolean isOminous(); + boolean isOminous(); /** * Changes this spawner between the normal and ominous @@ -148,7 +177,7 @@ public interface TrialSpawner extends TileState { * @param ominous true to use the ominous TrialSpawnerConfiguration, false to * use the normal one. */ - public void setOminous(boolean ominous); + void setOminous(boolean ominous); /** * Gets the {@link TrialSpawnerConfiguration} used when {@link #isOminous()} is @@ -156,8 +185,7 @@ public interface TrialSpawner extends TileState { * * @return the TrialSpawnerConfiguration */ - @NotNull - public TrialSpawnerConfiguration getNormalConfiguration(); + TrialSpawnerConfiguration getNormalConfiguration(); /** * Gets the {@link TrialSpawnerConfiguration} used when {@link #isOminous()} is @@ -165,6 +193,5 @@ public interface TrialSpawner extends TileState { * * @return the TrialSpawnerConfiguration */ - @NotNull - public TrialSpawnerConfiguration getOminousConfiguration(); + TrialSpawnerConfiguration getOminousConfiguration(); } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftTrialSpawner.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftTrialSpawner.java index a8f266438..c3b395a1f 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftTrialSpawner.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftTrialSpawner.java @@ -33,6 +33,26 @@ public class CraftTrialSpawner extends CraftBlockEntityState