Search in sources :

Example 6 with AnvilGUI

use of me.devtec.theapi.bukkit.gui.AnvilGUI in project TheAPI by TheDevTec.

the class v1_16_R3_Mohist method processInvClickPacket.

@Override
public boolean processInvClickPacket(Player player, HolderGUI gui, Object provPacket) {
    CClickWindowPacket packet = (CClickWindowPacket) provPacket;
    int slot = packet.func_149544_d();
    if (slot == -999)
        return false;
    int id = packet.func_149548_c();
    int mouseClick = packet.func_149543_e();
    InventoryClickType type = InventoryClickType.valueOf(packet.func_186993_f().name());
    Object container = gui.getContainer(player);
    ItemStack item = asBukkitItem(packet.func_149546_g());
    if ((type == InventoryClickType.QUICK_MOVE || type == InventoryClickType.CLONE || type == InventoryClickType.THROW || item.getType().isAir()) && item.getType().isAir())
        item = asBukkitItem(getSlotItem(container, slot));
    boolean cancel = false;
    if (InventoryClickType.SWAP == type) {
        item = player.getInventory().getItem(mouseClick);
        mouseClick = 0;
        cancel = true;
    }
    if (item == null)
        item = new ItemStack(Material.AIR);
    ItemStack before = player.getItemOnCursor();
    ClickType clickType = BukkitLoader.buildClick(item, type, slot, mouseClick);
    if (!cancel)
        cancel = BukkitLoader.useItem(player, item, gui, slot, clickType);
    if (!gui.isInsertable())
        cancel = true;
    int gameSlot = slot > gui.size() - 1 ? InventoryUtils.convertToPlayerInvSlot(slot - gui.size()) : slot;
    if (!cancel)
        cancel = gui.onIteractItem(player, item, clickType, gameSlot, slot < gui.size());
    else
        gui.onIteractItem(player, item, clickType, gameSlot, slot < gui.size());
    int position = 0;
    if (!cancel && type == InventoryClickType.QUICK_MOVE) {
        ItemStack[] contents = slot < gui.size() ? player.getInventory().getStorageContents() : gui.getInventory().getStorageContents();
        List<Integer> modified = slot < gui.size() ? InventoryUtils.shift(slot, player, gui, clickType, gui instanceof AnvilGUI ? DestinationType.PLAYER_INV_ANVIL : DestinationType.PLAYER_INV_CUSTOM_INV, null, contents, item) : InventoryUtils.shift(slot, player, gui, clickType, DestinationType.CUSTOM_INV, gui.getNotInterableSlots(player), contents, item);
        if (!modified.isEmpty()) {
            if (slot < gui.size()) {
                boolean canRemove = !modified.contains(-1);
                player.getInventory().setStorageContents(contents);
                if (canRemove) {
                    gui.remove(gameSlot);
                } else {
                    gui.getInventory().setItem(gameSlot, item);
                }
            } else {
                boolean canRemove = !modified.contains(-1);
                gui.getInventory().setStorageContents(contents);
                if (canRemove) {
                    player.getInventory().setItem(gameSlot, null);
                } else {
                    player.getInventory().setItem(gameSlot, item);
                }
            }
        }
        return true;
    }
    if (cancel) {
        // MOUSE
        BukkitLoader.getPacketHandler().send(player, packetSetSlot(-1, -1, asNMSItem(before)));
        switch(type) {
            case CLONE:
                return true;
            case SWAP:
            case QUICK_MOVE:
            case PICKUP_ALL:
                // TOP
                for (ItemStack cItem : gui.getInventory().getContents()) {
                    BukkitLoader.getPacketHandler().send(player, packetSetSlot(id, position++, asNMSItem(cItem)));
                }
                // BUTTON
                player.updateInventory();
                return true;
            default:
                BukkitLoader.getPacketHandler().send(player, packetSetSlot(id, slot, getSlotItem(container, slot)));
                if (gui instanceof AnvilGUI) {
                    // TOP
                    for (ItemStack cItem : gui.getInventory().getContents()) {
                        if (position != slot)
                            BukkitLoader.getPacketHandler().send(player, packetSetSlot(id, position++, asNMSItem(cItem)));
                    }
                    // BUTTON
                    player.updateInventory();
                }
                return true;
        }
    } else {
        if (gui instanceof AnvilGUI && slot == 2)
            postToMainThread(() -> ((RepairContainer) container).func_82846_b((PlayerEntity) getPlayer(player), slot));
    }
    return false;
}
Also used : InventoryClickType(me.devtec.theapi.bukkit.BukkitLoader.InventoryClickType) AnvilGUI(me.devtec.theapi.bukkit.gui.AnvilGUI) InventoryClickType(me.devtec.theapi.bukkit.BukkitLoader.InventoryClickType) ClickType(me.devtec.theapi.bukkit.gui.GUI.ClickType) RepairContainer(net.minecraft.inventory.container.RepairContainer) CClickWindowPacket(net.minecraft.network.play.client.CClickWindowPacket) ItemStack(org.bukkit.inventory.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack)

