Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-18 12:30:06 +01:00
Implement PlayerBookEditEvent. Adds BUKKIT-1995
Dieser Commit ist enthalten in:
Ursprung
c55c0db86d
Commit
045121d095
@ -1661,10 +1661,10 @@ public class PlayerConnection extends Connection {
|
||||
|
||||
itemstack1 = this.player.inventory.getItemInHand();
|
||||
if (itemstack != null && itemstack.id == Item.BOOK_AND_QUILL.id && itemstack.id == itemstack1.id) {
|
||||
itemstack1.a("pages", (NBTBase) itemstack.getTag().getList("pages"));
|
||||
CraftEventFactory.handleEditBookEvent(player, itemstack); // CraftBukkit
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
// CraftBukkit start
|
||||
} catch (Throwable exception) {
|
||||
this.minecraftServer.getLogger().warning(this.player.name + " sent invalid MC|BEdit data", exception);
|
||||
this.disconnect("Invalid book data!");
|
||||
// CraftBukkit end
|
||||
@ -1679,13 +1679,10 @@ public class PlayerConnection extends Connection {
|
||||
|
||||
itemstack1 = this.player.inventory.getItemInHand();
|
||||
if (itemstack != null && itemstack.id == Item.WRITTEN_BOOK.id && itemstack1.id == Item.BOOK_AND_QUILL.id) {
|
||||
itemstack1.a("author", (NBTBase) (new NBTTagString("author", this.player.name)));
|
||||
itemstack1.a("title", (NBTBase) (new NBTTagString("title", itemstack.getTag().getString("title"))));
|
||||
itemstack1.a("pages", (NBTBase) itemstack.getTag().getList("pages"));
|
||||
itemstack1.id = Item.WRITTEN_BOOK.id;
|
||||
CraftEventFactory.handleEditBookEvent(player, itemstack); // CraftBukkit
|
||||
}
|
||||
} catch (Exception exception1) {
|
||||
// CraftBukkit start
|
||||
} catch (Throwable exception1) {
|
||||
this.minecraftServer.getLogger().warning(this.player.name + " sent invalid MC|BSign data", exception1);
|
||||
this.disconnect("Invalid book data!");
|
||||
// CraftBukkit end
|
||||
|
@ -18,10 +18,13 @@ import net.minecraft.server.EntityLiving;
|
||||
import net.minecraft.server.EntityPlayer;
|
||||
import net.minecraft.server.EntityPotion;
|
||||
import net.minecraft.server.Explosion;
|
||||
import net.minecraft.server.IInventory;
|
||||
import net.minecraft.server.InventoryCrafting;
|
||||
import net.minecraft.server.Item;
|
||||
import net.minecraft.server.ItemStack;
|
||||
import net.minecraft.server.Packet101CloseWindow;
|
||||
import net.minecraft.server.Packet103SetSlot;
|
||||
import net.minecraft.server.Slot;
|
||||
import net.minecraft.server.World;
|
||||
import net.minecraft.server.WorldServer;
|
||||
|
||||
@ -64,6 +67,7 @@ import org.bukkit.event.inventory.PrepareItemCraftEvent;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.event.server.ServerListPingEvent;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
|
||||
public class CraftEventFactory {
|
||||
public static final DamageSource MELTING = CraftDamageSource.copyOf(DamageSource.BURN);
|
||||
@ -672,4 +676,26 @@ public class CraftEventFactory {
|
||||
human.world.getServer().getPluginManager().callEvent(event);
|
||||
human.activeContainer.transferTo(human.defaultContainer, human.getBukkitEntity());
|
||||
}
|
||||
|
||||
public static void handleEditBookEvent(EntityPlayer player, ItemStack newBookItem) {
|
||||
int itemInHandIndex = player.inventory.itemInHandIndex;
|
||||
|
||||
PlayerEditBookEvent editBookEvent = new PlayerEditBookEvent(player.getBukkitEntity(), player.inventory.itemInHandIndex, (BookMeta) CraftItemStack.getItemMeta(player.inventory.getItemInHand()), (BookMeta) CraftItemStack.getItemMeta(newBookItem), newBookItem.id == Item.WRITTEN_BOOK.id);
|
||||
player.world.getServer().getPluginManager().callEvent(editBookEvent);
|
||||
ItemStack itemInHand = player.inventory.getItem(itemInHandIndex);
|
||||
|
||||
// If they've got the same item in their hand, it'll need to be updated.
|
||||
if (itemInHand.id == Item.BOOK_AND_QUILL.id) {
|
||||
if (!editBookEvent.isCancelled()) {
|
||||
CraftItemStack.setItemMeta(itemInHand, editBookEvent.getNewBookMeta());
|
||||
if (editBookEvent.isSigning()) {
|
||||
itemInHand.id = Item.WRITTEN_BOOK.id;
|
||||
}
|
||||
}
|
||||
|
||||
// Client will have updated its idea of the book item; we need to overwrite that
|
||||
Slot slot = player.activeContainer.a((IInventory) player.inventory, itemInHandIndex);
|
||||
player.playerConnection.sendPacket(new Packet103SetSlot(player.activeContainer.windowId, slot.g, itemInHand));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -298,7 +298,7 @@ public final class CraftItemStack extends ItemStack {
|
||||
return getItemMeta(handle);
|
||||
}
|
||||
|
||||
static ItemMeta getItemMeta(net.minecraft.server.ItemStack item) {
|
||||
public static ItemMeta getItemMeta(net.minecraft.server.ItemStack item) {
|
||||
if (!hasItemMeta(item)) {
|
||||
return CraftItemFactory.instance().getItemMeta(getType(item));
|
||||
}
|
||||
@ -338,7 +338,7 @@ public final class CraftItemStack extends ItemStack {
|
||||
return setItemMeta(handle, itemMeta);
|
||||
}
|
||||
|
||||
static boolean setItemMeta(net.minecraft.server.ItemStack item, ItemMeta itemMeta) {
|
||||
public static boolean setItemMeta(net.minecraft.server.ItemStack item, ItemMeta itemMeta) {
|
||||
if (item == null) {
|
||||
return false;
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren