summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDes Herriott <des.herriott@gmail.com>2013-01-18 08:53:23 +0000
committerNate Mortensen <nate.richard.mortensen@gmail.com>2013-06-10 10:55:51 -0600
commit7a233b33b46a43933a79e91d72729ecaacd1a3a0 (patch)
treedf212c2762c467d81f23ff315a962e78882e34e5 /src
parent2fb7b854349d6d13c08239101cd25910685b8672 (diff)
downloadbukkit-7a233b33b46a43933a79e91d72729ecaacd1a3a0.tar
bukkit-7a233b33b46a43933a79e91d72729ecaacd1a3a0.tar.gz
bukkit-7a233b33b46a43933a79e91d72729ecaacd1a3a0.tar.lz
bukkit-7a233b33b46a43933a79e91d72729ecaacd1a3a0.tar.xz
bukkit-7a233b33b46a43933a79e91d72729ecaacd1a3a0.zip
Add PlayerBookEditEvent. Adds BUKKIT-1995
Event related to book & quill and written book items.
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/bukkit/event/player/PlayerEditBookEvent.java125
1 files changed, 125 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/event/player/PlayerEditBookEvent.java b/src/main/java/org/bukkit/event/player/PlayerEditBookEvent.java
new file mode 100644
index 00000000..ed333930
--- /dev/null
+++ b/src/main/java/org/bukkit/event/player/PlayerEditBookEvent.java
@@ -0,0 +1,125 @@
+package org.bukkit.event.player;
+
+import org.apache.commons.lang.Validate;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.bukkit.inventory.meta.BookMeta;
+
+/**
+ * Called when a player edits or signs a book and quill item. If the event
+ * is cancelled, no changes are made to the BookMeta
+ */
+public class PlayerEditBookEvent extends PlayerEvent implements Cancellable {
+ private static final HandlerList handlers = new HandlerList();
+
+ private final BookMeta previousBookMeta;
+ private final int slot;
+ private BookMeta newBookMeta;
+ private boolean isSigning;
+ private boolean cancel;
+
+ public PlayerEditBookEvent(Player who, int slot, BookMeta previousBookMeta, BookMeta newBookMeta, boolean isSigning) {
+ super(who);
+
+ Validate.isTrue(slot >= 0 && slot <=8, "Slot must be in range 0-8 inclusive");
+ Validate.notNull(previousBookMeta, "Previous book meta must not be null");
+ Validate.notNull(newBookMeta, "New book meta must not be null");
+
+ Bukkit.getItemFactory().equals(previousBookMeta, newBookMeta);
+
+ this.previousBookMeta = previousBookMeta;
+ this.newBookMeta = newBookMeta;
+ this.slot = slot;
+ this.isSigning = isSigning;
+ this.cancel = false;
+ }
+
+ /**
+ * Gets the book meta currently on the book.
+ * <p>
+ * Note: this is a copy of the book meta. You cannot use this object to
+ * change the existing book meta.
+ *
+ * @return the book meta currently on the book
+ */
+ public BookMeta getPreviousBookMeta() {
+ return previousBookMeta.clone();
+ }
+
+ /**
+ * Gets the book meta that the player is attempting to add to
+ * the book.
+ * <p>
+ * Note: this is a copy of the proposed new book meta. Use {@link
+ * #setNewBookMeta(BookMeta)} to change what will actually be
+ * added to the book.
+ *
+ * @return the book meta that the player is attempting to add
+ */
+ public BookMeta getNewBookMeta() {
+ return newBookMeta.clone();
+ }
+
+ /**
+ * Gets the inventory slot number for the book item that triggered this
+ * event.
+ * <p>
+ * This is a slot number on the player's hotbar in the range 0-8.
+ *
+ * @return the inventory slot number that the book item occupies
+ */
+ public int getSlot() {
+ return slot;
+ }
+
+ /**
+ * Sets the book meta that will actually be added to the book.
+ *
+ * @param bookMeta new book meta
+ * @throws IllegalArgumentException if the new book meta is null
+ */
+ public void setNewBookMeta(BookMeta newBookMeta) throws IllegalArgumentException {
+ Validate.notNull(newBookMeta, "New book meta must not be null");
+ Bukkit.getItemFactory().equals(newBookMeta, null);
+ this.newBookMeta = newBookMeta.clone();
+ }
+
+ /**
+ * Gets whether or not the book is being signed. If a book is signed the
+ * Material changes from BOOK_AND_QUILL to WRITTEN_BOOK.
+ *
+ * @return true if the book is being signed
+ */
+ public boolean isSigning() {
+ return isSigning;
+ }
+
+ /**
+ * Sets whether or not the book is being signed. If a book is signed the
+ * Material changes from BOOK_AND_QUILL to WRITTEN_BOOK.
+ *
+ * @param signing whether or not the book is being signed.
+ */
+ public void setSigning(boolean signing) {
+ isSigning = signing;
+ }
+
+ @Override
+ public HandlerList getHandlers() {
+ return handlers;
+ }
+
+ public static HandlerList getHandlerList() {
+ return handlers;
+ }
+
+ public boolean isCancelled() {
+ return cancel;
+ }
+
+ public void setCancelled(boolean cancel) {
+ this.cancel = cancel;
+ }
+}