Example 7 with AnvilGUI

use of me.devtec.theapi.bukkit.gui.AnvilGUI in project TheAPI by TheDevTec.

the class BukkitLoader method onLoad.

public void onLoad() {
    initTheAPI(this);
    new Metrics(this, 10581);
    boolean mohist = false;
    try {
        if (Class.forName("com.mohistmc.MohistMC", true, getClassLoader()) != null)
            mohist = true;
    } catch (Exception | NoClassDefFoundError err) {
    }
    try {
        nmsProvider = (NmsProvider) Class.forName("me.devtec.theapi.bukkit.nms." + Ref.serverVersion() + (mohist ? "_Mohist" : ""), true, getClassLoader()).newInstance();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    if (nmsProvider != null)
        nmsProvider.loadParticles();
    if (new File("spigot.yml").exists() && new Config("spigot.yml").getBoolean("settings.late-bind")) {
        new Thread(() -> {
            // ASYNC
            if (Ref.isNewerThan(7))
                handler = new PacketHandler_New(true);
            else
                handler = (PacketHandler<?>) Ref.newInstanceByClass("me.devtec.theapi.bukkit.packetlistener.PacketHandler_Legacy", true);
        }).start();
    } else {
        if (Ref.isNewerThan(7))
            handler = new PacketHandler_New(false);
        else
            handler = (PacketHandler<?>) Ref.newInstanceByClass("me.devtec.theapi.bukkit.packetlistener.PacketHandler_Legacy", false);
    }
    resource = Ref.nmsOrOld("network.protocol.game.PacketPlayInResourcePackStatus", "PacketPlayInResourcePackStatus");
    close = Ref.nmsOrOld("network.protocol.game.PacketPlayInCloseWindow", "PacketPlayInCloseWindow");
    click = Ref.nmsOrOld("network.protocol.game.PacketPlayInWindowClick", "PacketPlayInWindowClick");
    itemname = Ref.nmsOrOld("network.protocol.game.PacketPlayInItemName", "PacketPlayInItemName");
    airBlock = Ref.invoke(Ref.getNulled(Ref.field(Ref.nmsOrOld("world.level.block.Block", "Block"), "AIR")), "getBlockData");
    if (airBlock == null)
        airBlock = Ref.getNulled(Ref.field(Ref.nmsOrOld("world.level.block.Blocks", "Blocks"), "AIR"));
    if (airBlock == null && Ref.isNewerThan(12))
        airBlock = Ref.invoke(Ref.get(Ref.cast(Ref.craft("block.data.CraftBlockData"), Bukkit.createBlockData(Material.AIR)), "state"), "getBlock");
    // BOSSBAR API: 1.7.10 - 1.8.8
    if (Ref.isOlderThan(9)) {
        new Tasker() {

            public void run() {
                for (BossBar s : bossbars) s.move();
            }
        }.runRepeating(0, 20);
    } else
        bossbars = null;
    new PacketListener() {

        @Override
        public boolean PacketPlayOut(String player, Object packet, Object channel) {
            return false;
        }

        public boolean isAllowedChatCharacter(char var0) {
            return var0 != 167 && var0 >= ' ' && var0 != 127;
        }

        public String buildText(String var0) {
            StringBuilder var1 = new StringBuilder();
            char[] var2 = var0.toCharArray();
            int var3 = var2.length;
            for (int var4 = 0; var4 < var3; ++var4) {
                char var5 = var2[var4];
                if (isAllowedChatCharacter(var5)) {
                    var1.append(var5);
                }
            }
            return var1.toString();
        }

        public boolean PacketPlayIn(String nick, Object packet, Object channel) {
            // NPC
            if (nick == null)
                return false;
            // ResourcePackAPI
            if (resource != null && packet.getClass() == resource) {
                Player player = Bukkit.getPlayer(nick);
                if (player == null)
                    return false;
                if (ResourcePackAPI.getResourcePack(player) == null || ResourcePackAPI.getHandlingPlayer(player) == null)
                    return false;
                ResourcePackAPI.getHandlingPlayer(player).onHandle(player, ResourcePackAPI.getResourcePack(player), ResourcePackResult.valueOf(Ref.isNewerThan(16) ? getLegacyNameOf(Ref.get(packet, Ref.isNewerThan(16) ? "a" : "status").toString()) : Ref.get(packet, Ref.isNewerThan(16) ? "a" : "status").toString()));
                return false;
            }
            // GUIS
            if (packet.getClass() == itemname) {
                Player player = Bukkit.getPlayer(nick);
                if (player == null)
                    return false;
                HolderGUI gui = BukkitLoader.gui.get(player.getUniqueId());
                if (gui != null && gui instanceof AnvilGUI) {
                    nmsProvider.postToMainThread(() -> {
                        ((AnvilGUI) gui).setRepairText(buildText(Ref.get(packet, "a") + ""));
                    });
                    return true;
                }
            }
            if (packet.getClass() == close) {
                Player player = Bukkit.getPlayer(nick);
                if (player == null)
                    return false;
                HolderGUI gui = BukkitLoader.gui.remove(player.getUniqueId());
                if (gui == null)
                    return false;
                gui.closeWithoutPacket(player);
                return true;
            }
            if (packet.getClass() == click) {
                Player player = Bukkit.getPlayer(nick);
                if (player == null)
                    return false;
                HolderGUI gui = BukkitLoader.gui.get(player.getUniqueId());
                return gui == null ? false : nmsProvider.processInvClickPacket(player, gui, packet);
            }
            return false;
        }

        private String getLegacyNameOf(String string) {
            switch(string.charAt(0)) {
                case 'a':
                    return "SUCCESSFULLY_LOADED";
                case 'b':
                    return "DECLINED";
                case 'c':
                    return "FAILED_DOWNLOAD";
                case 'd':
                    return "ACCEPTED";
            }
            return null;
        }
    }.register();
}
Also used : AnvilGUI(me.devtec.theapi.bukkit.gui.AnvilGUI) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) HolderGUI(me.devtec.theapi.bukkit.gui.HolderGUI) Config(me.devtec.shared.dataholder.Config) BossBar(me.devtec.theapi.bukkit.bossbar.BossBar) PacketHandler_New(me.devtec.theapi.bukkit.packetlistener.PacketHandler_New) PacketListener(me.devtec.theapi.bukkit.packetlistener.PacketListener) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) Tasker(me.devtec.shared.scheduler.Tasker) PacketHandler(me.devtec.theapi.bukkit.packetlistener.PacketHandler) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 8 with AnvilGUI

