use of org.bukkit.craftbukkit.v1_12_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);
}
use of org.bukkit.craftbukkit.v1_12_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);
}
use of org.bukkit.craftbukkit.v1_12_R1.inventory.CraftContainer in project MyPet by MyPetORG.
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);
}
}
use of org.bukkit.craftbukkit.v1_12_R1.inventory.CraftContainer in project MyPet by MyPetORG.
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);
}
}
use of org.bukkit.craftbukkit.v1_12_R1.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);
}
}
Aggregations