Solved Change a player's inventory

Discussion in 'Spigot Plugin Development' started by TheGamerPlayz, May 30, 2016.

Thread Status:
Not open for further replies.
  1. I am making an /invsee plugin and i can get the player's inventory, but I can't seem to make it change the other player's inventory. I tried setting its contents to the contents of the edited inventory, but nothing seems to happen anyone have any ideas?
     
  2. How are you getting/setting contents and the inventories themselves? Code?
     
  3. Code (Java):

                          Inventory inv = Bukkit.createInventory(p, InventoryType.PLAYER, "InvSee View");
                          inv.setContents(player.getInventory().getContents());
                          p.openInventory(inv);
     
    And after every click in the inventory
    Code (Java):

               Bukkit.broadcastMessage("clicked");
               Inventory inv = event.getInventory();
                Player p = (Player) event.getWhoClicked();
                Player player = Bukkit.getPlayer(data.getString("InvSee." + p.getName()));
                player.getInventory().setContents(inv.getContents());
                player.updateInventory();
     
    Edit: I just added trying with the listener and am now getting this error
    [code
    [19:11:32 ERROR]: Could not pass event InventoryClickEvent to Vanish v4.0
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:1630) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.PacketPlayInWindowClick.a(SourceFile:31) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.PacketPlayInWindowClick.a(SourceFile:9) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_73]
    at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_73]
    at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_73]
    Caused by: java.lang.NullPointerException
    at Vanish.listeners.invseeListener.onInventoryChange(invseeListener.java:29) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_73]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_73]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_73]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_73]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
    ... 15 more
    ][/code]
     
    #3 TheGamerPlayz, May 31, 2016
    Last edited: May 31, 2016
  4. you have to create a listener to the inventory close ecent and there set the inventory of the original pplayer to the new one.
     
  5. Ok let me try that

    Edit: Ok thanks it is working fine, now
     
    #5 TheGamerPlayz, May 31, 2016
    Last edited: May 31, 2016
Thread Status:
Not open for further replies.