use of me.devtec.theapi.bukkit.gui.AnvilGUI in project TheAPI by TheDevTec.

the class v1_11_R1 method processInvClickPacket.

@Override
public boolean processInvClickPacket(Player player, HolderGUI gui, Object provPacket) {
    PacketPlayInWindowClick packet = (PacketPlayInWindowClick) provPacket;
    int slot = packet.b();
    if (slot == -999)
        return false;
    int id = packet.a();
    int mouseClick = packet.c();
    net.minecraft.server.v1_11_R1.InventoryClickType nmsType = packet.f();
    InventoryClickType type = InventoryClickType.valueOf(nmsType.name());
    Object container = gui.getContainer(player);
    ItemStack item = asBukkitItem(packet.e());
    if ((type == InventoryClickType.QUICK_MOVE || type == InventoryClickType.CLONE || type == InventoryClickType.THROW || item.getType() == Material.AIR) && item.getType() == Material.AIR)
        item = asBukkitItem(getSlotItem(container, slot));
    boolean cancel = false;
    if (InventoryClickType.SWAP == type) {
        item = player.getInventory().getItem(mouseClick);
        mouseClick = 0;
        cancel = true;
    }
    if (item == null)
        item = new ItemStack(Material.AIR);
    ItemStack before = player.getItemOnCursor();
    ClickType clickType = BukkitLoader.buildClick(item, type, slot, mouseClick);
    if (!cancel)
        cancel = BukkitLoader.useItem(player, item, gui, slot, clickType);
    if (!gui.isInsertable())
        cancel = true;
    int gameSlot = slot > gui.size() - 1 ? InventoryUtils.convertToPlayerInvSlot(slot - gui.size()) : slot;
    if (!cancel)
        cancel = gui.onIteractItem(player, item, clickType, gameSlot, slot < gui.size());
    else
        gui.onIteractItem(player, item, clickType, gameSlot, slot < gui.size());
    int position = 0;
    if (!cancel && type == InventoryClickType.QUICK_MOVE) {
        ItemStack[] contents = slot < gui.size() ? player.getInventory().getStorageContents() : gui.getInventory().getStorageContents();
        List<Integer> modified = slot < gui.size() ? InventoryUtils.shift(slot, player, gui, clickType, gui instanceof AnvilGUI ? DestinationType.PLAYER_INV_ANVIL : DestinationType.PLAYER_INV_CUSTOM_INV, null, contents, item) : InventoryUtils.shift(slot, player, gui, clickType, DestinationType.CUSTOM_INV, gui.getNotInterableSlots(player), contents, item);
        if (!modified.isEmpty()) {
            if (slot < gui.size()) {
                boolean canRemove = !modified.contains(-1);
                player.getInventory().setStorageContents(contents);
                if (canRemove) {
                    gui.remove(gameSlot);
                } else {
                    gui.getInventory().setItem(gameSlot, item);
                }
            } else {
                boolean canRemove = !modified.contains(-1);
                gui.getInventory().setStorageContents(contents);
                if (canRemove) {
                    player.getInventory().setItem(gameSlot, null);
                } else {
                    player.getInventory().setItem(gameSlot, item);
                }
            }
        }
        return true;
    }
    if (cancel) {
        // MOUSE
        BukkitLoader.getPacketHandler().send(player, packetSetSlot(-1, -1, asNMSItem(before)));
        switch(type) {
            case CLONE:
                return true;
            case SWAP:
            case QUICK_MOVE:
            case PICKUP_ALL:
                // TOP
                for (ItemStack cItem : gui.getInventory().getContents()) {
                    BukkitLoader.getPacketHandler().send(player, packetSetSlot(id, position++, asNMSItem(cItem)));
                }
                // BUTTON
                player.updateInventory();
                return true;
            default:
                BukkitLoader.getPacketHandler().send(player, packetSetSlot(id, slot, getSlotItem(container, slot)));
                if (gui instanceof AnvilGUI) {
                    // TOP
                    for (ItemStack cItem : gui.getInventory().getContents()) {
                        if (position != slot)
                            BukkitLoader.getPacketHandler().send(player, packetSetSlot(id, position++, asNMSItem(cItem)));
                    }
                    // BUTTON
                    player.updateInventory();
                }
                return true;
        }
    } else {
        if (gui instanceof AnvilGUI && slot == 2)
            postToMainThread(() -> ((ContainerAnvil) container).b((EntityPlayer) getPlayer(player), slot));
    }
    return false;
}
Also used : AnvilGUI(me.devtec.theapi.bukkit.gui.AnvilGUI) InventoryClickType(me.devtec.theapi.bukkit.BukkitLoader.InventoryClickType) InventoryClickType(me.devtec.theapi.bukkit.BukkitLoader.InventoryClickType) ClickType(me.devtec.theapi.bukkit.gui.GUI.ClickType) ContainerAnvil(net.minecraft.server.v1_11_R1.ContainerAnvil) PacketPlayInWindowClick(net.minecraft.server.v1_11_R1.PacketPlayInWindowClick) ItemStack(org.bukkit.inventory.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack)

