1.12.2 Could not pass event PlayerJoinEvent

Discussion in 'Spigot Plugin Development' started by EpicPro, Apr 20, 2020.

  1. Hello, I received an error in my server console. Please help me and tell me how to fix it. For example, give me exactly where the error is and show me how to fix it.
    Here is the code of main class:

    Code (Java):
    package tk.gevrecigaming.gevrecisecurity;

    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;

    public class GevreciSecurity extends JavaPlugin implements Listener {
        boolean isLogged = false;
        FileConfiguration config = this.getConfig();

        public void onEnable() {
            config.addDefault("password", "GEVRECIGAMING2020");
            config.options().copyDefaults(true);
            saveConfig();
            getServer().getPluginManager().registerEvents(this, this);
        }
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event) {
            Player player = event.getPlayer();
            player.teleport(new Location(Bukkit.getWorld("world"), 175, 253, 254));
            double playerx = player.getLocation().getX();
            double playery = player.getLocation().getY();
            double playerz = player.getLocation().getZ();
            while (!isLogged) {
                player.sendMessage("Use /login <password>");
                this.getCommand("login").setExecutor(new Login());
            }
            player.teleport(new Location(Bukkit.getWorld("world"), playerx, playery, playerz));
        }

    }
     
    Here is the code of Login class:
    Code (Java):
    package tk.gevrecigaming.gevrecisecurity;

    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;

    public class Login implements CommandExecutor {
        GevreciSecurity mainClass = new GevreciSecurity();
        @Override
        public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
            Player player = (Player) sender;
            if (args.length == 0) {
                player.sendMessage("Pls enter pass");
            }
            if (args.length == 1) {
                if (args[0].equals(mainClass.config.getString("password"))) {
                    mainClass.isLogged = true;
                } else {
                    player.sendMessage("Invalid password!!");
                }
            }

            return true;
        }
    }
     
     
  2. There is the output from console:
    Code (Text):
    Could not pass event PlayerJoinEvent to GevreciSecurity v1.0
    org.bukkit.event.EventException: null
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-79a30d7-acbc348]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-79a30d7-acbc348]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:500) [spigot.jar:git-Spigot-79a30d7-acbc348]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:485) [spigot.jar:git-Spigot-79a30d7-acbc348]
            at net.minecraft.server.v1_12_R1.PlayerList.onPlayerJoin(PlayerList.java:346) [spigot.jar:git-Spigot-79a30d7-acbc348]
            at net.minecraft.server.v1_12_R1.PlayerList.a(PlayerList.java:166) [spigot.jar:git-Spigot-79a30d7-acbc348]
            at net.minecraft.server.v1_12_R1.LoginListener.b(LoginListener.java:159) [spigot.jar:git-Spigot-79a30d7-acbc348]
            at net.minecraft.server.v1_12_R1.LoginListener.e(LoginListener.java:57) [spigot.jar:git-Spigot-79a30d7-acbc348]
            at net.minecraft.server.v1_12_R1.NetworkManager.a(NetworkManager.java:233) [spigot.jar:git-Spigot-79a30d7-acbc348]
            at net.minecraft.server.v1_12_R1.ServerConnection.c(ServerConnection.java:140) [spigot.jar:git-Spigot-79a30d7-acbc348]
            at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:845) [spigot.jar:git-Spigot-79a30d7-acbc348]
            at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:406) [spigot.jar:git-Spigot-79a30d7-acbc348]
            at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679) [spigot.jar:git-Spigot-79a30d7-acbc348]
            at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577) [spigot.jar:git-Spigot-79a30d7-acbc348]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_231]
    Caused by: java.lang.IllegalArgumentException: Plugin already initialized!
            at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:183) ~[spigot.jar:git-Spigot-79a30d7-acbc348]
            at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:60) ~[spigot.jar:git-Spigot-79a30d7-acbc348]
            at tk.gevrecigaming.gevrecisecurity.GevreciSecurity.<init>(GevreciSecurity.java:15) ~[?:?]
            at tk.gevrecigaming.gevrecisecurity.Login.<init>(Login.java:9) ~[?:?]
            at tk.gevrecigaming.gevrecisecurity.GevreciSecurity.onPlayerJoin(GevreciSecurity.java:34) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_231]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_231]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_231]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_231]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot.jar:git-Spigot-79a30d7-acbc348]
            ... 14 more
    Caused by: java.lang.IllegalStateException: Initial initialization
            at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:186) ~[spigot.jar:git-Spigot-79a30d7-acbc348]
            at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:60) ~[spigot.jar:git-Spigot-79a30d7-acbc348]
            at tk.gevrecigaming.gevrecisecurity.GevreciSecurity.<init>(GevreciSecurity.java:15) ~[?:?]
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_231]
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_231]
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_231]
            at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_231]
            at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_231]
            at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:90) ~[spigot.jar:git-Spigot-79a30d7-acbc348]
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:129) ~[spigot.jar:git-Spigot-79a30d7-acbc348]
            at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:327) ~[spigot.jar:git-Spigot-79a30d7-acbc348]
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:248) ~[spigot.jar:git-Spigot-79a30d7-acbc348]
            at org.bukkit.craftbukkit.v1_12_R1.CraftServer.loadPlugins(CraftServer.java:305) ~[spigot.jar:git-Spigot-79a30d7-acbc348]
            at net.minecraft.server.v1_12_R1.DedicatedServer.init(DedicatedServer.java:205) ~[spigot.jar:git-Spigot-79a30d7-acbc348]
            at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:545) ~[spigot.jar:git-Spigot-79a30d7-acbc348]
            ... 1 more
     
  3. SteelPhoenix

    Moderator

    You can only have one instance of your main class
    and
    Code (Java):
    while (!isLogged) {
        player.sendMessage("Use /login <password>");
        this.getCommand("login").setExecutor(new Login());
    }
    does not make any sense.