Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Add PlayerBookEditEvent. Adds BUKKIT-1995
Browse files Browse the repository at this point in the history
Event related to book & quill and written book items.
  • Loading branch information
desht authored and natemort committed Jun 10, 2013
1 parent cbd5e3b commit 373af3e
Showing 1 changed file with 125 additions and 0 deletions.
125 changes: 125 additions & 0 deletions src/main/java/org/bukkit/event/player/PlayerEditBookEvent.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 373af3e

Please sign in to comment.