Example 9 with AnvilGUI

use of me.devtec.theapi.bukkit.gui.AnvilGUI in project TheAPI by TheDevTec.

the class v1_10_R1 method processInvClickPacket.

@Override
public boolean processInvClickPacket(Player player, HolderGUI gui, Object provPacket) {
    PacketPlayInWindowClick packet = (PacketPlayInWindowClick) provPacket;
    int slot = packet.b();
    if (slot == -999)
        return false;
    int id = packet.a();
    int mouseClick = packet.c();
    net.minecraft.server.v1_10_R1.InventoryClickType nmsType = packet.f();
    InventoryClickType type = InventoryClickType.valueOf(nmsType.name());
    Object container = gui.getContainer(player);
    ItemStack item = asBukkitItem(packet.e());
    if ((type == InventoryClickType.QUICK_MOVE || type == InventoryClickType.CLONE || type == InventoryClickType.THROW || item.getType() == Material.AIR) && item.getType() == Material.AIR)
        item = asBukkitItem(getSlotItem(container, slot));
    boolean cancel = false;
    if (InventoryClickType.SWAP == type) {
        item = player.getInventory().getItem(mouseClick);
        mouseClick = 0;
        cancel = true;
    }
    if (item == null)
        item = new ItemStack(Material.AIR);
    ItemStack before = player.getItemOnCursor();
    ClickType clickType = BukkitLoader.buildClick(item, type, slot, mouseClick);
    if (!cancel)
        cancel = BukkitLoader.useItem(player, item, gui, slot, clickType);
    if (!gui.isInsertable())
        cancel = true;
    int gameSlot = slot > gui.size() - 1 ? InventoryUtils.convertToPlayerInvSlot(slot - gui.size()) : slot;
    if (!cancel)
        cancel = gui.onIteractItem(player, item, clickType, gameSlot, slot < gui.size());
    else
        gui.onIteractItem(player, item, clickType, gameSlot, slot < gui.size());
    int position = 0;
    if (!cancel && type == InventoryClickType.QUICK_MOVE) {
        ItemStack[] contents = slot < gui.size() ? player.getInventory().getStorageContents() : gui.getInventory().getStorageContents();
        List<Integer> modified = slot < gui.size() ? InventoryUtils.shift(slot, player, gui, clickType, gui instanceof AnvilGUI ? DestinationType.PLAYER_INV_ANVIL : DestinationType.PLAYER_INV_CUSTOM_INV, null, contents, item) : InventoryUtils.shift(slot, player, gui, clickType, DestinationType.CUSTOM_INV, gui.getNotInterableSlots(player), contents, item);
        if (!modified.isEmpty()) {
            if (slot < gui.size()) {
                boolean canRemove = !modified.contains(-1);
                player.getInventory().setStorageContents(contents);
                if (canRemove) {
                    gui.remove(gameSlot);
                } else {
                    gui.getInventory().setItem(gameSlot, item);
                }
            } else {
                boolean canRemove = !modified.contains(-1);
                gui.getInventory().setStorageContents(contents);
                if (canRemove) {
                    player.getInventory().setItem(gameSlot, null);
                } else {
                    player.getInventory().setItem(gameSlot, item);
                }
            }
        }
        return true;
    }
    if (cancel) {
        // MOUSE
        BukkitLoader.getPacketHandler().send(player, packetSetSlot(-1, -1, asNMSItem(before)));
        switch(type) {
            case CLONE:
                return true;
            case SWAP:
            case QUICK_MOVE:
            case PICKUP_ALL:
                // TOP
                for (ItemStack cItem : gui.getInventory().getContents()) {
                    BukkitLoader.getPacketHandler().send(player, packetSetSlot(id, position++, asNMSItem(cItem)));
                }
                // BUTTON
                player.updateInventory();
                return true;
            default:
                BukkitLoader.getPacketHandler().send(player, packetSetSlot(id, slot, getSlotItem(container, slot)));
                if (gui instanceof AnvilGUI) {
                    // TOP
                    for (ItemStack cItem : gui.getInventory().getContents()) {
                        if (position != slot)
                            BukkitLoader.getPacketHandler().send(player, packetSetSlot(id, position++, asNMSItem(cItem)));
                    }
                    // BUTTON
                    player.updateInventory();
                }
                return true;
        }
    } else {
        if (gui instanceof AnvilGUI && slot == 2)
            postToMainThread(() -> ((ContainerAnvil) container).b((EntityPlayer) getPlayer(player), slot));
    }
    return false;
}
Also used : AnvilGUI(me.devtec.theapi.bukkit.gui.AnvilGUI) InventoryClickType(me.devtec.theapi.bukkit.BukkitLoader.InventoryClickType) InventoryClickType(me.devtec.theapi.bukkit.BukkitLoader.InventoryClickType) ClickType(me.devtec.theapi.bukkit.gui.GUI.ClickType) ContainerAnvil(net.minecraft.server.v1_10_R1.ContainerAnvil) PacketPlayInWindowClick(net.minecraft.server.v1_10_R1.PacketPlayInWindowClick) ItemStack(org.bukkit.inventory.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack)

