Internal Error

Discussion in 'Plugin Development' started by spurkle, Jul 21, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    spurkle

    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
    1. public void onPlayerJoinEvent(PlayerJoinEvent e) {
    2. Player p = e.getPlayer();
    3. if (p.getGameMode() != GameMode.CREATIVE) {
    4. Inventory chooseSever = Bukkit.createInventory(p, 27, "Choose your server");
    5.  
    6. ItemStack server1book = new ItemStack(Material.BOOK, 1);
    7. List<String> ls = new ArrayList<String>();
    8. ls.set(0,"§bthem Info will come here");
    9. chooseClass.setItem(2, setName(server1book, "§aserver1", ls));
    10.  
    11. ItemStack server2book = new ItemStack(Material.BOOK, 1);
    12. ls.set(0,"§bthem Info will come here");
    13. chooseClass.setItem(3, setName(server2book, "§aserver2", ls));
    14.  
    15. ItemStack server3book = new ItemStack(Material.BOOK, 1);
    16. ls.set(0,"§bthem Info will come here");
    17. chooseClass.setItem(4, setName(server3book, "§aserver3", ls));
    18.  
    19. ItemStack server4book = new ItemStack(Material.BOOK, 1);
    20. ls.set(0,"§bthem Info will come here");
    21. chooseClass.setItem(6, setName(server4book, "§aserver4", ls));
    22.  
    23. p.openInventory(chooseServer);
    24.  
    25. }
    26. }

    any help appreciated.
     
  2. Offline

    Saladoc

    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?
     
  3. Offline

    spurkle


     
  4. Offline

    fireblast709

    spurkle you are registering your Listener twice
     
  5. Offline

    spurkle

    Um... I am not.

    Btw: If i comment out 'p.openInventory(chooseClass);' i can join the server.
     
  6. Offline

    Saladoc

    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.
     
  7. Offline

    fireblast709

    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
     
    Saladoc likes this.
  8. Offline

    spurkle

    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
    1. getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    2. @Override
    3. public void run() {
    4. p.openInventory(chooseClass);
    5. }
    6. }, 20L);
     
  9. Offline

    Saladoc

    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.
     
  10. Offline

    fireblast709

    spurkle should be fine. If you didn't already, make the inventory and p final.
     
  11. Offline

    spurkle


    Code:java
    1. final Player p = e.getPlayer();
    2. if (p.getGameMode() != GameMode.CREATIVE) {
    3. final Inventory chooseClass = Bukkit.createInventory(p, 27, "Choose your server");

    Seems like. But the inventory wont show up.
     
  12. Offline

    Saladoc

    spurkle No error messages this time? You can connect to the server?
     
  13. Offline

    spurkle

    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
     
  14. Offline

    Saladoc

    spurkle


    The "plugin" variable you pass to scheduleSyncDelayedTask is null
     
  15. Offline

    spurkle

    Ohh! Right. Stupid me, haha ;3

    Okay, it works now. Thank you for your help

    Code if someone might need it:
    Code:java
    1. getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    2. @Override
    3. public void run() {
    4. p.openInventory(chooseClass);
    5. }
    6. }, 20);
     
  16. Offline

    Saladoc

    spurkle
    Glad to help. If your Problem as fixed, please mark the thread as solved.
     
  17. Offline

    spurkle

    How do i do that? I can't seem to find it.
     
  18. Offline

    Saladoc

    spurkle Don't know. Never did that xD Today is my first day posting here.
     
Thread Status:
Not open for further replies.

Share This Page