Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
PlayerEditBookEvent.java
1 package org.bukkit.event.player;
2 
3 import org.apache.commons.lang.Validate;
4 import org.bukkit.Bukkit;
5 import org.bukkit.entity.Player;
9 
10 /**
11  * Called when a player edits or signs a book and quill item. If the event is
12  * cancelled, no changes are made to the BookMeta
13  */
14 public class PlayerEditBookEvent extends PlayerEvent implements Cancellable {
15  private static final HandlerList handlers = new HandlerList();
16 
17  private final BookMeta previousBookMeta;
18  private final int slot;
19  private BookMeta newBookMeta;
20  private boolean isSigning;
21  private boolean cancel;
22 
23  public PlayerEditBookEvent(Player who, int slot, BookMeta previousBookMeta, BookMeta newBookMeta, boolean isSigning) {
24  super(who);
25 
26  Validate.isTrue(slot >= 0 && slot <=8, "Slot must be in range 0-8 inclusive");
27  Validate.notNull(previousBookMeta, "Previous book meta must not be null");
28  Validate.notNull(newBookMeta, "New book meta must not be null");
29 
30  Bukkit.getItemFactory().equals(previousBookMeta, newBookMeta);
31 
32  this.previousBookMeta = previousBookMeta;
33  this.newBookMeta = newBookMeta;
34  this.slot = slot;
35  this.isSigning = isSigning;
36  this.cancel = false;
37  }
38 
39  /**
40  * Gets the book meta currently on the book.
41  * <p>
42  * Note: this is a copy of the book meta. You cannot use this object to
43  * change the existing book meta.
44  *
45  * @return the book meta currently on the book
46  */
48  return previousBookMeta.clone();
49  }
50 
51  /**
52  * Gets the book meta that the player is attempting to add to the book.
53  * <p>
54  * Note: this is a copy of the proposed new book meta. Use {@link
55  * #setNewBookMeta(BookMeta)} to change what will actually be added to the
56  * book.
57  *
58  * @return the book meta that the player is attempting to add
59  */
61  return newBookMeta.clone();
62  }
63 
64  /**
65  * Gets the inventory slot number for the book item that triggered this
66  * event.
67  * <p>
68  * This is a slot number on the player's hotbar in the range 0-8.
69  *
70  * @return the inventory slot number that the book item occupies
71  */
72  public int getSlot() {
73  return slot;
74  }
75 
76  /**
77  * Sets the book meta that will actually be added to the book.
78  *
79  * @param newBookMeta new book meta
80  * @throws IllegalArgumentException if the new book meta is null
81  */
82  public void setNewBookMeta(BookMeta newBookMeta) throws IllegalArgumentException {
83  Validate.notNull(newBookMeta, "New book meta must not be null");
84  Bukkit.getItemFactory().equals(newBookMeta, null);
85  this.newBookMeta = newBookMeta.clone();
86  }
87 
88  /**
89  * Gets whether or not the book is being signed. If a book is signed the
90  * Material changes from BOOK_AND_QUILL to WRITTEN_BOOK.
91  *
92  * @return true if the book is being signed
93  */
94  public boolean isSigning() {
95  return isSigning;
96  }
97 
98  /**
99  * Sets whether or not the book is being signed. If a book is signed the
100  * Material changes from BOOK_AND_QUILL to WRITTEN_BOOK.
101  *
102  * @param signing whether or not the book is being signed.
103  */
104  public void setSigning(boolean signing) {
105  isSigning = signing;
106  }
107 
108  @Override
109  public HandlerList getHandlers() {
110  return handlers;
111  }
112 
113  public static HandlerList getHandlerList() {
114  return handlers;
115  }
116 
117  public boolean isCancelled() {
118  return cancel;
119  }
120 
121  public void setCancelled(boolean cancel) {
122  this.cancel = cancel;
123  }
124 }
static ItemFactory getItemFactory()
Definition: Bukkit.java:682
boolean equals(final ItemMeta meta1, final ItemMeta meta2)