Search in sources :

Example 6 with CraftContainer

use of org.bukkit.craftbukkit.v1_9_R1.inventory.CraftContainer in project Magma by magmafoundation.

the class CraftHumanEntity method openCustomInventory.

private void openCustomInventory(Inventory inventory, EntityPlayerMP player, String windowType) {
    if (player.connection == null)
        return;
    Container container = new CraftContainer(inventory, this.getHandle(), player.getNextWindowIdCB());
    container = CraftEventFactory.callInventoryOpenEvent(player, container);
    if (container == null)
        return;
    String title = container.getBukkitView().getTitle();
    int size = container.getBukkitView().getTopInventory().getSize();
    // Special cases
    if (windowType.equals("minecraft:crafting_table") || windowType.equals("minecraft:anvil") || windowType.equals("minecraft:enchanting_table")) {
        size = 0;
    }
    player.connection.sendPacket(new SPacketOpenWindow(container.windowId, windowType, new TextComponentString(title), size));
    getHandle().openContainer = container;
    getHandle().openContainer.addListener(player);
}
Also used : CraftContainer(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftContainer) Container(net.minecraft.inventory.Container) 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 7 with CraftContainer

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

the class CraftHumanEntity method openCustomInventory.

private void openCustomInventory(Inventory inventory, ServerPlayerEntity player, ContainerType<?> windowType) {
    if (player.connection == null)
        return;
    Preconditions.checkArgument(windowType != null, "Unknown windowType");
    net.minecraft.inventory.container.Container container = new CraftContainer(inventory, this.getHandle(), player.nextContainerCounter());
    container = CraftEventFactory.callInventoryOpenEvent(player, container);
    if (container == null)
        return;
    // String title = container.getBukkitView().getTitle(); // Paper - comment
    // Paper
    net.kyori.adventure.text.Component adventure$title = container.getBukkitView().title();
    // Paper
    if (adventure$title == null)
        adventure$title = io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(container.getBukkitView().getTitle());
    // player.connection.send(new SOpenWindowPacket(container.containerId, windowType, CraftChatMessage.fromString(title)[0])); // Paper // Paper - comment
    // Paper
    player.connection.send(new SOpenWindowPacket(container.containerId, windowType, io.papermc.paper.adventure.PaperAdventure.asVanilla(adventure$title)));
    getHandle().containerMenu = container;
    getHandle().containerMenu.addSlotListener(player);
}
Also used : Container(net.minecraft.inventory.container.Container) SOpenWindowPacket(net.minecraft.network.play.server.SOpenWindowPacket) CraftContainer(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftContainer)

Example 8 with CraftContainer

use of org.bukkit.craftbukkit.v1_9_R1.inventory.CraftContainer in project PaperDev by Kamillaova.

the class CraftHumanEntity method openCustomInventory.

private void openCustomInventory(Inventory inventory, EntityPlayer player, String windowType) {
    if (player.playerConnection == null)
        return;
    Container container = new CraftContainer(inventory, this.getHandle(), player.nextContainerCounter());
    container = CraftEventFactory.callInventoryOpenEvent(player, container);
    if (container == null)
        return;
    String title = container.getBukkitView().getTitle();
    int size = container.getBukkitView().getTopInventory().getSize();
    // Special cases
    if (windowType.equals("minecraft:crafting_table") || windowType.equals("minecraft:anvil") || windowType.equals("minecraft:enchanting_table")) {
        size = 0;
    }
    player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, windowType, new ChatComponentText(title), size));
    getHandle().activeContainer = container;
    getHandle().activeContainer.addSlotListener(player);
}
Also used : CraftContainer(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftContainer) CraftContainer(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftContainer)

Example 9 with CraftContainer

use of org.bukkit.craftbukkit.v1_9_R1.inventory.CraftContainer in project PaperDev by Kamillaova.

the class CraftHumanEntity method openInventory.

public void openInventory(InventoryView inventory) {
    // TODO: NPC support?
    if (!(getHandle() instanceof EntityPlayer))
        return;
    if (((EntityPlayer) getHandle()).playerConnection == null)
        return;
    if (getHandle().activeContainer != getHandle().defaultContainer) {
        // fire INVENTORY_CLOSE if one already open
        ((EntityPlayer) getHandle()).playerConnection.a(new PacketPlayInCloseWindow(getHandle().activeContainer.windowId));
    }
    EntityPlayer player = (EntityPlayer) getHandle();
    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
    InventoryType type = inventory.getType();
    String windowType = CraftContainer.getNotchInventoryType(type);
    String title = inventory.getTitle();
    int size = inventory.getTopInventory().getSize();
    player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, windowType, new ChatComponentText(title), size));
    player.activeContainer = container;
    player.activeContainer.addSlotListener(player);
}
Also used : CraftContainer(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftContainer) InventoryType(org.bukkit.event.inventory.InventoryType) CraftInventoryView(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftInventoryView) CraftContainer(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftContainer)

Example 10 with CraftContainer

use of org.bukkit.craftbukkit.v1_9_R1.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)

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