From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: William Blake Galbreath Date: Fri, 18 Oct 2019 22:50:05 -0500 Subject: [PATCH] Llama API diff --git a/src/main/java/net/pl3x/purpur/event/entity/LlamaJoinCaravanEvent.java b/src/main/java/net/pl3x/purpur/event/entity/LlamaJoinCaravanEvent.java new file mode 100644 index 0000000000000000000000000000000000000000..6e68c1399bf30eeef6ce0385867f0cf258698eae --- /dev/null +++ b/src/main/java/net/pl3x/purpur/event/entity/LlamaJoinCaravanEvent.java @@ -0,0 +1,61 @@ +package net.pl3x.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.NotNull; + +/** + * Called when a Llama tries to join a caravan. + *

+ * Cancelling the event will not let the Llama join. To prevent future attempts + * at joining a caravan use {@link Llama#setShouldJoinCaravan(boolean)}. + */ +public class LlamaJoinCaravanEvent extends EntityEvent implements Cancellable { + private static final HandlerList handlers = new HandlerList(); + private boolean canceled; + private final Llama head; + + public LlamaJoinCaravanEvent(@NotNull Llama llama, @NotNull Llama head) { + super(llama); + this.head = head; + } + + @Override + @NotNull + public Llama getEntity() { + return (Llama) entity; + } + + /** + * Get the Llama that this Llama is about to follow + * + * @return Llama about to be followed + */ + @NotNull + public Llama getHead() { + return head; + } + + @Override + public boolean isCancelled() { + return canceled; + } + + @Override + public void setCancelled(boolean cancel) { + canceled = cancel; + } + + @Override + @NotNull + public HandlerList getHandlers() { + return handlers; + } + + @NotNull + public static HandlerList getHandlerList() { + return handlers; + } +} diff --git a/src/main/java/net/pl3x/purpur/event/entity/LlamaLeaveCaravanEvent.java b/src/main/java/net/pl3x/purpur/event/entity/LlamaLeaveCaravanEvent.java new file mode 100644 index 0000000000000000000000000000000000000000..ec8d978c22835e2789ebaaeddf0d13588ed1122a --- /dev/null +++ b/src/main/java/net/pl3x/purpur/event/entity/LlamaLeaveCaravanEvent.java @@ -0,0 +1,34 @@ +package net.pl3x.purpur.event.entity; + +import org.bukkit.entity.Llama; +import org.bukkit.event.HandlerList; +import org.bukkit.event.entity.EntityEvent; +import org.jetbrains.annotations.NotNull; + +/** + * Called when a Llama leaves a caravan + */ +public class LlamaLeaveCaravanEvent extends EntityEvent { + private static final HandlerList handlers = new HandlerList(); + + public LlamaLeaveCaravanEvent(@NotNull Llama llama) { + super(llama); + } + + @Override + @NotNull + public Llama getEntity() { + return (Llama) entity; + } + + @Override + @NotNull + public HandlerList getHandlers() { + return handlers; + } + + @NotNull + public static HandlerList getHandlerList() { + return handlers; + } +} diff --git a/src/main/java/org/bukkit/entity/Llama.java b/src/main/java/org/bukkit/entity/Llama.java index d23226ccb0f6c25028f000ce31346cd0a8898e6a..1ef9479c962b3f4f6fed46671a1209c34040d16d 100644 --- a/src/main/java/org/bukkit/entity/Llama.java +++ b/src/main/java/org/bukkit/entity/Llama.java @@ -3,6 +3,7 @@ package org.bukkit.entity; import com.destroystokyo.paper.entity.RangedEntity; import org.bukkit.inventory.LlamaInventory; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; // Purpur /** * Represents a Llama. @@ -67,4 +68,65 @@ public interface Llama extends ChestedHorse, RangedEntity { // Paper @NotNull @Override LlamaInventory getInventory(); + + // 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); + + /** + * Check if Llama is in a caravan + * + * @return True if in caravan + */ + boolean inCaravan(); + + /** + * Join a caravan + * + * @param llama Head of caravan to join + */ + void joinCaravan(@NotNull Llama llama); + + /** + * Leave current caravan if in one + */ + void leaveCaravan(); + + /** + * Check if another Llama is following this Llama + * + * @return True if being followed in the caravan + */ + boolean hasCaravanTail(); + + /** + * Get the Llama that this Llama is following + *

+ * Does not necessarily mean the leader of the entire caravan + * + * @return The Llama being followed + */ + @Nullable + Llama getCaravanHead(); + + /** + * Get the Llama following this Llama, if any + * + * @return The Llama following this one + */ + @Nullable + Llama getCaravanTail(); + // Purpur end }