Search in sources :

Example 1 with CCloseWindowPacket

use of net.minecraft.network.play.client.CCloseWindowPacket in project Magma-1.16.x by magmafoundation.

the class CraftEventFactory method callInventoryOpenEvent.

public static Container callInventoryOpenEvent(ServerPlayerEntity player, Container container, boolean cancelled) {
    if (player.containerMenu != player.inventoryMenu) {
        // fire INVENTORY_CLOSE if one already open
        player.connection.handleContainerClose(new CCloseWindowPacket(player.containerMenu.containerId));
    }
    CraftServer server = player.level.getServerCB();
    CraftPlayer craftPlayer = player.getBukkitEntity();
    try {
        player.containerMenu.transferTo(container, craftPlayer);
    } catch (AbstractMethodError e) {
    // Magma - modded
    }
    InventoryOpenEvent event = new InventoryOpenEvent(container.getBukkitView());
    event.setCancelled(cancelled);
    if (container.getBukkitView() != null) {
        server.getPluginManager().callEvent(event);
    }
    if (event.isCancelled()) {
        container.transferTo(player.containerMenu, craftPlayer);
        if (!cancelled) {
            // fire INVENTORY_CLOSE if one already open
            player.containerMenu = container;
            player.closeContainer();
            player.containerMenu = player.inventoryMenu;
        }
        return null;
    }
    return container;
}
Also used : InventoryOpenEvent(org.bukkit.event.inventory.InventoryOpenEvent) CCloseWindowPacket(net.minecraft.network.play.client.CCloseWindowPacket) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) CraftServer(org.bukkit.craftbukkit.v1_16_R3.CraftServer)

Example 2 with CCloseWindowPacket

use of net.minecraft.network.play.client.CCloseWindowPacket 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 3 with CCloseWindowPacket

use of net.minecraft.network.play.client.CCloseWindowPacket in project LoliServer by Loli-Server.

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.nextContainerCounterCB());
    }
    // 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();
    player.connection.send(new SOpenWindowPacket(container.containerId, windowType, CraftChatMessage.fromString(title)[0]));
    player.containerMenu = container;
    player.containerMenu.addSlotListener(player);
}
Also used : CCloseWindowPacket(net.minecraft.network.play.client.CCloseWindowPacket) Container(net.minecraft.inventory.container.Container) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SOpenWindowPacket(net.minecraft.network.play.server.SOpenWindowPacket)

Example 4 with CCloseWindowPacket

use of net.minecraft.network.play.client.CCloseWindowPacket in project LoliServer by Loli-Server.

the class CraftEventFactory method callInventoryOpenEvent.

public static Container callInventoryOpenEvent(ServerPlayerEntity player, Container container, boolean cancelled) {
    if (player.containerMenu != player.inventoryMenu) {
        // fire INVENTORY_CLOSE if one already open
        player.connection.handleContainerClose(new CCloseWindowPacket(player.containerMenu.containerId));
    }
    CraftServer server = player.level.getCBServer();
    CraftPlayer craftPlayer = player.getBukkitEntity();
    try {
        player.containerMenu.transferTo(container, craftPlayer);
    } catch (AbstractMethodError e) {
    }
    InventoryOpenEvent event = new InventoryOpenEvent(container.getBukkitView());
    event.setCancelled(cancelled);
    if (container.getBukkitView() != null) {
        server.getPluginManager().callEvent(event);
    }
    if (event.isCancelled()) {
        container.transferTo(player.containerMenu, craftPlayer);
        if (!cancelled) {
            // fire INVENTORY_CLOSE if one already open
            // make sure the right container is processed
            player.containerMenu = container;
            player.closeContainer();
            player.containerMenu = player.inventoryMenu;
        }
        return null;
    }
    return container;
}
Also used : InventoryOpenEvent(org.bukkit.event.inventory.InventoryOpenEvent) CCloseWindowPacket(net.minecraft.network.play.client.CCloseWindowPacket) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) CraftServer(org.bukkit.craftbukkit.v1_16_R3.CraftServer)

Aggregations

CCloseWindowPacket (net.minecraft.network.play.client.CCloseWindowPacket)4 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 Container (net.minecraft.inventory.container.Container)2 CraftServer (org.bukkit.craftbukkit.v1_16_R3.CraftServer)2 CraftPlayer (org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer)2 InventoryOpenEvent (org.bukkit.event.inventory.InventoryOpenEvent)2 SOpenWindowPacket (net.minecraft.network.play.server.SOpenWindowPacket)1 CraftContainer (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftContainer)1 CraftInventoryView (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryView)1