Yatopia/patches/api/0008-Add-StructureLocateEvent.patch

150 lines
4.9 KiB
Diff
Raw Normal View History

2020-09-27 21:36:48 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: dfsek <dfsek@protonmail.com>
Date: Tue, 15 Sep 2020 21:59:16 -0700
Subject: [PATCH] Add StructureLocateEvent
diff --git a/src/main/java/org/bukkit/event/world/StructureLocateEvent.java b/src/main/java/org/bukkit/event/world/StructureLocateEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..1011b03fcc7be912e617a6fde3f62e68d70f2c1c
--- /dev/null
+++ b/src/main/java/org/bukkit/event/world/StructureLocateEvent.java
@@ -0,0 +1,137 @@
+package org.bukkit.event.world;
+
+import org.bukkit.Location;
+import org.bukkit.StructureType;
+import org.bukkit.World;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Called <b>before</b> a structure/feature is located.
+ * This happens when:<br>
+ * - The /locate command is used.<br>
+ * - An Eye of Ender is used.<br>
+ * - An Explorer/Treasure Map is activated.<br>
+ * - {@link World#locateNearestStructure(Location, StructureType, int, boolean)} is invoked.
+ */
+public class StructureLocateEvent extends WorldEvent implements Cancellable {
+ private static final HandlerList handlers = new HandlerList();
+ private final Location origin;
+ private Location result = null;
+ private StructureType type;
+ private int radius;
+ private boolean findUnexplored;
+ private boolean cancelled = false;
+ public StructureLocateEvent(@NotNull World world, @NotNull Location origin, @NotNull StructureType structureType, int radius, boolean findUnexplored) {
+ super(world);
+ this.origin = origin;
+ this.type = structureType;
+ this.radius = radius;
+ this.findUnexplored = findUnexplored;
+ }
+
+ @NotNull
+ @Override
+ public HandlerList getHandlers() {
+ return handlers;
+ }
+
+ @NotNull
+ public static HandlerList getHandlerList() {
+ return handlers;
+ }
+
+ /**
+ * Gets the location set as the structure location, if it was defined.<br>
+ * Returns null if it has not been set by {@link StructureLocateEvent#setResult(Location)}.<br>
+ * Since this event fires <i>before</i> the search is done, the actual location is unknown at this point.<br>
+ * If you wish to manipulate the location, use {@link World#locateNearestStructure(Location, StructureType, int, boolean)}
+ * @return The result location, if it has been set. null if it has not.
+ */
+ @Nullable
+ public Location getResult() {
+ return result;
+ }
+
+ /**
+ * Sets the result Location. This causes the search to be skipped, and the location passed here to be used as the result.
+ * @param result the Location of the structure.
+ */
+ public void setResult(@Nullable Location result) {
+ this.result = result;
+ }
+
+ /**
+ * Gets the {@link StructureType} that is to be located.
+ * @return the structure type.
+ */
+ @NotNull
+ public StructureType getType() {
+ return type;
+ }
+
+ /**
+ * Sets the {@link StructureType} that is to be located.
+ * @param type the structure type.
+ */
+ public void setType(@NotNull StructureType type) {
+ this.type = type;
+ }
+
+ /**
+ * Gets the location from which the search is to be conducted.
+ * @return Location where search begins
+ */
+ @NotNull
+ public Location getOrigin() {
+ return origin;
+ }
+
+ /**
+ * Gets the search radius in which to attempt locating the structure.<br>
+ * This radius may not always be obeyed during the structure search!
+ * @return the search radius.
+ */
+ public int getRadius() {
+ return radius;
+ }
+
+ /**
+ * Sets the search radius in which to attempt locating the structure.<br>
+ * This radius may not always be obeyed during the structure search!
+ * @param radius the search radius.
+ */
+ public void setRadius(int radius) {
+ this.radius = radius;
+ }
+
+ /**
+ * Gets whether to search exclusively for unexplored structures.<br>
+ * As with the search radius, this value is not always obeyed.
+ * @return Whether to search for only unexplored structures.
+ */
+ public boolean shouldFindUnexplored() {
+ return findUnexplored;
+ }
+
+ /**
+ * Sets whether to search exclusively for unexplored structures.<br>
+ * As with the search radius, this value is not always obeyed.
+ * @param findUnexplored Whether to search for only unexplored structures.
+ */
+ public void setFindUnexplored(boolean findUnexplored) {
+ this.findUnexplored = findUnexplored;
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return cancelled;
+ }
+
+ @Override
+ public void setCancelled(boolean cancel) {
+ this.cancelled = cancel;
+ }
+}