Search in sources :

Example 11 with CraftContainer

use of org.bukkit.craftbukkit.v1_16_R2.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 12 with CraftContainer

use of org.bukkit.craftbukkit.v1_16_R2.inventory.CraftContainer in project Magma-1.16.x by magmafoundation.

the class CraftHumanEntity method openInventory.

@Override
public void openInventory(InventoryView inventory) {
    // TODO: NPC support?
    if (!(getHandle() instanceof ServerPlayerEntity))
        return;
    if (((ServerPlayerEntity) getHandle()).connection == null)
        return;
    if (getHandle().containerMenu != getHandle().inventoryMenu) {
        // fire INVENTORY_CLOSE if one already open
        ((ServerPlayerEntity) getHandle()).connection.handleContainerClose(new CCloseWindowPacket(getHandle().containerMenu.containerId));
    }
    ServerPlayerEntity player = (ServerPlayerEntity) getHandle();
    net.minecraft.inventory.container.Container container;
    if (inventory instanceof CraftInventoryView) {
        container = ((CraftInventoryView) inventory).getHandle();
    } else {
        container = new CraftContainer(inventory, this.getHandle(), player.nextContainerCounter());
    }
    // Trigger an INVENTORY_OPEN event
    container = CraftEventFactory.callInventoryOpenEvent(player, container);
    if (container == null) {
        return;
    }
    // Now open the window
    ContainerType<?> windowType = CraftContainer.getNotchInventoryType(inventory.getTopInventory());
    // String title = inventory.getTitle(); // Paper - comment
    // Paper
    net.kyori.adventure.text.Component adventure$title = inventory.title();
    // Paper
    if (adventure$title == null)
        adventure$title = io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(inventory.getTitle());
    player.containerMenu = container;
    player.containerMenu.addSlotListener(player);
}
Also used : CraftInventoryView(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryView) CCloseWindowPacket(net.minecraft.network.play.client.CCloseWindowPacket) Container(net.minecraft.inventory.container.Container) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) CraftContainer(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftContainer)

Example 13 with CraftContainer

use of org.bukkit.craftbukkit.v1_16_R2.inventory.CraftContainer in project Mohist by MohistMC.

the class CraftHumanEntity method openCustomInventory.

private static void openCustomInventory(Inventory inventory, ServerPlayer player, MenuType<?> windowType) {
    if (player.connection == null)
        return;
    Preconditions.checkArgument(windowType != null, "Unknown windowType");
    AbstractContainerMenu container = new CraftContainer(inventory, player, player.nextContainerCounterInt());
    container = CraftEventFactory.callInventoryOpenEvent(player, container);
    if (container == null)
        return;
    String title = container.getBukkitView().getTitle();
    player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, CraftChatMessage.fromString(title)[0]));
    player.containerMenu = container;
    player.initMenu(container);
}
Also used : AbstractContainerMenu(net.minecraft.world.inventory.AbstractContainerMenu) ClientboundOpenScreenPacket(net.minecraft.network.protocol.game.ClientboundOpenScreenPacket) CraftContainer(org.bukkit.craftbukkit.v1_18_R2.inventory.CraftContainer)

Example 14 with CraftContainer

use of org.bukkit.craftbukkit.v1_16_R2.inventory.CraftContainer in project Mohist by MohistMC.

the class CraftHumanEntity method openInventory.

@Override
public void openInventory(InventoryView inventory) {
    // TODO: NPC support?
    if (!(getHandle() instanceof ServerPlayer))
        return;
    if (((ServerPlayer) getHandle()).connection == null)
        return;
    if (getHandle().containerMenu != getHandle().inventoryMenu) {
        // fire INVENTORY_CLOSE if one already open
        ((ServerPlayer) getHandle()).connection.handleContainerClose(new ServerboundContainerClosePacket(getHandle().containerMenu.containerId));
    }
    ServerPlayer player = (ServerPlayer) getHandle();
    AbstractContainerMenu container;
    if (inventory instanceof CraftInventoryView) {
        container = ((CraftInventoryView) inventory).getHandle();
    } else {
        container = new CraftContainer(inventory, this.getHandle(), player.nextContainerCounterInt());
    }
    // Trigger an INVENTORY_OPEN event
    container = CraftEventFactory.callInventoryOpenEvent(player, container);
    if (container == null) {
        return;
    }
    // Now open the window
    MenuType<?> windowType = CraftContainer.getNotchInventoryType(inventory.getTopInventory());
    String title = inventory.getTitle();
    player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, CraftChatMessage.fromString(title)[0]));
    player.containerMenu = container;
    player.initMenu(container);
}
Also used : AbstractContainerMenu(net.minecraft.world.inventory.AbstractContainerMenu) CraftInventoryView(org.bukkit.craftbukkit.v1_18_R2.inventory.CraftInventoryView) ServerPlayer(net.minecraft.server.level.ServerPlayer) ServerboundContainerClosePacket(net.minecraft.network.protocol.game.ServerboundContainerClosePacket) ClientboundOpenScreenPacket(net.minecraft.network.protocol.game.ClientboundOpenScreenPacket) CraftContainer(org.bukkit.craftbukkit.v1_18_R2.inventory.CraftContainer)

Example 15 with CraftContainer

use of org.bukkit.craftbukkit.v1_16_R2.inventory.CraftContainer in project MyPet by MyPetORG.

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)

Aggregations

ClientboundOpenScreenPacket (net.minecraft.network.protocol.game.ClientboundOpenScreenPacket)7 AbstractContainerMenu (net.minecraft.world.inventory.AbstractContainerMenu)7 ServerPlayer (net.minecraft.server.level.ServerPlayer)6 TextComponent (net.minecraft.network.chat.TextComponent)5 CraftContainer (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftContainer)4 CraftContainer (org.bukkit.craftbukkit.v1_18_R2.inventory.CraftContainer)3 Container (net.minecraft.inventory.Container)2 Container (net.minecraft.inventory.container.Container)2 SPacketOpenWindow (net.minecraft.network.play.server.SPacketOpenWindow)2 TextComponentString (net.minecraft.util.text.TextComponentString)2 CraftContainer (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftContainer)2 CraftPlayer (org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer)2 CraftContainer (org.bukkit.craftbukkit.v1_16_R1.inventory.CraftContainer)2 CraftPlayer (org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer)2 CraftPlayer (org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer)2 CraftContainer (org.bukkit.craftbukkit.v1_17_R1.inventory.CraftContainer)2 CraftPlayer (org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer)2 CraftContainer (org.bukkit.craftbukkit.v1_18_R1.inventory.CraftContainer)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1