1
0
Fork 0
mirror of https://github.com/PaperMC/Paper.git synced 2025-03-30 11:19:17 +02:00

Add methods for Creaking ()

This commit is contained in:
Pedro 2025-02-25 18:23:47 -03:00 committed by GitHub
parent 9b9f046f41
commit fc56c728c0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 66 additions and 1 deletions
paper-api/src/main/java/org/bukkit/entity
paper-server/src/main/java/org/bukkit/craftbukkit/entity

View file

@ -1,8 +1,43 @@
package org.bukkit.entity;
import org.bukkit.Location;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
/**
* Represents a Creaking.
*/
@NullMarked
public interface Creaking extends Monster {
/**
* Gets the home location for this creaking (where its {@link org.bukkit.block.CreakingHeart} could be found).
*
* @return the location of the home if available, null otherwise
*/
@Nullable
Location getHome();
/**
* Activates this creaking to target and follow a player.
*
* @param player the target
*/
void activate(final Player player);
/**
* Deactivates the creaking, clearing its current attack target and
* marking it as inactive.
*/
void deactivate();
/**
* Returns if this creaking is currently active and hunting.
*
* @see #activate(Player)
*
* @return true if active
*/
boolean isActive();
}

View file

@ -1,11 +1,19 @@
package org.bukkit.craftbukkit.entity;
import com.google.common.base.Preconditions;
import net.minecraft.Optionull;
import net.minecraft.world.entity.monster.creaking.Creaking;
import org.bukkit.Location;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.util.CraftLocation;
import org.bukkit.entity.Player;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
@NullMarked
public class CraftCreaking extends CraftMonster implements org.bukkit.entity.Creaking {
public CraftCreaking(CraftServer server, Creaking entity) {
public CraftCreaking(final CraftServer server, final Creaking entity) {
super(server, entity);
}
@ -14,6 +22,28 @@ public class CraftCreaking extends CraftMonster implements org.bukkit.entity.Cre
return (Creaking) this.entity;
}
@Nullable
@Override
public Location getHome() {
return Optionull.map(this.getHandle().getHomePos(), pos -> CraftLocation.toBukkit(pos, this.getHandle().level()));
}
@Override
public void activate(final Player player) {
Preconditions.checkArgument(player != null, "player cannot be null");
this.getHandle().activate(((CraftPlayer) player).getHandle());
}
@Override
public void deactivate() {
this.getHandle().deactivate();
}
@Override
public boolean isActive() {
return this.getHandle().isActive();
}
@Override
public String toString() {
return "CraftCreaking";