1
0
Fork 0
mirror of https://github.com/PaperMC/Paper.git synced 2024-12-23 06:50:25 +01:00
PaperMC/patches/api/0151-Turtle-API.patch

289 lines
7.5 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: BillyGalbreath <Blake.Galbreath@GMail.com>
Date: Fri, 28 Sep 2018 17:08:09 -0500
Subject: [PATCH] Turtle API
diff --git a/src/main/java/com/destroystokyo/paper/event/entity/TurtleGoHomeEvent.java b/src/main/java/com/destroystokyo/paper/event/entity/TurtleGoHomeEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..91cede0e53cf6f1089e549053ebc2e2b190a1aab
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/entity/TurtleGoHomeEvent.java
@@ -0,0 +1,53 @@
2021-06-11 14:02:28 +02:00
+package com.destroystokyo.paper.event.entity;
+
+import org.bukkit.entity.Turtle;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.entity.EntityEvent;
2024-02-01 10:15:57 +01:00
+import org.jetbrains.annotations.ApiStatus;
+import org.jspecify.annotations.NullMarked;
2021-06-11 14:02:28 +02:00
+
+/**
+ * Fired when a Turtle decides to go home
+ */
+@NullMarked
2021-06-11 14:02:28 +02:00
+public class TurtleGoHomeEvent extends EntityEvent implements Cancellable {
+
2024-02-01 10:15:57 +01:00
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+
+ private boolean cancelled;
+
+ @ApiStatus.Internal
+ public TurtleGoHomeEvent(final Turtle turtle) {
2021-06-11 14:02:28 +02:00
+ super(turtle);
+ }
+
+ /**
+ * The turtle going home
+ *
+ * @return The turtle
+ */
+ @Override
2021-06-11 14:02:28 +02:00
+ public Turtle getEntity() {
2024-02-01 10:15:57 +01:00
+ return (Turtle) super.getEntity();
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public boolean isCancelled() {
2024-02-01 10:15:57 +01:00
+ return this.cancelled;
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public void setCancelled(final boolean cancel) {
2024-02-01 10:15:57 +01:00
+ this.cancelled = cancel;
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
2021-06-11 14:02:28 +02:00
+ public HandlerList getHandlers() {
2024-02-01 10:15:57 +01:00
+ return HANDLER_LIST;
2021-06-11 14:02:28 +02:00
+ }
+
+ public static HandlerList getHandlerList() {
2024-02-01 10:15:57 +01:00
+ return HANDLER_LIST;
2021-06-11 14:02:28 +02:00
+ }
+}
diff --git a/src/main/java/com/destroystokyo/paper/event/entity/TurtleLayEggEvent.java b/src/main/java/com/destroystokyo/paper/event/entity/TurtleLayEggEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..1492d168aa1dc538b732b0ff262074cc7c9900e6
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/entity/TurtleLayEggEvent.java
@@ -0,0 +1,90 @@
2021-06-11 14:02:28 +02:00
+package com.destroystokyo.paper.event.entity;
+
+import org.bukkit.Location;
+import org.bukkit.entity.Turtle;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.entity.EntityEvent;
2024-02-01 10:15:57 +01:00
+import org.jetbrains.annotations.ApiStatus;
+import org.jspecify.annotations.NullMarked;
2021-06-11 14:02:28 +02:00
+
+/**
+ * Fired when a Turtle lays eggs
+ */
+@NullMarked
2021-06-11 14:02:28 +02:00
+public class TurtleLayEggEvent extends EntityEvent implements Cancellable {
2024-02-01 10:15:57 +01:00
+
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+
2021-06-11 14:02:28 +02:00
+ private final Location location;
+ private int eggCount;
+
2024-02-01 10:15:57 +01:00
+ private boolean cancelled;
+
+ @ApiStatus.Internal
+ public TurtleLayEggEvent(final Turtle turtle, final Location location, final int eggCount) {
2021-06-11 14:02:28 +02:00
+ super(turtle);
+ this.location = location;
+ this.eggCount = eggCount;
+ }
+
+ /**
+ * The turtle laying the eggs
+ *
+ * @return The turtle
+ */
+ @Override
2021-06-11 14:02:28 +02:00
+ public Turtle getEntity() {
2024-02-01 10:15:57 +01:00
+ return (Turtle) super.getEntity();
2021-06-11 14:02:28 +02:00
+ }
+
+ /**
+ * Get the location where the eggs are being laid
+ *
+ * @return Location of eggs
+ */
+ public Location getLocation() {
+ return this.location.clone();
2021-06-11 14:02:28 +02:00
+ }
+
+ /**
+ * Get the number of eggs being laid
+ *
+ * @return Number of eggs
+ */
+ public int getEggCount() {
2024-02-01 10:15:57 +01:00
+ return this.eggCount;
2021-06-11 14:02:28 +02:00
+ }
+
+ /**
+ * Set the number of eggs being laid
+ *
+ * @param eggCount Number of eggs
+ */
+ public void setEggCount(final int eggCount) {
2021-06-11 14:02:28 +02:00
+ if (eggCount < 1) {
2024-02-01 10:15:57 +01:00
+ this.cancelled = true;
2021-06-11 14:02:28 +02:00
+ return;
+ }
+ this.eggCount = Math.min(eggCount, 4);
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public boolean isCancelled() {
2024-02-01 10:15:57 +01:00
+ return this.cancelled;
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public void setCancelled(final boolean cancel) {
2024-02-01 10:15:57 +01:00
+ this.cancelled = cancel;
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
2021-06-11 14:02:28 +02:00
+ public HandlerList getHandlers() {
2024-02-01 10:15:57 +01:00
+ return HANDLER_LIST;
2021-06-11 14:02:28 +02:00
+ }
+
+ public static HandlerList getHandlerList() {
2024-02-01 10:15:57 +01:00
+ return HANDLER_LIST;
2021-06-11 14:02:28 +02:00
+ }
+}
diff --git a/src/main/java/com/destroystokyo/paper/event/entity/TurtleStartDiggingEvent.java b/src/main/java/com/destroystokyo/paper/event/entity/TurtleStartDiggingEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..a84101fb1b478f3018f283bc47d3e73a7ae5bbc8
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/entity/TurtleStartDiggingEvent.java
@@ -0,0 +1,65 @@
2021-06-11 14:02:28 +02:00
+package com.destroystokyo.paper.event.entity;
+
+import org.bukkit.Location;
+import org.bukkit.entity.Turtle;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.entity.EntityEvent;
2024-02-01 10:15:57 +01:00
+import org.jetbrains.annotations.ApiStatus;
+import org.jspecify.annotations.NullMarked;
2021-06-11 14:02:28 +02:00
+
+/**
+ * Fired when a Turtle starts digging to lay eggs
+ */
+@NullMarked
2021-06-11 14:02:28 +02:00
+public class TurtleStartDiggingEvent extends EntityEvent implements Cancellable {
2024-02-01 10:15:57 +01:00
+
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+
+ private final Location location;
2024-02-01 10:15:57 +01:00
+ private boolean cancelled;
2021-06-11 14:02:28 +02:00
+
2024-02-01 10:15:57 +01:00
+ @ApiStatus.Internal
+ public TurtleStartDiggingEvent(final Turtle turtle, final Location location) {
2021-06-11 14:02:28 +02:00
+ super(turtle);
+ this.location = location;
+ }
+
+ /**
+ * The turtle digging
+ *
+ * @return The turtle
+ */
+ @Override
2021-06-11 14:02:28 +02:00
+ public Turtle getEntity() {
2024-02-01 10:15:57 +01:00
+ return (Turtle) super.getEntity();
2021-06-11 14:02:28 +02:00
+ }
+
+ /**
+ * Get the location where the turtle is digging
+ *
+ * @return Location where digging
+ */
+ public Location getLocation() {
+ return this.location.clone();
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public boolean isCancelled() {
2024-02-01 10:15:57 +01:00
+ return this.cancelled;
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
+ public void setCancelled(final boolean cancel) {
2024-02-01 10:15:57 +01:00
+ this.cancelled = cancel;
2021-06-11 14:02:28 +02:00
+ }
+
+ @Override
2021-06-11 14:02:28 +02:00
+ public HandlerList getHandlers() {
2024-02-01 10:15:57 +01:00
+ return HANDLER_LIST;
2021-06-11 14:02:28 +02:00
+ }
+
+ public static HandlerList getHandlerList() {
2024-02-01 10:15:57 +01:00
+ return HANDLER_LIST;
2021-06-11 14:02:28 +02:00
+ }
+}
diff --git a/src/main/java/org/bukkit/entity/Turtle.java b/src/main/java/org/bukkit/entity/Turtle.java
index 5584936158e3762d348cb2eaee2082da24ede367..aa83615a0c6565c9874c906a83cfe20c2a964b22 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/entity/Turtle.java
+++ b/src/main/java/org/bukkit/entity/Turtle.java
@@ -1,5 +1,8 @@
2021-06-11 14:02:28 +02:00
package org.bukkit.entity;
+import org.bukkit.Location;
+import org.jetbrains.annotations.NotNull;
+
/**
* Represents a turtle.
*/
@@ -18,4 +21,42 @@ public interface Turtle extends Animals {
* @return Whether the turtle is laying an egg
*/
boolean isLayingEgg();
2021-06-11 14:02:28 +02:00
+
+ // Paper start
2021-06-11 14:02:28 +02:00
+ /**
+ * Get the turtle's home location
+ *
+ * @return Home location
+ */
+ @NotNull
+ Location getHome();
+
+ /**
+ * Set the turtle's home location
+ *
+ * @param location Home location
+ */
+ void setHome(@NotNull Location location);
+
+ /**
+ * Check if turtle is currently pathfinding to it's home
+ *
+ * @return True if going home
+ */
+ boolean isGoingHome();
+
+ /**
+ * Get if turtle is digging to lay eggs
+ *
+ * @return True if digging
+ */
+ boolean isDigging();
+
+ /**
+ * Set if turtle is carrying egg
+ *
+ * @param hasEgg True if carrying egg
+ */
+ void setHasEgg(boolean hasEgg);
+ // Paper end
}