Example 10 with AnvilGUI

use of me.devtec.theapi.bukkit.gui.AnvilGUI in project TheAPI by TheDevTec.

the class v1_16_R2 method processInvClickPacket.

@Override
public boolean processInvClickPacket(Player player, HolderGUI gui, Object provPacket) {
    PacketPlayInWindowClick packet = (PacketPlayInWindowClick) provPacket;
    int slot = packet.c();
    if (slot == -999)
        return false;
    int id = packet.b();
    int mouseClick = packet.d();
    net.minecraft.server.v1_16_R2.InventoryClickType nmsType = packet.g();
    InventoryClickType type = InventoryClickType.valueOf(nmsType.name());
    Object container = gui.getContainer(player);
    ItemStack item = asBukkitItem(packet.f());
    if ((type == InventoryClickType.QUICK_MOVE || type == InventoryClickType.CLONE || type == InventoryClickType.THROW || item.getType().isAir()) && item.getType().isAir())
        item = asBukkitItem(getSlotItem(container, slot));
    boolean cancel = false;
    if (InventoryClickType.SWAP == type) {
        item = player.getInventory().getItem(mouseClick);
        mouseClick = 0;
        cancel = true;
    }
    if (item == null)
        item = new ItemStack(Material.AIR);
    ItemStack before = player.getItemOnCursor();
    ClickType clickType = BukkitLoader.buildClick(item, type, slot, mouseClick);
    if (!cancel)
        cancel = BukkitLoader.useItem(player, item, gui, slot, clickType);
    if (!gui.isInsertable())
        cancel = true;
    int gameSlot = slot > gui.size() - 1 ? InventoryUtils.convertToPlayerInvSlot(slot - gui.size()) : slot;
    if (!cancel)
        cancel = gui.onIteractItem(player, item, clickType, gameSlot, slot < gui.size());
    else
        gui.onIteractItem(player, item, clickType, gameSlot, slot < gui.size());
    int position = 0;
    if (!cancel && type == InventoryClickType.QUICK_MOVE) {
        ItemStack[] contents = slot < gui.size() ? player.getInventory().getStorageContents() : gui.getInventory().getStorageContents();
        List<Integer> modified = slot < gui.size() ? InventoryUtils.shift(slot, player, gui, clickType, gui instanceof AnvilGUI ? DestinationType.PLAYER_INV_ANVIL : DestinationType.PLAYER_INV_CUSTOM_INV, null, contents, item) : InventoryUtils.shift(slot, player, gui, clickType, DestinationType.CUSTOM_INV, gui.getNotInterableSlots(player), contents, item);
        if (!modified.isEmpty()) {
            if (slot < gui.size()) {
                boolean canRemove = !modified.contains(-1);
                player.getInventory().setStorageContents(contents);
                if (canRemove) {
                    gui.remove(gameSlot);
                } else {
                    gui.getInventory().setItem(gameSlot, item);
                }
            } else {
                boolean canRemove = !modified.contains(-1);
                gui.getInventory().setStorageContents(contents);
                if (canRemove) {
                    player.getInventory().setItem(gameSlot, null);
                } else {
                    player.getInventory().setItem(gameSlot, item);
                }
            }
        }
        return true;
    }
    if (cancel) {
        // MOUSE
        BukkitLoader.getPacketHandler().send(player, packetSetSlot(-1, -1, asNMSItem(before)));
        switch(type) {
            case CLONE:
                return true;
            case SWAP:
            case QUICK_MOVE:
            case PICKUP_ALL:
                // TOP
                for (ItemStack cItem : gui.getInventory().getContents()) {
                    BukkitLoader.getPacketHandler().send(player, packetSetSlot(id, position++, asNMSItem(cItem)));
                }
                // BUTTON
                player.updateInventory();
                return true;
            default:
                BukkitLoader.getPacketHandler().send(player, packetSetSlot(id, slot, getSlotItem(container, slot)));
                if (gui instanceof AnvilGUI) {
                    // TOP
                    for (ItemStack cItem : gui.getInventory().getContents()) {
                        if (position != slot)
                            BukkitLoader.getPacketHandler().send(player, packetSetSlot(id, position++, asNMSItem(cItem)));
                    }
                    // BUTTON
                    player.updateInventory();
                }
                return true;
        }
    } else {
        if (gui instanceof AnvilGUI && slot == 2)
            postToMainThread(() -> ((ContainerAnvil) container).shiftClick((EntityPlayer) getPlayer(player), slot));
    }
    return false;
}
Also used : AnvilGUI(me.devtec.theapi.bukkit.gui.AnvilGUI) InventoryClickType(me.devtec.theapi.bukkit.BukkitLoader.InventoryClickType) InventoryClickType(me.devtec.theapi.bukkit.BukkitLoader.InventoryClickType) ClickType(me.devtec.theapi.bukkit.gui.GUI.ClickType) ContainerAnvil(net.minecraft.server.v1_16_R2.ContainerAnvil) PacketPlayInWindowClick(net.minecraft.server.v1_16_R2.PacketPlayInWindowClick) CraftItemStack(org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

AnvilGUI (me.devtec.theapi.bukkit.gui.AnvilGUI)20 InventoryClickType (me.devtec.theapi.bukkit.BukkitLoader.InventoryClickType)19 ClickType (me.devtec.theapi.bukkit.gui.GUI.ClickType)19 ItemStack (org.bukkit.inventory.ItemStack)19 PacketPlayInWindowClick (net.minecraft.network.protocol.game.PacketPlayInWindowClick)3 Container (net.minecraft.world.inventory.Container)2 ContainerAnvil (net.minecraft.world.inventory.ContainerAnvil)2 File (java.io.File)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 JarFile (java.util.jar.JarFile)1 Config (me.devtec.shared.dataholder.Config)1 Tasker (me.devtec.shared.scheduler.Tasker)1 BossBar (me.devtec.theapi.bukkit.bossbar.BossBar)1 HolderGUI (me.devtec.theapi.bukkit.gui.HolderGUI)1 PacketHandler (me.devtec.theapi.bukkit.packetlistener.PacketHandler)1 PacketHandler_New (me.devtec.theapi.bukkit.packetlistener.PacketHandler_New)1 PacketListener (me.devtec.theapi.bukkit.packetlistener.PacketListener)1 RepairContainer (net.minecraft.inventory.container.RepairContainer)1 CClickWindowPacket (net.minecraft.network.play.client.CClickWindowPacket)1