Items take forever to show in newly created GUI

Discussion in 'Spigot Plugin Development' started by devonzimmi, Nov 14, 2019.

  1. I've successfully created a GUI with items inside it. My problem with this though is that after the server starts and I type the command to open the GUI, the items inside take about 3-4 seconds to actually appear.

    I initialize the GUI inside my onEnable()
    Code (Text):
    public void onEnable() {
        getLogger().info("nvd loaded");



    And my initialize method looks like this:
    Code (Text):
    public static void initializeItems() {
        inv = Bukkit.createInventory(owner, 9, "§lmyGUI");
    The GUI is opened through a command:
    Code (Text):
    if (args.length == 0) {
       myGUI.openInventory((Player) sender);
       return true;
    Why are the items taking so long to appear?

    Edit 1
    How my items are set:
    Code (Text):
    static void guiSetUnmuted() {
            inv.setItem(4, createGuiItem(Material.WHITE_CONCRETE, "item 2", false, "lore", "lore"));

        static void guiSetMuted() {
            inv.setItem(4, createGuiItem(Material.RED_CONCRETE, "item 1", true, "lore", "lore"));
    How my items are created:
    Code (Text):
        private static ItemStack createGuiItem(Material material, String name, boolean enchanted, String... lore) {
            ItemStack item = new ItemStack(material, 1);

            if(enchanted) {
                item.addUnsafeEnchantment(Enchantment.LUCK, 1);

            ItemMeta meta = item.getItemMeta();

            ArrayList<String> metalore = new ArrayList<String>(Arrays.asList(lore));

            return item;
    Edit 2
    How I open the inventory.
    Code (Text):
    public static void openInventory(Player p) {
    #1 devonzimmi, Nov 14, 2019
    Last edited: Nov 14, 2019
  2. We have no way to even access your problem if you don't specify the code that inserts items into the GUI.
    • Agree Agree x 2
  3. I totally didn't even think to do that. I've edited my original post with how my items are set. Thank you for pointing that out!
  4. I don't see anything in the code you provided that would make your task execute in incredibly slow speed, but in order to verify that I'm suggesting to measure the time that myGUI.initializeItems(); takes to finish using:

    Code (Java):

    long before = System.currentTimeMillis();
    long after = System.currentTimeMillis();

    System.out.println((after-before) + "ms!");
  5. It's not an issue of how long the method takes to execute. It's called in #onEnable, then opened by a player well after the onEnable method ends.
    Is there any difference if you create the inventory the first time it's meant to be opened, rather than when the plugin is enabled?
  6. oh yeah, whoops.
    Thread opener, can you show the code of myGUI.openInventory()?
  7. There is absolutely no difference between the two.

    I have put an edit in the original post as well as a code block here. Could there be a more efficent way to open the inventory?

    Code (Text):
    public static void openInventory(Player p) {
  8. nope, it's the only way to open an inventory for a player.. can you try opening an empty inventory?
  9. Not sure why you need that but I did it anyways. No items appeared.
  10. are you using some weird api or spigot fork? i saw someone else with the similar issue as you a few months ago and i couldn't reproduce it either on spigot using my own implementation
  11. Here is my pom file. Not sure if i'm using the right source.

    Code (Text):
    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns:xsi=""






  12. i don't see a problem with this one, maybe uhm the way where you refresh the items?
  13. I'm not really sure the cause of it myself - it comes up occasionally - but I wouldn't sweat it. There's probably some reason that the client takes a bit longer than usual to show the items in the inventory.
    You could also see if there's any changes depending on when you populate the inventory. It might be quicker if it's after a player opens it the first time. Just a hunch, so don't hold me accountable, lol. Otherwise, though, it shouldn't cause any major issues.
    Not necessarily related to the issue, but you don't need to depend on both Spigot and Bukkit, since Spigot is a fork of Bukkit.
    • Like Like x 1
  14. As of right now, the items are not refreshed. The only time it takes items forever to show up is after server start up. After that, it's like normal.