diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index 7da317c81c..10ac9590cd 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -28,6 +28,7 @@ import org.bukkit.craftbukkit.entity.CraftLivingEntity; import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.craftbukkit.inventory.CraftInventoryCrafting; import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.craftbukkit.inventory.CraftMetaBook; import org.bukkit.craftbukkit.util.CraftDamageSource; import org.bukkit.craftbukkit.util.CraftMagicNumbers; import org.bukkit.entity.Arrow; @@ -834,7 +835,12 @@ public class CraftEventFactory { if (editBookEvent.isSigning()) { itemInHand.setItem(Items.WRITTEN_BOOK); } - CraftItemStack.setItemMeta(itemInHand, editBookEvent.getNewBookMeta()); + CraftMetaBook meta = (CraftMetaBook) editBookEvent.getNewBookMeta(); + List pages = meta.pages; + for (int i = 0; i < pages.size(); i++) { + pages.set(i, stripEvents(pages.get(i))); + } + CraftItemStack.setItemMeta(itemInHand, meta); } // Client will have updated its idea of the book item; we need to overwrite that @@ -843,6 +849,32 @@ public class CraftEventFactory { } } + private static IChatBaseComponent stripEvents(IChatBaseComponent c) { + ChatModifier modi = c.getChatModifier(); + if (modi != null) { + modi.setChatClickable(null); + modi.setChatHoverable(null); + } + c.setChatModifier(modi); + if (c instanceof ChatMessage) { + ChatMessage cm = (ChatMessage) c; + Object[] oo = cm.j(); + for (int i = 0; i < oo.length; i++) { + Object o = oo[i]; + if (o instanceof IChatBaseComponent) { + oo[i] = stripEvents((IChatBaseComponent) o); + } + } + } + List ls = c.a(); + if (ls != null) { + for (int i = 0; i < ls.size(); i++) { + ls.set(i, stripEvents(ls.get(i))); + } + } + return c; + } + public static PlayerUnleashEntityEvent callPlayerUnleashEntityEvent(EntityInsentient entity, EntityHuman player) { PlayerUnleashEntityEvent event = new PlayerUnleashEntityEvent(entity.getBukkitEntity(), (Player) player.getBukkitEntity()); entity.world.getServer().getPluginManager().callEvent(event); diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java index f23decd36d..0318958828 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java @@ -23,7 +23,7 @@ import net.minecraft.server.NBTTagString; import org.bukkit.craftbukkit.util.CraftChatMessage; @DelegateDeserialization(SerializableMeta.class) -class CraftMetaBook extends CraftMetaItem implements BookMeta { +public class CraftMetaBook extends CraftMetaItem implements BookMeta { static final ItemMetaKey BOOK_TITLE = new ItemMetaKey("title"); static final ItemMetaKey BOOK_AUTHOR = new ItemMetaKey("author"); static final ItemMetaKey BOOK_PAGES = new ItemMetaKey("pages"); @@ -34,7 +34,7 @@ class CraftMetaBook extends CraftMetaItem implements BookMeta { protected String title; protected String author; - protected List pages = new ArrayList(); + public List pages = new ArrayList(); protected Integer generation; CraftMetaBook(CraftMetaItem meta) {