Listener Already Listening

Discussion in 'Plugin Development' started by FlareLine, Apr 6, 2014.

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

    FlareLine

    I tried to open an inventory when a Player joined, but it produces an Internal Server Error whenever someone tries to connect:
    Code:
    [15:44:59 INFO]: UUID of player FlareLine is 6c7ec3d9036c45269de918497bb28095
    [15:44:59 INFO]: Loaded player file for FlareLine
    [15:44:59 WARN]: Failed to handle packet for /127.0.0.1:17059
    java.lang.IllegalArgumentException: Listener already listening
            at net.minecraft.server.v1_7_R2.Container.addSlotListener(Container.java
    :53) ~[craftbukkit-1.7.5-R0.1.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
            at net.minecraft.server.v1_7_R2.EntityPlayer.syncInventory(EntityPlayer.
    java:151) ~[craftbukkit-1.7.5-R0.1.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jn
    ks]
            at net.minecraft.server.v1_7_R2.PlayerList.a(PlayerList.java:132) ~[craf
    tbukkit-1.7.5-R0.1.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
            at net.minecraft.server.v1_7_R2.LoginListener.c(LoginListener.java:78) ~
    [craftbukkit-1.7.5-R0.1.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
            at net.minecraft.server.v1_7_R2.LoginListener.a(LoginListener.java:42) ~
    [craftbukkit-1.7.5-R0.1.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
            at net.minecraft.server.v1_7_R2.NetworkManager.a(NetworkManager.java:150
    ) ~[craftbukkit-1.7.5-R0.1.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
            at net.minecraft.server.v1_7_R2.ServerConnection.c(SourceFile:134) [craf
    tbukkit-1.7.5-R0.1.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
            at net.minecraft.server.v1_7_R2.MinecraftServer.v(MinecraftServer.java:6
    57) [craftbukkit-1.7.5-R0.1.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
            at net.minecraft.server.v1_7_R2.DedicatedServer.v(DedicatedServer.java:2
    50) [craftbukkit-1.7.5-R0.1.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
            at net.minecraft.server.v1_7_R2.MinecraftServer.u(MinecraftServer.java:5
    48) [craftbukkit-1.7.5-R0.1.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
            at net.minecraft.server.v1_7_R2.MinecraftServer.run(MinecraftServer.java
    :459) [craftbukkit-1.7.5-R0.1.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
            at net.minecraft.server.v1_7_R2.ThreadServerApplication.run(SourceFile:6
    18) [craftbukkit-1.7.5-R0.1.jar:git-Bukkit-1.7.2-R0.3-10-gcf5a547-b3035jnks]
    [15:45:00 INFO]: FlareLine lost connection: Internal server error
    [15:45:00 INFO]: Removing player from memory: FlareLine
    [15:45:00 INFO]: FlareLine left the game.
    I'm not sure what is wrong, as I've done this plenty of times before.
     
  2. Offline

    RawCode

    how random people from forum expected to help you without any code posted?

    well i can guess - this is lupus, but it wont help you.
     
  3. Offline

    FlareLine

    RawCode There's really no need to be rude. If you require code to help me find a solution then ask for it, don't just ramble on about how you can't fix it.
     
  4. Offline

    Wolfey

    FlareLine How about posting your listener?
     
  5. Offline

    BillyGalbreath

    No code, no help.
     
  6. Offline

    Shevchik

    You have somehow registered you listener twice.
     
  7. Offline

    RawCode

    I have asked you to provide code already, you will have issues IRL if can't understand so obvious sarcasm.
     
  8. Offline

    FlareLine

    This is the entire listener class
    Show Spoiler
    Code:java
    1. package me.genki.ms.team;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.DyeColor;
    6. import org.bukkit.Material;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.player.PlayerJoinEvent;
    11. import org.bukkit.inventory.Inventory;
    12. import org.bukkit.inventory.ItemStack;
    13. import org.bukkit.inventory.meta.ItemMeta;
    14.  
    15. @SuppressWarnings("deprecation")
    16. public class OpenGUI implements Listener {
    17.  
    18. public ItemStack REDWOOL = new ItemStack(Material.WOOL, 1, DyeColor.RED.getData());
    19. public ItemStack GREENWOOL = new ItemStack(Material.WOOL, 1, DyeColor.GREEN.getData());
    20. public ItemStack BLUEWOOL = new ItemStack(Material.WOOL, 1, DyeColor.CYAN.getData());
    21.  
    22. @EventHandler
    23. public void onPlayerJoin(PlayerJoinEvent ev){
    24. try {
    25. Player p = ev.getPlayer();
    26.  
    27. Inventory i = Bukkit.getServer().createInventory(null, 36, ChatColor.GOLD + "Choos a Faction");
    28.  
    29. ItemMeta RM = REDWOOL.getItemMeta();
    30. RM.setDisplayName(ChatColor.RED + "Red Team");
    31. REDWOOL.setItemMeta(RM);
    32. ItemMeta GM = GREENWOOL.getItemMeta();
    33. GM.setDisplayName(ChatColor.GREEN + "Green Team");
    34. GREENWOOL.setItemMeta(GM);
    35. ItemMeta BM = BLUEWOOL.getItemMeta();
    36. BM.setDisplayName(ChatColor.BLUE + "Blue Team");
    37. BLUEWOOL.setItemMeta(BM);
    38.  
    39. i.setItem(10, REDWOOL);
    40. i.setItem(13, GREENWOOL);
    41. i.setItem(16, BLUEWOOL);
    42.  
    43. p.openInventory(i);
    44.  
    45. } catch (Exception e){
    46. e.printStackTrace();
    47. }
    48. }
    49. }
    50.  
     
  9. Offline

    Maurdekye

    FlareLine Show your main class; i'm sure there won't be much in your listener class.
     
  10. Offline

    FlareLine

    Maurdekye All that is related to ShowGUI:
    Code:java
    1. package me.genki.ms;
    2.  
    3. import me.genki.ms.team.Armour;
    4. import me.genki.ms.team.GameHandler;
    5. import me.genki.ms.team.OpenGUI;
    6.  
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.command.Command;
    9. import org.bukkit.command.CommandSender;
    10. import org.bukkit.configuration.file.FileConfiguration;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.plugin.PluginManager;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14.  
    15. public class MineSide extends JavaPlugin {
    16.  
    17. public GameHandler gh = new GameHandler();
    18. public Armour am = new Armour();
    19. public PluginManager pm = getServer().getPluginManager();
    20. public FileConfiguration config;
    21. public OpenGUI gui = new OpenGUI(); // Related Instance
    22.  
    23. public void onEnable() {
    24.  
    25. pm.registerEvents(gui, this); // Related Register Events
    26. am.addItems();
    27. saveDefaultConfig();
    28. }
    29.  
    30. public void onDisable() {
    31.  
    32. }
    33. }
    34.  

    Please excuse the messy formatting.

    Update:

    I just found out that I can join the server fine, and the GUI pops up. However, after about half a second, I get kicked because of this "Internal Server Error".
     
  11. Offline

    RawCode

    not going to spoonfeed you, add some debug output atleast.

    this is little spoiler about source of issue.
    Code:
        public void addSlotListener(ICrafting icrafting) {
            if (this.listeners.contains(icrafting)) {
                throw new IllegalArgumentException("Listener already listening");
            } else {
                this.listeners.add(icrafting);
                icrafting.a(this, this.a());
                this.b();
            }
        }
    
     
  12. Offline

    FlareLine

    RawCode I figure that this is called whenever I register a Listener. Therefore, I'm thinking that somehow I have two instances of OpenGUI appearing somewhere in my code.
    That is correct right?
     
  13. Offline

    Rocoty

    No that is not the issue, but it would seem like it. I have had this one before and it's somewhat tricky to understand. It is not complaining about YOUR listener, but rather an internal one which you do not need to worry about. This error occurs when you try to open an inventory on a player who hasn't fully joined yet. Adding a delay before opening the inv should do it
     
  14. Offline

    FlareLine

    Rocoty This doesn't seem to be the case though, as the inventory is loaded on screen after I've joined before the server kicks me.
     
  15. Offline

    Rocoty

  16. Offline

    FlareLine

    Rocoty I'll get back to you with the results ;)

    Edit: That's got it, however I might try to do it another way completely removing the need to open an inventory when the play joins, as I need it to come up immediately after the player has loaded and before they can do anything - in a broader term, forcing them to use the GUI as soon as they join.
    Cheers :)
     
  17. Offline

    Maurdekye

    FlareLine The reason it was failing is because the event is called before the player actually joins, so the server breaks. That's why the delay works.
     
  18. Offline

    FlareLine

    Maurdekye Is there a reason it was working and then I got an error?
     
  19. Offline

    Maurdekye

    FlareLine Possibly because the client had loaded up, but the event was called just before the server was completely ready with the player. So it showed for just a half second on the client before the server realized that it couldn't show you any kind of serverside information. All just speculation, though.
     
  20. Offline

    FlareLine

  21. Offline

    Rocoty

    FlareLine Maurdekye Yeah. Basically we don't know...and everyone is too lazy to check through tons of NMS/Craftbukkit source to find out why it happens. Just know that it happens and what to do to prevent it. A delay of one tick is enough I think. If not, maybe two.
     
  22. Offline

    MOMOTHEREAL

    Try doing a small Delayed Task after the PlayerJoinEvent, and then showing up the GUI.
    Edit: Ninja'd :(
     
  23. Offline

    FlareLine

    Rocoty Ah just a couple of ticks, I was thinking like 1 or 2 seconds but I'll go and change that. ;)

    MOMOTHEREAL I kinda figured that from previous posts, but thanks for your help.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  24. Offline

    Maurdekye

    FlareLine 1 tick should be more than enough in all situations. It's not like a variable delay; the event is just a method called alongside the code when a player joins the game.
     
  25. Offline

    FlareLine

    Maurdekye I see, it's just more than one method conflicting.
     
  26. Offline

    Rocoty

    Maurdekye Unless of course the event is async...then you're in trouble.
     
Thread Status:
Not open for further replies.

Share This Page