aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/api/0083-PlayerNaturallySpawnCreaturesEvent.patch
blob: 817c6f25e13e44793ee4bf83999a10ddd95b4313 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sun, 14 Jan 2018 17:31:37 -0500
Subject: [PATCH] PlayerNaturallySpawnCreaturesEvent

This event can be used for when you want to exclude a certain player
from triggering monster spawns on a server.

Also a highly more effecient way to blanket block spawns in a world

diff --git a/src/main/java/com/destroystokyo/paper/event/entity/PlayerNaturallySpawnCreaturesEvent.java b/src/main/java/com/destroystokyo/paper/event/entity/PlayerNaturallySpawnCreaturesEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..7fcee73d61347165cefef7b92f0e63e0bed8ad73
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/entity/PlayerNaturallySpawnCreaturesEvent.java
@@ -0,0 +1,66 @@
+package com.destroystokyo.paper.event.entity;
+
+import org.bukkit.entity.Player;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.player.PlayerEvent;
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Fired when the server is calculating what chunks to try to spawn monsters in every Monster Spawn Tick event
+ */
+public class PlayerNaturallySpawnCreaturesEvent extends PlayerEvent implements Cancellable {
+
+    private static final HandlerList HANDLER_LIST = new HandlerList();
+
+    private byte radius;
+    private boolean cancelled;
+
+    @ApiStatus.Internal
+    public PlayerNaturallySpawnCreaturesEvent(@NotNull Player player, byte radius) {
+        super(player);
+        this.radius = radius;
+    }
+
+    /**
+     * @return The radius of chunks around this player to be included in natural spawn selection
+     */
+    public byte getSpawnRadius() {
+        return this.radius;
+    }
+
+    /**
+     * @param radius The radius of chunks around this player to be included in natural spawn selection
+     */
+    public void setSpawnRadius(byte radius) {
+        this.radius = radius;
+    }
+
+    /**
+     * @return If this players chunks will be excluded from natural spawns
+     */
+    @Override
+    public boolean isCancelled() {
+        return this.cancelled;
+    }
+
+    /**
+     * @param cancel {@code true} if you wish to cancel this event, and not include this players chunks for natural spawning
+     */
+    @Override
+    public void setCancelled(boolean cancel) {
+        this.cancelled = cancel;
+    }
+
+    @NotNull
+    @Override
+    public HandlerList getHandlers() {
+        return HANDLER_LIST;
+    }
+
+    @NotNull
+    public static HandlerList getHandlerList() {
+        return HANDLER_LIST;
+    }
+}