Hi. I'm trying to make an inventory which opens when player joins a server, but i get an internal error instead. Code: Code:java public void onPlayerJoinEvent(PlayerJoinEvent e) {Player p = e.getPlayer();if (p.getGameMode() != GameMode.CREATIVE) {Inventory chooseSever = Bukkit.createInventory(p, 27, "Choose your server"); ItemStack server1book = new ItemStack(Material.BOOK, 1);List<String> ls = new ArrayList<String>();ls.set(0,"§bthem Info will come here");chooseClass.setItem(2, setName(server1book, "§aserver1", ls)); ItemStack server2book = new ItemStack(Material.BOOK, 1);ls.set(0,"§bthem Info will come here");chooseClass.setItem(3, setName(server2book, "§aserver2", ls)); ItemStack server3book = new ItemStack(Material.BOOK, 1);ls.set(0,"§bthem Info will come here");chooseClass.setItem(4, setName(server3book, "§aserver3", ls)); ItemStack server4book = new ItemStack(Material.BOOK, 1);ls.set(0,"§bthem Info will come here");chooseClass.setItem(6, setName(server4book, "§aserver4", ls)); p.openInventory(chooseServer); }} any help appreciated.
spurkle Error log? edit: From what I see you define the Inventory "choosesever" (sic!) and then try to add items to "chooseclass". Maybe you got a mixup there?
spurkle fireblast709 If that were the case, we'd have the bukkit PluginManager somewhere in the stacktrace. No, I think the problem is that the PlayerJoinEvent is called before the player actually is on the server. So you cant open an inventory for him right away. Try scheduling a task to be executed after a few seconds to open the inventory. If my theory is correct, that should work.
spurkle I was too fast with my conclusions. It probably tries to open the inventory twice, once in your join listener and once through NMS (since it thinks your inventory is the one it needs to send as the player inventory, or at least that's my current guess) Try scheduling a delayed task for the inventory open
I am not very familiar with schedulers, could you please correct me if i am doing something wrong? Because it seems that i am doing this in a wrong was, cause the inventory wont even show up. Code:java getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {@Overridepublic void run() {p.openInventory(chooseClass);}}, 20L);
spurkle That should do it, if I'm not overlooking something. Be sure that p and chooseClass are both declared as final, so you can safely use them in your anonymous class.
Code:java final Player p = e.getPlayer();if (p.getGameMode() != GameMode.CREATIVE) {final Inventory chooseClass = Bukkit.createInventory(p, 27, "Choose your server"); Seems like. But the inventory wont show up.
I can connect to the server, but i have just noticed the error in console. Code: org.bukkit.event.EventException at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja va:427) ~[craftbukkit174b.jar:git-Bukkit-1.7.2-R0.2-b2974jnks] at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav a:62) ~[craftbukkit174b.jar:git-Bukkit-1.7.2-R0.2-b2974jnks] at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j ava:481) [craftbukkit174b.jar:git-Bukkit-1.7.2-R0.2-b2974jnks] at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j ava:466) [craftbukkit174b.jar:git-Bukkit-1.7.2-R0.2-b2974jnks] at net.minecraft.server.v1_7_R1.PlayerList.c(PlayerList.java:225) [craft bukkit174b.jar:git-Bukkit-1.7.2-R0.2-b2974jnks] at net.minecraft.server.v1_7_R1.PlayerList.a(PlayerList.java:116) [craft bukkit174b.jar:git-Bukkit-1.7.2-R0.2-b2974jnks] at net.minecraft.server.v1_7_R1.LoginListener.c(LoginListener.java:78) [ craftbukkit174b.jar:git-Bukkit-1.7.2-R0.2-b2974jnks] at net.minecraft.server.v1_7_R1.LoginListener.a(LoginListener.java:42) [ craftbukkit174b.jar:git-Bukkit-1.7.2-R0.2-b2974jnks] at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:149 ) [craftbukkit174b.jar:git-Bukkit-1.7.2-R0.2-b2974jnks] at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craf tbukkit174b.jar:git-Bukkit-1.7.2-R0.2-b2974jnks] at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:6 55) [craftbukkit174b.jar:git-Bukkit-1.7.2-R0.2-b2974jnks] at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:2 50) [craftbukkit174b.jar:git-Bukkit-1.7.2-R0.2-b2974jnks] at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:5 45) [craftbukkit174b.jar:git-Bukkit-1.7.2-R0.2-b2974jnks] at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java :457) [craftbukkit174b.jar:git-Bukkit-1.7.2-R0.2-b2974jnks] at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:6 17) [craftbukkit174b.jar:git-Bukkit-1.7.2-R0.2-b2974jnks] Caused by: java.lang.IllegalArgumentException: Plugin cannot be null at org.apache.commons.lang.Validate.notNull(Validate.java:203) ~[craftbu kkit174b.jar:git-Bukkit-1.7.2-R0.2-b2974jnks] at org.bukkit.craftbukkit.v1_7_R1.scheduler.CraftScheduler.validate(Craf tScheduler.java:391) ~[craftbukkit174b.jar:git-Bukkit-1.7.2-R0.2-b2974jnks] at org.bukkit.craftbukkit.v1_7_R1.scheduler.CraftScheduler.runTaskTimer( CraftScheduler.java:120) ~[craftbukkit174b.jar:git-Bukkit-1.7.2-R0.2-b2974jnks] at org.bukkit.craftbukkit.v1_7_R1.scheduler.CraftScheduler.scheduleSyncR epeatingTask(CraftScheduler.java:116) ~[craftbukkit174b.jar:git-Bukkit-1.7.2-R0. 2-b2974jnks] at org.bukkit.craftbukkit.v1_7_R1.scheduler.CraftScheduler.scheduleSyncD elayedTask(CraftScheduler.java:100) ~[craftbukkit174b.jar:git-Bukkit-1.7.2-R0.2- b2974jnks] at me.plugin.Essentials.Essentials.onPlayerJoinEvent(Essentials.java:28 9) ~[?:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0 _60] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0 _60] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1 .7.0_60] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_60] at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja va:425) ~[craftbukkit174b.jar:git-Bukkit-1.7.2-R0.2-b2974jnks] ... 14 more
Ohh! Right. Stupid me, haha ;3 Okay, it works now. Thank you for your help Code if someone might need it: Code:java getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() { @Override public void run() { p.openInventory(chooseClass); } }, 20);