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

Add TrialSpawner methods for end of cooldown and next mob spawn time #12025

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions build-data/paper.at
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,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.state.BlockBehaviour getMenuProvider(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/MenuProvider;
public net.minecraft.world.level.block.state.BlockBehaviour hasCollision
Expand Down
69 changes: 48 additions & 21 deletions paper-api/src/main/java/org/bukkit/block/TrialSpawner.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,57 @@
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
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -61,16 +92,15 @@ 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<Player> getTrackedPlayers();
Collection<Player> getTrackedPlayers();

/**
* Checks if this spawner is currently tracking the provided player.
*
* @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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -102,16 +132,15 @@ 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<Entity> getTrackedEntities();
Collection<Entity> getTrackedEntities();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why there is a space here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

skill issue.


/**
* Checks if this spawner is currently tracking the provided entity.
*
* @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.
Expand All @@ -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.
Expand All @@ -131,15 +160,15 @@ 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
* {@link TrialSpawnerConfiguration}.
*
* @return true is using the ominous configuration
*/
public boolean isOminous();
boolean isOminous();

/**
* Changes this spawner between the normal and ominous
Expand All @@ -148,23 +177,21 @@ 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
* false.
*
* @return the TrialSpawnerConfiguration
*/
@NotNull
public TrialSpawnerConfiguration getNormalConfiguration();
TrialSpawnerConfiguration getNormalConfiguration();

/**
* Gets the {@link TrialSpawnerConfiguration} used when {@link #isOminous()} is
* true.
*
* @return the TrialSpawnerConfiguration
*/
@NotNull
public TrialSpawnerConfiguration getOminousConfiguration();
TrialSpawnerConfiguration getOminousConfiguration();
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@ protected CraftTrialSpawner(CraftTrialSpawner state, Location location) {
this.ominousConfig = state.ominousConfig;
}

@Override
public long getCooldownEnd() {
return this.getSnapshot().trialSpawner.getData().cooldownEndsAt;
}

@Override
public void setCooldownEnd(long ticks) {
this.getSnapshot().trialSpawner.getData().cooldownEndsAt = ticks;
}

@Override
public long getNextSpawnAttempt() {
return this.getSnapshot().trialSpawner.getData().nextMobSpawnsAt;
}

@Override
public void setNextSpawnAttempt(long ticks) {
this.getSnapshot().trialSpawner.getData().nextMobSpawnsAt = ticks;
}

@Override
public int getCooldownLength() {
return this.getSnapshot().trialSpawner.getTargetCooldownLength();
Expand Down
29 changes: 29 additions & 0 deletions test-plugin/src/main/java/io/papermc/testplugin/TestPlugin.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,43 @@
package io.papermc.testplugin;

import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.entity.Armadillo;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import java.util.List;

public final class TestPlugin extends JavaPlugin implements Listener {

BlockData testBlockData;

@Override
public void onEnable() {
this.getServer().getPluginManager().registerEvents(this, this);

// io.papermc.testplugin.brigtests.Registration.registerViaOnEnable(this);
testBlockData = Material.PISTON.createBlockData();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to revert that


this.getServer().getCommandMap().register("fallback", new BukkitCommand("test", "cool test command", "<>", List.of()) {
@Override
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
sender.sendMessage("hi");
sender.sendMessage(testBlockData.toString());
return true;
}
});
this.getServer().getCommandMap().register("fallback", new BukkitCommand("test2", "cool test command", "<>", List.of()) {
@Override
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
sender.sendMessage("hi");
sender.sendMessage(Material.PISTON.createBlockData().toString());
return true;
}
});
}


}