Llama API

This commit is contained in:
William Blake Galbreath
2025-01-04 19:21:35 -08:00
committed by granny
parent 3f0b653764
commit c5902528c1
10 changed files with 203 additions and 235 deletions

View File

@@ -0,0 +1,23 @@
--- a/src/main/java/org/bukkit/entity/Llama.java
+++ b/src/main/java/org/bukkit/entity/Llama.java
@@ -119,4 +_,20 @@
@org.jetbrains.annotations.Nullable
Llama getCaravanTail();
// Paper end
+
+ // Purpur start
+ /**
+ * Check if this Llama should attempt to join a caravan
+ *
+ * @return True if Llama is allowed to join a caravan
+ */
+ boolean shouldJoinCaravan();
+
+ /**
+ * Set if this Llama should attempt to join a caravan
+ *
+ * @param shouldJoinCaravan True to allow joining a caravan
+ */
+ void setShouldJoinCaravan(boolean shouldJoinCaravan);
+ // Purpur end
}

View File

@@ -0,0 +1,60 @@
package org.purpurmc.purpur.event.entity;
import org.bukkit.entity.Llama;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.entity.EntityEvent;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;
/**
* Called when a Llama tries to join a caravan.
* <p>
* Cancelling the event will not let the Llama join. To prevent future attempts
* at joining a caravan use {@link Llama#setShouldJoinCaravan(boolean)}.
*/
@NullMarked
public class LlamaJoinCaravanEvent extends EntityEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean canceled;
private final Llama head;
@ApiStatus.Internal
public LlamaJoinCaravanEvent(Llama llama, Llama head) {
super(llama);
this.head = head;
}
@Override
public Llama getEntity() {
return (Llama) entity;
}
/**
* Get the Llama that this Llama is about to follow
*
* @return Llama about to be followed
*/
public Llama getHead() {
return head;
}
@Override
public boolean isCancelled() {
return canceled;
}
@Override
public void setCancelled(boolean cancel) {
canceled = cancel;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@@ -0,0 +1,34 @@
package org.purpurmc.purpur.event.entity;
import org.bukkit.entity.Llama;
import org.bukkit.event.HandlerList;
import org.bukkit.event.entity.EntityEvent;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;
/**
* Called when a Llama leaves a caravan
*/
@NullMarked
public class LlamaLeaveCaravanEvent extends EntityEvent {
private static final HandlerList handlers = new HandlerList();
@ApiStatus.Internal
public LlamaLeaveCaravanEvent(Llama llama) {
super(llama);
}
@Override
public Llama getEntity() {
return (Llama) entity;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}