Search in sources :

Example 1 with CraftContainer

use of org.bukkit.craftbukkit.v1_8_R3.inventory.CraftContainer in project MyPet by xXKeyleXx.

the class CustomInventory method open.

@Override
public void open(Player player) {
    EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
    Container container = new CraftContainer(getBukkitInventory(), entityPlayer, entityPlayer.nextContainerCounter());
    container = CraftEventFactory.callInventoryOpenEvent(entityPlayer, container);
    if (container != null) {
        Containers customSize = Containers.GENERIC_9X1;
        switch(this.getSize()) {
            case 18:
                customSize = Containers.GENERIC_9X2;
                break;
            case 27:
                customSize = Containers.GENERIC_9X3;
                break;
            case 36:
                customSize = Containers.GENERIC_9X4;
                break;
            case 45:
                customSize = Containers.GENERIC_9X5;
                break;
            case 54:
                customSize = Containers.GENERIC_9X6;
                break;
        }
        entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, customSize, new ChatComponentText(this.getName())));
        entityPlayer.activeContainer = container;
        entityPlayer.activeContainer.addSlotListener(entityPlayer);
    }
}
Also used : CraftContainer(org.bukkit.craftbukkit.v1_16_R1.inventory.CraftContainer) CraftPlayer(org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer) CraftContainer(org.bukkit.craftbukkit.v1_16_R1.inventory.CraftContainer)

Example 2 with CraftContainer

use of org.bukkit.craftbukkit.v1_8_R3.inventory.CraftContainer in project MyPet by xXKeyleXx.

the class CustomInventory method open.

@Override
public void open(Player player) {
    EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
    Container container = new CraftContainer(getBukkitInventory(), entityPlayer, entityPlayer.nextContainerCounter());
    container = CraftEventFactory.callInventoryOpenEvent(entityPlayer, container);
    if (container != null) {
        Containers customSize = Containers.GENERIC_9X1;
        switch(this.getSize()) {
            case 18:
                customSize = Containers.GENERIC_9X2;
                break;
            case 27:
                customSize = Containers.GENERIC_9X3;
                break;
            case 36:
                customSize = Containers.GENERIC_9X4;
                break;
            case 45:
                customSize = Containers.GENERIC_9X5;
                break;
            case 54:
                customSize = Containers.GENERIC_9X6;
                break;
        }
        entityPlayer.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, customSize, new ChatComponentText(this.getName())));
        entityPlayer.activeContainer = container;
        entityPlayer.activeContainer.addSlotListener(entityPlayer);
    }
}
Also used : CraftContainer(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftContainer) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) CraftContainer(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftContainer)

Example 3 with CraftContainer

use of org.bukkit.craftbukkit.v1_8_R3.inventory.CraftContainer in project MyPet by xXKeyleXx.

the class CustomInventory method open.

@Override
public void open(Player player) {
    ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle();
    AbstractContainerMenu container = new CraftContainer(getBukkitInventory(), entityPlayer, entityPlayer.nextContainerCounter());
    container = CraftEventFactory.callInventoryOpenEvent(entityPlayer, container);
    if (container != null) {
        MenuType<?> customSize = MenuType.GENERIC_9x1;
        switch(this.getContainerSize()) {
            case 18:
                customSize = MenuType.GENERIC_9x2;
                break;
            case 27:
                customSize = MenuType.GENERIC_9x3;
                break;
            case 36:
                customSize = MenuType.GENERIC_9x4;
                break;
            case 45:
                customSize = MenuType.GENERIC_9x5;
                break;
            case 54:
                customSize = MenuType.GENERIC_9x6;
                break;
        }
        entityPlayer.connection.send(new ClientboundOpenScreenPacket(container.containerId, customSize, new TextComponent(this.getName())));
        entityPlayer.containerMenu = container;
        entityPlayer.initMenu(container);
    }
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) AbstractContainerMenu(net.minecraft.world.inventory.AbstractContainerMenu) ServerPlayer(net.minecraft.server.level.ServerPlayer) ClientboundOpenScreenPacket(net.minecraft.network.protocol.game.ClientboundOpenScreenPacket) CraftPlayer(org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer) CraftContainer(org.bukkit.craftbukkit.v1_17_R1.inventory.CraftContainer)

Example 4 with CraftContainer

use of org.bukkit.craftbukkit.v1_8_R3.inventory.CraftContainer in project MyPet by xXKeyleXx.

the class CustomInventory method open.

@Override
public void open(Player player) {
    ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle();
    AbstractContainerMenu container = new CraftContainer(getBukkitInventory(), entityPlayer, entityPlayer.nextContainerCounter());
    container = CraftEventFactory.callInventoryOpenEvent(entityPlayer, container);
    if (container != null) {
        MenuType<?> customSize = MenuType.GENERIC_9x1;
        switch(this.getContainerSize()) {
            case 18:
                customSize = MenuType.GENERIC_9x2;
                break;
            case 27:
                customSize = MenuType.GENERIC_9x3;
                break;
            case 36:
                customSize = MenuType.GENERIC_9x4;
                break;
            case 45:
                customSize = MenuType.GENERIC_9x5;
                break;
            case 54:
                customSize = MenuType.GENERIC_9x6;
                break;
        }
        entityPlayer.connection.send(new ClientboundOpenScreenPacket(container.containerId, customSize, new TextComponent(this.getName())));
        entityPlayer.containerMenu = container;
        entityPlayer.initMenu(container);
    }
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) AbstractContainerMenu(net.minecraft.world.inventory.AbstractContainerMenu) ServerPlayer(net.minecraft.server.level.ServerPlayer) ClientboundOpenScreenPacket(net.minecraft.network.protocol.game.ClientboundOpenScreenPacket) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) CraftContainer(org.bukkit.craftbukkit.v1_18_R1.inventory.CraftContainer)

Example 5 with CraftContainer

use of org.bukkit.craftbukkit.v1_8_R3.inventory.CraftContainer 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)

Aggregations

ClientboundOpenScreenPacket (net.minecraft.network.protocol.game.ClientboundOpenScreenPacket)4 AbstractContainerMenu (net.minecraft.world.inventory.AbstractContainerMenu)4 CraftContainer (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftContainer)4 ServerPlayer (net.minecraft.server.level.ServerPlayer)3 CraftContainer (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftContainer)3 Container (net.minecraft.inventory.Container)2 Container (net.minecraft.inventory.container.Container)2 TextComponent (net.minecraft.network.chat.TextComponent)2 SPacketOpenWindow (net.minecraft.network.play.server.SPacketOpenWindow)2 TextComponentString (net.minecraft.util.text.TextComponentString)2 CraftInventoryView (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventoryView)2 CraftContainer (org.bukkit.craftbukkit.v1_18_R2.inventory.CraftContainer)2 InventoryType (org.bukkit.event.inventory.InventoryType)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1 CCloseWindowPacket (net.minecraft.network.play.client.CCloseWindowPacket)1 CPacketCloseWindow (net.minecraft.network.play.client.CPacketCloseWindow)1 SOpenWindowPacket (net.minecraft.network.play.server.SOpenWindowPacket)1 ServerboundContainerClosePacket (net.minecraft.network.protocol.game.ServerboundContainerClosePacket)1 CraftPlayer (org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer)1