mirror of
https://github.com/SparklyPower/SparklyPaper.git
synced 2025-12-19 15:09:27 +00:00
143 lines
4.3 KiB
Diff
143 lines
4.3 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Kieran Wallbanks <kieran.wallbanks@gmail.com>
|
|
Date: Thu, 11 Feb 2021 13:16:44 +0000
|
|
Subject: [PATCH] More note block events
|
|
|
|
|
|
diff --git a/src/main/java/ml/beancraft/haricot/event/block/NoteBlockPlaceEvent.java b/src/main/java/ml/beancraft/haricot/event/block/NoteBlockPlaceEvent.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..2a22bb7c80884bde59cafaff2b50f99d44504998
|
|
--- /dev/null
|
|
+++ b/src/main/java/ml/beancraft/haricot/event/block/NoteBlockPlaceEvent.java
|
|
@@ -0,0 +1,44 @@
|
|
+package ml.beancraft.haricot.event.block;
|
|
+
|
|
+import org.bukkit.block.Block;
|
|
+import org.bukkit.block.data.type.NoteBlock;
|
|
+import org.bukkit.event.HandlerList;
|
|
+import org.bukkit.event.block.BlockEvent;
|
|
+import org.bukkit.inventory.ItemStack;
|
|
+import org.jetbrains.annotations.NotNull;
|
|
+
|
|
+public class NoteBlockPlaceEvent extends BlockEvent {
|
|
+ private static final HandlerList handlers = new HandlerList();
|
|
+
|
|
+ private final ItemStack itemInHand;
|
|
+ private NoteBlock data;
|
|
+
|
|
+ public NoteBlockPlaceEvent(@NotNull Block block, @NotNull NoteBlock data, @NotNull ItemStack itemInHand) {
|
|
+ super(block);
|
|
+ this.data = data;
|
|
+ this.itemInHand = itemInHand;
|
|
+ }
|
|
+
|
|
+ public @NotNull ItemStack getItemInHand() {
|
|
+ return itemInHand;
|
|
+ }
|
|
+
|
|
+ public @NotNull NoteBlock getData() {
|
|
+ return data;
|
|
+ }
|
|
+
|
|
+ public void setData(@NotNull NoteBlock data) {
|
|
+ this.data = data;
|
|
+ }
|
|
+
|
|
+ @NotNull
|
|
+ @Override
|
|
+ public HandlerList getHandlers() {
|
|
+ return handlers;
|
|
+ }
|
|
+
|
|
+ @NotNull
|
|
+ public static HandlerList getHandlerList() {
|
|
+ return handlers;
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/ml/beancraft/haricot/event/block/NoteBlockUpdateEvent.java b/src/main/java/ml/beancraft/haricot/event/block/NoteBlockUpdateEvent.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..c1d8b37cb43d09244014963eb73f64e816d2b1cb
|
|
--- /dev/null
|
|
+++ b/src/main/java/ml/beancraft/haricot/event/block/NoteBlockUpdateEvent.java
|
|
@@ -0,0 +1,80 @@
|
|
+package ml.beancraft.haricot.event.block;
|
|
+
|
|
+import org.apache.commons.lang.Validate;
|
|
+import org.bukkit.block.Block;
|
|
+import org.bukkit.block.data.type.NoteBlock;
|
|
+import org.bukkit.event.Cancellable;
|
|
+import org.bukkit.event.HandlerList;
|
|
+import org.bukkit.event.block.BlockEvent;
|
|
+import org.jetbrains.annotations.NotNull;
|
|
+
|
|
+/**
|
|
+ * Called when the data of a note block changes. Note that this may not be called for
|
|
+ * every note block update and might be called multiple times for one cause.
|
|
+ */
|
|
+public class NoteBlockUpdateEvent extends BlockEvent implements Cancellable {
|
|
+ private static final HandlerList handlers = new HandlerList();
|
|
+
|
|
+ private final NoteBlock oldData;
|
|
+ private NoteBlock newData;
|
|
+ private boolean cancelled;
|
|
+
|
|
+ /**
|
|
+ * Constructs a new note block update event.
|
|
+ * @param theBlock the block that is being updated
|
|
+ * @param oldData the data the block had before the update
|
|
+ * @param newData the data this block is going to have after the update
|
|
+ */
|
|
+ public NoteBlockUpdateEvent(@NotNull Block theBlock, @NotNull NoteBlock oldData, @NotNull NoteBlock newData) {
|
|
+ super(theBlock);
|
|
+ this.oldData = oldData;
|
|
+ this.newData = newData;
|
|
+ this.cancelled = false;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Gets the data of the note block before the update.
|
|
+ * @return the data
|
|
+ */
|
|
+ public @NotNull NoteBlock getOldData() {
|
|
+ return this.oldData;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Gets the data that the note block will have after this event.
|
|
+ * @return the data
|
|
+ */
|
|
+ public @NotNull NoteBlock getNewData() {
|
|
+ return this.newData;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Sets the data that the note block will have after this event.
|
|
+ * @param data the data
|
|
+ */
|
|
+ public void setNewData(@NotNull NoteBlock data) {
|
|
+ Validate.notNull(data, "Data cannot be null");
|
|
+ this.newData = data;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean isCancelled() {
|
|
+ return cancelled;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void setCancelled(boolean cancel) {
|
|
+ this.cancelled = cancel;
|
|
+ }
|
|
+
|
|
+ @NotNull
|
|
+ @Override
|
|
+ public HandlerList getHandlers() {
|
|
+ return handlers;
|
|
+ }
|
|
+
|
|
+ @NotNull
|
|
+ public static HandlerList getHandlerList() {
|
|
+ return handlers;
|
|
+ }
|
|
+}
|