mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-29 19:52:55 +01:00
f9c7f2a5c1
* Begin switching to JSpecify annotations * more * fixes
282 lines
7.4 KiB
Diff
282 lines
7.4 KiB
Diff
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..560b46b7b4fdd3394bc5e8fc917776a5838eba09
|
|
--- /dev/null
|
|
+++ b/src/main/java/com/destroystokyo/paper/event/entity/TurtleGoHomeEvent.java
|
|
@@ -0,0 +1,51 @@
|
|
+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;
|
|
+import org.jetbrains.annotations.ApiStatus;
|
|
+import org.jspecify.annotations.NullMarked;
|
|
+
|
|
+/**
|
|
+ * Fired when a Turtle decides to go home
|
|
+ */
|
|
+@NullMarked
|
|
+public class TurtleGoHomeEvent extends EntityEvent implements Cancellable {
|
|
+
|
|
+ private static final HandlerList HANDLER_LIST = new HandlerList();
|
|
+
|
|
+ private boolean cancelled;
|
|
+
|
|
+ @ApiStatus.Internal
|
|
+ public TurtleGoHomeEvent(final Turtle turtle) {
|
|
+ super(turtle);
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * The turtle going home
|
|
+ *
|
|
+ * @return The turtle
|
|
+ */
|
|
+ public Turtle getEntity() {
|
|
+ return (Turtle) super.getEntity();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean isCancelled() {
|
|
+ return this.cancelled;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void setCancelled(final boolean cancel) {
|
|
+ this.cancelled = cancel;
|
|
+ }
|
|
+
|
|
+ public HandlerList getHandlers() {
|
|
+ return HANDLER_LIST;
|
|
+ }
|
|
+
|
|
+ public static HandlerList getHandlerList() {
|
|
+ return HANDLER_LIST;
|
|
+ }
|
|
+}
|
|
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..d1b2bbb57280726690e704c5978d312d856243eb
|
|
--- /dev/null
|
|
+++ b/src/main/java/com/destroystokyo/paper/event/entity/TurtleLayEggEvent.java
|
|
@@ -0,0 +1,88 @@
|
|
+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;
|
|
+import org.jetbrains.annotations.ApiStatus;
|
|
+import org.jspecify.annotations.NullMarked;
|
|
+
|
|
+/**
|
|
+ * Fired when a Turtle lays eggs
|
|
+ */
|
|
+@NullMarked
|
|
+public class TurtleLayEggEvent extends EntityEvent implements Cancellable {
|
|
+
|
|
+ private static final HandlerList HANDLER_LIST = new HandlerList();
|
|
+
|
|
+ private final Location location;
|
|
+ private int eggCount;
|
|
+
|
|
+ private boolean cancelled;
|
|
+
|
|
+ @ApiStatus.Internal
|
|
+ public TurtleLayEggEvent(final Turtle turtle, final Location location, final int eggCount) {
|
|
+ super(turtle);
|
|
+ this.location = location;
|
|
+ this.eggCount = eggCount;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * The turtle laying the eggs
|
|
+ *
|
|
+ * @return The turtle
|
|
+ */
|
|
+ public Turtle getEntity() {
|
|
+ return (Turtle) super.getEntity();
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Get the location where the eggs are being laid
|
|
+ *
|
|
+ * @return Location of eggs
|
|
+ */
|
|
+ public Location getLocation() {
|
|
+ return this.location.clone();
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Get the number of eggs being laid
|
|
+ *
|
|
+ * @return Number of eggs
|
|
+ */
|
|
+ public int getEggCount() {
|
|
+ return this.eggCount;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Set the number of eggs being laid
|
|
+ *
|
|
+ * @param eggCount Number of eggs
|
|
+ */
|
|
+ public void setEggCount(final int eggCount) {
|
|
+ if (eggCount < 1) {
|
|
+ this.cancelled = true;
|
|
+ return;
|
|
+ }
|
|
+ this.eggCount = Math.min(eggCount, 4);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean isCancelled() {
|
|
+ return this.cancelled;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void setCancelled(final boolean cancel) {
|
|
+ this.cancelled = cancel;
|
|
+ }
|
|
+
|
|
+ public HandlerList getHandlers() {
|
|
+ return HANDLER_LIST;
|
|
+ }
|
|
+
|
|
+ public static HandlerList getHandlerList() {
|
|
+ return HANDLER_LIST;
|
|
+ }
|
|
+}
|
|
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..4a53af5da307cd71e0e647917bec9be44136e6aa
|
|
--- /dev/null
|
|
+++ b/src/main/java/com/destroystokyo/paper/event/entity/TurtleStartDiggingEvent.java
|
|
@@ -0,0 +1,63 @@
|
|
+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;
|
|
+import org.jetbrains.annotations.ApiStatus;
|
|
+import org.jspecify.annotations.NullMarked;
|
|
+
|
|
+/**
|
|
+ * Fired when a Turtle starts digging to lay eggs
|
|
+ */
|
|
+@NullMarked
|
|
+public class TurtleStartDiggingEvent extends EntityEvent implements Cancellable {
|
|
+
|
|
+ private static final HandlerList HANDLER_LIST = new HandlerList();
|
|
+
|
|
+ private final Location location;
|
|
+ private boolean cancelled;
|
|
+
|
|
+ @ApiStatus.Internal
|
|
+ public TurtleStartDiggingEvent(final Turtle turtle, final Location location) {
|
|
+ super(turtle);
|
|
+ this.location = location;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * The turtle digging
|
|
+ *
|
|
+ * @return The turtle
|
|
+ */
|
|
+ public Turtle getEntity() {
|
|
+ return (Turtle) super.getEntity();
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Get the location where the turtle is digging
|
|
+ *
|
|
+ * @return Location where digging
|
|
+ */
|
|
+ public Location getLocation() {
|
|
+ return this.location.clone();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean isCancelled() {
|
|
+ return this.cancelled;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void setCancelled(final boolean cancel) {
|
|
+ this.cancelled = cancel;
|
|
+ }
|
|
+
|
|
+ public HandlerList getHandlers() {
|
|
+ return HANDLER_LIST;
|
|
+ }
|
|
+
|
|
+ public static HandlerList getHandlerList() {
|
|
+ return HANDLER_LIST;
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/org/bukkit/entity/Turtle.java b/src/main/java/org/bukkit/entity/Turtle.java
|
|
index 5584936158e3762d348cb2eaee2082da24ede367..aa83615a0c6565c9874c906a83cfe20c2a964b22 100644
|
|
--- a/src/main/java/org/bukkit/entity/Turtle.java
|
|
+++ b/src/main/java/org/bukkit/entity/Turtle.java
|
|
@@ -1,5 +1,8 @@
|
|
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();
|
|
+
|
|
+ // Paper start
|
|
+ /**
|
|
+ * 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
|
|
}
|