Solved PlayerJoinEvent return Errors

Discussion in 'Plugin Help/Development/Requests' started by ChocoCraft, Jan 14, 2015.

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

    ChocoCraft

    Hello,
    Actually, I'm making a Lobby plugin, with some things such as Hats, Trails...
    But, when a Player Join the server, an error occured with a PlayerJoinEvent.
    This is my event:
    Code:
    public void joinEvent(PlayerJoinEvent e) {
            boolean info = new GetInfo().messageJoin(e.getPlayer());
            if(info == true) {
                e.setJoinMessage(ChatColor.AQUA + " > " + ChatColor.DARK_AQUA + ChatColor.BOLD +e.getPlayer().getDisplayName() + ChatColor.AQUA + " a rejoint le serveur");
            }
            else {
                e.setJoinMessage(null);
            }
    }
    And this is the GetInfo class, with the messageJoin:
    Code:
    package me.chococraft74.lobby.Group;
    
    
    import me.chococraft74.lobby.*;
    import me.chococraft74.lobby.Perm.BDD;
    import me.chococraft74.lobby.mysql.MySQL;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    
    public class GetInfo extends JavaPlugin {
        FileConfiguration config = this.getConfig();
        String host = config.getString("bdd.host");
        String db = config.getString("bdd.db");
        String user = config.getString("bdd.user");
        String pass = config.getString("bdd.pass");
        me.chococraft74.lobby.mysql.MySQL MySQL = new MySQL(this, host, "3306", db, user, pass);
        Connection c = null;
    
        public void Launch() {
            try {
                c = MySQL.openConnection();
            } catch (SQLException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        }
    
        public boolean messageJoin(Player player) {
            Launch();
            try {
                Statement statement = c.createStatement();
                ResultSet res = statement.executeQuery("SELECT * FROM `users` WHERE `uuid` = '" + player.getName() + "';");
                if (res.next()) {
                    player.sendMessage(ChatColor.DARK_RED + "Info Handled");
                    return true;
                } else {
                    return false;
                }
            } catch (SQLException e) {
                player.sendMessage(ChatColor.DARK_GRAY + "Join Problem");
                return false;
            }
        }
    }
    There is the error that it was Show on Console:
    Error (Clique) (open)
    Code:
    [18:21:15] [Server thread/ERROR]: Could not pass event PlayerJoinEvent to lobby v0.1
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[spigot.jar:git-Spigot-52c130f-89944c0]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-52c130f-89944c0]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-52c130f-89944c0]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-52c130f-89944c0]
        at net.minecraft.server.v1_8_R1.PlayerList.onPlayerJoin(PlayerList.java:263) [spigot.jar:git-Spigot-52c130f-89944c0]
        at net.minecraft.server.v1_8_R1.PlayerList.a(PlayerList.java:148) [spigot.jar:git-Spigot-52c130f-89944c0]
        at net.minecraft.server.v1_8_R1.LoginListener.b(LoginListener.java:109) [spigot.jar:git-Spigot-52c130f-89944c0]
        at net.minecraft.server.v1_8_R1.LoginListener.c(LoginListener.java:41) [spigot.jar:git-Spigot-52c130f-89944c0]
        at net.minecraft.server.v1_8_R1.NetworkManager.a(NetworkManager.java:159) [spigot.jar:git-Spigot-52c130f-89944c0]
        at net.minecraft.server.v1_8_R1.ServerConnection.c(ServerConnection.java:82) [spigot.jar:git-Spigot-52c130f-89944c0]
        at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:785) [spigot.jar:git-Spigot-52c130f-89944c0]
        at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:316) [spigot.jar:git-Spigot-52c130f-89944c0]
        at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:623) [spigot.jar:git-Spigot-52c130f-89944c0]
        at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:526) [spigot.jar:git-Spigot-52c130f-89944c0]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0]
    Caused by: java.lang.IllegalArgumentException: Plugin already initialized!
        at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:122) ~[spigot.jar:git-Spigot-52c130f-89944c0]
        at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[spigot.jar:git-Spigot-52c130f-89944c0]
        at me.chococraft74.lobby.Group.GetInfo.<init>(GetInfo.java:20) ~[?:?]
        at me.chococraft74.lobby.Lobby.joinEvent(Lobby.java:84) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[spigot.jar:git-Spigot-52c130f-89944c0]
        ... 14 more
    Caused by: java.lang.IllegalStateException: Initial initialization
        at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:125) ~[spigot.jar:git-Spigot-52c130f-89944c0]
        at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[spigot.jar:git-Spigot-52c130f-89944c0]
        at me.chococraft74.lobby.Lobby.<init>(Lobby.java:34) ~[?:?]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0]
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0]
        at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0]
        at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0]
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) ~[spigot.jar:git-Spigot-52c130f-89944c0]
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131) ~[spigot.jar:git-Spigot-52c130f-89944c0]
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:329) ~[spigot.jar:git-Spigot-52c130f-89944c0]
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) ~[spigot.jar:git-Spigot-52c130f-89944c0]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugins(CraftServer.java:290) ~[spigot.jar:git-Spigot-52c130f-89944c0]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.reload(CraftServer.java:742) ~[spigot.jar:git-Spigot-52c130f-89944c0]
        at org.bukkit.Bukkit.reload(Bukkit.java:534) ~[spigot.jar:git-Spigot-52c130f-89944c0]
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:23) ~[spigot.jar:git-Spigot-52c130f-89944c0]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot.jar:git-Spigot-52c130f-89944c0]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServer.java:645) ~[spigot.jar:git-Spigot-52c130f-89944c0]
        at net.minecraft.server.v1_8_R1.PlayerConnection.handleCommand(PlayerConnection.java:1115) ~[spigot.jar:git-Spigot-52c130f-89944c0]
        at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java:950) ~[spigot.jar:git-Spigot-52c130f-89944c0]
        at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java:26) ~[spigot.jar:git-Spigot-52c130f-89944c0]
        at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java:53) ~[spigot.jar:git-Spigot-52c130f-89944c0]
        at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) ~[spigot.jar:git-Spigot-52c130f-89944c0]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0]
        at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0]
        at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:683) ~[spigot.jar:git-Spigot-52c130f-89944c0]
        ... 4 more
    [18:21:15] [Server thread/INFO]: ChocoCraft74[/25.163.104.246:54328] logged in with entity id 513 at ([world] 4.118655398866336, 135.78502770378924, -1.916585947927032)
    



    Please, could you help me to solve this problem ?
    Thanks,
    Choco'
     
  2. Offline

    sirrus86

    Unless GetInfo is the plugin's main class I don't think it should be extending JavaPlugin. That's my first guess.
     
  3. Offline

    ColonelHedgehog

    This.

    Only your Main class should extend the JavaPlugin class.
     
  4. Offline

    BurnerDiamond

    Code:
    @EventHandler
    public void joinEvent(PlayerJoinEvent e) {
            boolean info = new GetInfo().messageJoin(e.getPlayer());
            if(info == true) {
                e.setJoinMessage(ChatColor.AQUA + " > " + ChatColor.DARK_AQUA + ChatColor.BOLD +e.getPlayer().getDisplayName() + ChatColor.AQUA + " a rejoint le serveur");
            }
            else {
                e.setJoinMessage(null);
            }
    }
    Could we have the whole code please?

    I think you may be missing the @EventHandler
     
  5. Offline

    mine-care

    As said above
    Caused by: java.lang.IllegalStateException: Initial initialization
    D not instance ate main class, abd as a tip: use constructors to pass things from class to class (static is not the solution)
    Also I am not the best in JDB but I'm unsure of how efficient it is to use databases here :/
     
  6. Code:java
    1.  
    2. //Instead of using
    3. if(boolean == true) {}
    4. //Use this
    5. if(boolean) {} //To check if the boolean is true
    6. if(!boolean) {} //To check if the boolean is false
    7.  
     
  7. Offline

    ChocoCraft

    Thanks. Problem Solved, it was about JavaPlugin Extends another time.
    Sorry :p
     
  8. Offline

    BurnerDiamond

  9. Offline

    ChocoCraft

    I'd forgotten. Change right now
     
Thread Status:
Not open for further replies.

Share This Page