aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/api/0223-Add-TargetHitEvent-API.patch
blob: 6c6822436378cf8ab0c7fcaa6d5a8f8b5e4a9d60 (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
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jason Penilla <11360596+jpenilla@users.noreply.github.com>
Date: Wed, 25 Nov 2020 23:21:32 -0800
Subject: [PATCH] Add TargetHitEvent API


diff --git a/src/main/java/io/papermc/paper/event/block/TargetHitEvent.java b/src/main/java/io/papermc/paper/event/block/TargetHitEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..5247e7f78e0076089c1e1bdea2afbb455c43732a
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/block/TargetHitEvent.java
@@ -0,0 +1,61 @@
+package io.papermc.paper.event.block;
+
+import com.google.common.base.Preconditions;
+import org.bukkit.block.Block;
+import org.bukkit.block.BlockFace;
+import org.bukkit.entity.Projectile;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.entity.ProjectileHitEvent;
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Range;
+
+/**
+ * Called when a Target Block is hit by a projectile.
+ * <p>
+ * Cancelling this event will stop the Target from emitting a redstone signal,
+ * and in the case that the shooter is a player, will stop them from receiving
+ * advancement criteria.
+ */
+public class TargetHitEvent extends ProjectileHitEvent {
+
+    private static final HandlerList HANDLER_LIST = new HandlerList();
+
+    private int signalStrength;
+
+    @ApiStatus.Internal
+    public TargetHitEvent(@NotNull Projectile projectile, @NotNull Block block, @NotNull BlockFace blockFace, int signalStrength) {
+        super(projectile, null, block, blockFace);
+        this.signalStrength = signalStrength;
+    }
+
+    /**
+     * Gets the strength of the redstone signal to be emitted by the Target block
+     *
+     * @return the strength of the redstone signal to be emitted
+     */
+    public @Range(from = 0, to = 15) int getSignalStrength() {
+        return this.signalStrength;
+    }
+
+    /**
+     * Sets the strength of the redstone signal to be emitted by the Target block
+     *
+     * @param signalStrength the strength of the redstone signal to be emitted
+     */
+    public void setSignalStrength(@Range(from = 0, to = 15) int signalStrength) {
+        Preconditions.checkArgument(signalStrength >= 0 && signalStrength <= 15, "Signal strength out of range (%s), must be in range [0,15]", signalStrength);
+        this.signalStrength = signalStrength;
+    }
+
+    @NotNull
+    @Override
+    public HandlerList getHandlers() {
+        return HANDLER_LIST;
+    }
+
+    @NotNull
+    public static HandlerList getHandlerList() {
+        return HANDLER_LIST;
+    }
+}