mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-01 20:50:41 +01:00
Strip events from book pages on signing
This commit is contained in:
parent
815922ab1a
commit
e4ca2af9c4
2 changed files with 35 additions and 3 deletions
|
@ -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<IChatBaseComponent> 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<IChatBaseComponent> 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);
|
||||
|
|
|
@ -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<IChatBaseComponent> pages = new ArrayList<IChatBaseComponent>();
|
||||
public List<IChatBaseComponent> pages = new ArrayList<IChatBaseComponent>();
|
||||
protected Integer generation;
|
||||
|
||||
CraftMetaBook(CraftMetaItem meta) {
|
||||
|
|
Loading…
Reference in a new issue