Solved Inventory#setItem not working

Discussion in 'Spigot Plugin Development' started by FiXed, Jun 1, 2016.

Thread Status:
Not open for further replies.
  1. So this has been working for a while until... I switched the server to bungeecord, this is my code:
    Code (Java):
        @EventHandler
        public void onJoin(PlayerJoinEvent event) {
            Bukkit.broadcastMessage("Handling...");
            new BukkitRunnable() {
                @Override
                public void run() {
                    event.getPlayer().getInventory().setItem(selectorSlot - 1, selector);
                    event.getPlayer().updateInventory();
                    Bukkit.broadcastMessage("Handled...");
                }
            }.runTaskLater(ServerSelector.getPlugin(), 10L);
        }
    This is what shows up when I join:
    [​IMG]
    and I have no idea why it's no longer working, just for before anyone asks, selector is an actual item, not null or anything like that and the selector slot should be 5 so it should show up in the middle of the hotbar. If anyone could help that would be great.
     
  2. Curious.. What happens if you delay the updateInventory() another 10 ticks after that? Not the whole thing, just the update. (a task in a task).

    Edit: Also a side note: I sure hope your players dont log off holding a stack of diamond blocks (or anything else important) in slot #5 of their hotbar. ;)
     
  3. Code (Java):
        @EventHandler
        public void onJoin(PlayerJoinEvent event) {
            Bukkit.broadcastMessage("Handling...");
            new BukkitRunnable() {
                @Override
                public void run() {
                    event.getPlayer().getInventory().setItem(selectorSlot - 1, selector);
                    new BukkitRunnable() {
                        @Override
                        public void run() {
                            event.getPlayer().updateInventory();
                            Bukkit.broadcastMessage("Updated...");
                        }
                    }.runTaskLater(ServerSelector.getPlugin(), 10L);
                    Bukkit.broadcastMessage("Handled...");
                }
            }.runTaskLater(ServerSelector.getPlugin(), 10L);
        }
    is this what you mean? Because nothing, and it's a hub server selector thing. They won't get anything other than the selector in slot 5.
     
  4. Yeah, thats what I meant. Hmm.

    Ok. What if instead of using event.getPlayer(), what if you used Bukkit.getPlayer() from the UUID? Like, store the UUID when the event fires and pass that to the task. My reasoning of thinking: Bungee might be doing some dark magic with the Player (no idea how it works at all), so the Player in the event might not be the correct Player object needed.. If that makes any sense. Idk. Just something to try.

    Ok, that makes sense. Just wanted to point it out in case you overlooked it ^_^
     
  5. What is selector? Show where you set it.
     
  6. I'll try it
    EDIT:
    Doesn't work, code:
    Code (Java):
        @EventHandler
        public void onJoin(PlayerJoinEvent event) {
            UUID id = event.getPlayer().getUniqueId();
            Bukkit.broadcastMessage("Handling...");
            new BukkitRunnable() {
                @Override
                public void run() {
                    Player player = Bukkit.getPlayer(id);
                    player.getInventory().setItem(selectorSlot - 1, selector);
                    player.updateInventory();
                    Bukkit.broadcastMessage("Handled...");
                }
            }.runTaskLater(ServerSelector.getPlugin(), 10L);
        }
    still nothing happens
    nice thought but as stated before it only stopped working when I switched to bungee so the selector definitely exists and there's no stacktrace in the console.
     
  7. I fixed it, stupid mistake on my part, I initialized the selector stack before making it. Lol
     
Thread Status:
Not open for further replies.