Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added PlayerBookEvent, PlayerBookEditEvent & PlayerBookSignEvent. #756

Closed
wants to merge 1 commit into from

Conversation

desht
Copy link
Contributor

@desht desht commented Jan 18, 2013

Adds three new events: PlayerBookEvent (abstract), PlayerBookEditEvent and PlayerBookSign Event. These are fired when a player edits or signs a book & quill item.

Implements: https://bukkit.atlassian.net/browse/BUKKIT-1995
CraftBukkit PR: Bukkit/CraftBukkit#996
Test Plugin: https://github.com/desht/testbookevents

@feildmaster
Copy link
Member

I'm not sure about providing the slot index... actually, now that it's possible to switch the active slot (not yet in the API) maybe this is a good idea.

@desht
Copy link
Contributor Author

desht commented Jan 24, 2013

Yeah, given that plugin A could make a player.setActiveSlot() (or whatever) call in response to a book edit/sign event, plugin B would then not be able to get the book via player.getItemInHand(). So having the slot in the event could be useful there.

Although that reasoning could be applied to events other than just book events (e.g. PlayerInteractEvent)...

@desht
Copy link
Contributor Author

desht commented Jan 24, 2013

PR updated: setBookMeta() is now setNewBookMeta() for consistency with getNewBookMeta(), and the getter and setter both now clone the meta data, as suggested.

@navarr
Copy link

navarr commented Mar 1, 2013

+1

@ghost ghost assigned natemort Mar 19, 2013
* @param bookMeta New book meta data
*/
public void setNewBookMeta(BookMeta newBookMeta) {
this.newBookMeta = newBookMeta.clone();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will throw a NPE if you provide null for the newBookMeta.

@desht
Copy link
Contributor Author

desht commented Mar 21, 2013

@evilmidget38 I've updated the PR to account for all your comments, thanks.

testbookevents plugin is now also up to date wrt bukkit 1.5.1-R0.1-SNAPSHOT

@desht
Copy link
Contributor Author

desht commented Mar 25, 2013

Collapsed the three events into a single PlayerEditBookEvent as suggested by @Wolvereness

*
* @param bookMeta New book meta data
*/
public void setNewBookMeta(BookMeta newBookMeta) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a throws declaration to this, as well as Javadoc

@desht
Copy link
Contributor Author

desht commented Mar 25, 2013

Added throws declaration to setNewBookMeta() method and its Javadoc as requested by @gmcferrin

Events related to book & quill and written book items.
https://bukkit.atlassian.net/browse/BUKKIT-1995

Changes as requested by evilmidget38

oldBookMeta -> previousBookMeta

Collapsed new book edit events into single PlayerEditBookEvent
As per discussion with Wolvereness and evilmidget38

Added throws declarations to setNewBookMeta() and associated Javadoc

More updates as requested by gmcferrin/Wolvereness
@riking
Copy link
Contributor

riking commented Apr 11, 2013

Deleted that comment because you already did it, heh.

* Sets the book meta data that will actually be added to the book
*
* @param bookMeta new book meta data
* @throws IllegalArgumentException if the new book meta data is null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@throws IllegalArgumentException if the new bookmeta is null or of the incorrect type

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking the wording should be "...if the new book meta data is null or not created by the {@link ItemFactory}"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the CraftItemFactory doesn't do any creation, just validation.

if (meta1 != null && !(meta1 instanceof CraftMetaItem)) {
    throw new IllegalArgumentException("First meta of " + meta1.getClass().getName() + " does not belong to " + CraftItemFactory.class.getName());

The purpose of the check is to head off early people creating their own ItemMeta implementations, which would cause a class cast error elsewhere in the code. (I'm not quite sure where, but I trust Wolvereness to get that right.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, understand the purpose. "of the incorrect type" just sounds a little vague. Valid creators of ItemMeta (CraftMetaItem) objects today are CraftItemFactory and CraftItemStack. So what's a good way of expressing that succinctly in a one-line comment?

@natemort
Copy link
Member

Pulled, thanks.

@natemort natemort closed this Jun 10, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants