Search in sources :

Example 1 with CraftInventoryView

use of org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventoryView in project Magma by magmafoundation.

the class CraftHumanEntity method openInventory.

public void openInventory(InventoryView inventory) {
    // TODO: NPC support?
    if (!(getHandle() instanceof EntityPlayerMP))
        return;
    if (((EntityPlayerMP) getHandle()).connection == null)
        return;
    if (getHandle().openContainer != getHandle().inventoryContainer) {
        // fire INVENTORY_CLOSE if one already open
        ((EntityPlayerMP) getHandle()).connection.processCloseWindow(new CPacketCloseWindow(getHandle().openContainer.windowId));
    }
    EntityPlayerMP player = (EntityPlayerMP) getHandle();
    Container container;
    if (inventory instanceof CraftInventoryView) {
        container = ((CraftInventoryView) inventory).getHandle();
    } else {
        container = new CraftContainer(inventory, this.getHandle(), player.getNextWindowIdCB());
    }
    // Trigger an INVENTORY_OPEN event
    container = CraftEventFactory.callInventoryOpenEvent(player, container);
    if (container == null) {
        return;
    }
    // Now open the window
    InventoryType type = inventory.getType();
    String windowType = CraftContainer.getNotchInventoryType(type);
    String title = inventory.getTitle();
    int size = inventory.getTopInventory().getSize();
    player.connection.sendPacket(new SPacketOpenWindow(container.windowId, windowType, new TextComponentString(title), size));
    player.openContainer = container;
    player.openContainer.addListener(player);
}
Also used : CraftContainer(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftContainer) Container(net.minecraft.inventory.Container) InventoryType(org.bukkit.event.inventory.InventoryType) CraftInventoryView(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventoryView) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) CPacketCloseWindow(net.minecraft.network.play.client.CPacketCloseWindow) TextComponentString(net.minecraft.util.text.TextComponentString) CraftContainer(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftContainer) SPacketOpenWindow(net.minecraft.network.play.server.SPacketOpenWindow) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 2 with CraftInventoryView

use of org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventoryView in project SpaciousLib by anhcraft.

the class Anvil_1_10_R1 method open.

@Override
public void open() {
    p.setLevel(p.getLevel() + 1);
    container = new AnvilContainer(human);
    CraftInventoryView civ = container.getBukkitView();
    this.inv = civ.getTopInventory();
    for (AnvilSlot slot : this.items.keySet()) {
        this.inv.setItem(slot.getSlot(), this.items.get(slot));
    }
    int id = ep.nextContainerCounter();
    ep.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, "minecraft:anvil", new ChatMessage("Repairing", new Object[] {}), 0));
    ep.activeContainer = container;
    ep.activeContainer.windowId = id;
    ep.activeContainer.addSlotListener(ep);
}
Also used : CraftInventoryView(org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventoryView)

Example 3 with CraftInventoryView

use of org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventoryView in project SpaciousLib by anhcraft.

the class Anvil_1_8_R1 method open.

@Override
public void open() {
    p.setLevel(p.getLevel() + 1);
    container = new AnvilContainer(human);
    CraftInventoryView civ = container.getBukkitView();
    this.inv = civ.getTopInventory();
    for (AnvilSlot slot : this.items.keySet()) {
        this.inv.setItem(slot.getSlot(), this.items.get(slot));
    }
    int id = ep.nextContainerCounter();
    ep.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, "minecraft:anvil", new ChatMessage("Repairing", new Object[] {}), 0));
    ep.activeContainer = container;
    ep.activeContainer.windowId = id;
    ep.activeContainer.addSlotListener(ep);
}
Also used : CraftInventoryView(org.bukkit.craftbukkit.v1_8_R1.inventory.CraftInventoryView)

Example 4 with CraftInventoryView

use of org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventoryView in project SpaciousLib by anhcraft.

the class Anvil_1_8_R2 method open.

@Override
public void open() {
    p.setLevel(p.getLevel() + 1);
    container = new AnvilContainer(human);
    CraftInventoryView civ = container.getBukkitView();
    this.inv = civ.getTopInventory();
    for (AnvilSlot slot : this.items.keySet()) {
        this.inv.setItem(slot.getSlot(), this.items.get(slot));
    }
    int id = ep.nextContainerCounter();
    ep.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, "minecraft:anvil", new ChatMessage("Repairing", new Object[] {}), 0));
    ep.activeContainer = container;
    ep.activeContainer.windowId = id;
    ep.activeContainer.addSlotListener(ep);
}
Also used : CraftInventoryView(org.bukkit.craftbukkit.v1_8_R2.inventory.CraftInventoryView)

Example 5 with CraftInventoryView

use of org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventoryView in project SpaciousLib by anhcraft.

the class Anvil_1_12_R1 method open.

@Override
public void open() {
    p.setLevel(p.getLevel() + 1);
    container = new AnvilContainer(human);
    CraftInventoryView civ = container.getBukkitView();
    this.inv = civ.getTopInventory();
    for (AnvilSlot slot : this.items.keySet()) {
        this.inv.setItem(slot.getSlot(), this.items.get(slot));
    }
    int id = ep.nextContainerCounter();
    ep.playerConnection.sendPacket(new PacketPlayOutOpenWindow(id, "minecraft:anvil", new ChatMessage("Repairing", new Object[] {}), 0));
    ep.activeContainer = container;
    ep.activeContainer.windowId = id;
    ep.activeContainer.addSlotListener(ep);
}
Also used : CraftInventoryView(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventoryView)

Aggregations

CraftInventoryView (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventoryView)3 CraftInventoryView (org.bukkit.craftbukkit.v1_10_R1.inventory.CraftInventoryView)2 CraftInventoryView (org.bukkit.craftbukkit.v1_11_R1.inventory.CraftInventoryView)2 CraftInventoryView (org.bukkit.craftbukkit.v1_8_R1.inventory.CraftInventoryView)2 CraftInventoryView (org.bukkit.craftbukkit.v1_8_R2.inventory.CraftInventoryView)2 CraftInventoryView (org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventoryView)2 CraftInventoryView (org.bukkit.craftbukkit.v1_9_R1.inventory.CraftInventoryView)2 CraftInventoryView (org.bukkit.craftbukkit.v1_9_R2.inventory.CraftInventoryView)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1 Container (net.minecraft.inventory.Container)1 Container (net.minecraft.inventory.container.Container)1 CCloseWindowPacket (net.minecraft.network.play.client.CCloseWindowPacket)1 CPacketCloseWindow (net.minecraft.network.play.client.CPacketCloseWindow)1 SPacketOpenWindow (net.minecraft.network.play.server.SPacketOpenWindow)1 ClientboundOpenScreenPacket (net.minecraft.network.protocol.game.ClientboundOpenScreenPacket)1 ServerboundContainerClosePacket (net.minecraft.network.protocol.game.ServerboundContainerClosePacket)1 ServerPlayer (net.minecraft.server.level.ServerPlayer)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 AbstractContainerMenu (net.minecraft.world.inventory.AbstractContainerMenu)1