From 9856d8a18395617ffa0ecc05dcbf9255e6a66d12 Mon Sep 17 00:00:00 2001 From: Roy Curtis Date: Tue, 14 Jun 2016 22:40:46 +0100 Subject: Improvements to BookMeta API * Added hasGeneration() * Fixed `applyHash()` (used by `CraftMetaItem.hashCode()`) not taking generation into account * Fixed `equalsCommon()` (used by `CraftMetaItem.equals()`) not taking generation into account --- .../java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java index d517d7d5..2ed6ad72 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java @@ -175,6 +175,10 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta { return !pages.isEmpty(); } + public boolean hasGeneration() { + return generation != null; + } + public String getTitle() { return this.title; } @@ -292,6 +296,9 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta { if (hasPages()) { hash = 61 * hash + 17 * this.pages.hashCode(); } + if (hasGeneration()) { + hash = 61 * hash + 19 * this.generation.hashCode(); + } return original != hash ? CraftMetaBook.class.hashCode() ^ hash : hash; } @@ -305,7 +312,8 @@ public class CraftMetaBook extends CraftMetaItem implements BookMeta { return (hasTitle() ? that.hasTitle() && this.title.equals(that.title) : !that.hasTitle()) && (hasAuthor() ? that.hasAuthor() && this.author.equals(that.author) : !that.hasAuthor()) - && (hasPages() ? that.hasPages() && this.pages.equals(that.pages) : !that.hasPages()); + && (hasPages() ? that.hasPages() && this.pages.equals(that.pages) : !that.hasPages()) + && (hasGeneration() ? that.hasGeneration() && this.generation.equals(that.generation) : !that.hasGeneration()); } return true; } -- cgit v1.2.3