Error when I try to pick a banned IP

Discussion in 'Plugin Development' started by idkG0D, Feb 10, 2019.

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


    Well guys, i trying to make a /banip /ipban example plugin, for that, i've created a .YML file to save all banned ip's.
    The problem is, i can banip and save it normally, but when i try to pick that in a PlayerLoginEvent, he show a error in console... Someone can help-me?

    import Main.Main;
    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    public class BanIP implements CommandExecutor {
        public static String BanReason;
        public static String BanAuthor;
        public static String BannedIP;
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            Player p = (Player) sender;
            String perm = "flash.ipban";
            String cmd1 = "IPBAN";
            String cmd2 = "BANIP";
            String motivo = "";
            String Author = p.getName();
            if(cmd.getName().equalsIgnoreCase(cmd1) || cmd.getName().equalsIgnoreCase(cmd2)){
                    p.sendMessage("§cVocê não tem permissão para executar esse comando!");
                    return true;
                if(args.length == 0){
                    p.sendMessage("§3IPBAN  §cVocê precisa selecionar o jogador!");
                    return true;
                if(args.length == 1){
                    p.sendMessage("§3IPBAN  §cSeu ban precisa ter um motivo!");
                    return true;
                if(args.length > 1){
                    Player target = (Player) Bukkit.getServer().getPlayer(args[0]);
                    String ip = target.getAddress().getAddress().getHostAddress();
                    for(int i = 1; i < args.length; i++){
                        motivo = (motivo+args[i]+" ");
                    BanReason = motivo;
                    BanAuthor = Author;
                    BannedIP = ip;
                    if(target == null){
                        p.sendMessage("§3IPBAN  §cO jogador precisa estar online!");
                        return true;
                    target.kickPlayer("§f§lFLASH§cMC"+"\n"+"§cVocê foi permanentemente banido de nosso servidor!"+"\n"+"§fMotivo: §c"+motivo+"\n"+"§fAutor: §c"+Author);
                    Bukkit.broadcastMessage("§fO jogador §c"+target.getName()+" §ffoi banido por §c"+p.getName()+"§f Motivo: §c"+motivo);
                    Main.ipbancfg.set(BannedIP, "");
                    Main.ipbancfg.set(BannedIP+".MOTIVO", BanReason);
                    Main.ipbancfg.set(BannedIP+".AUTOR", BanAuthor);
                    }catch (IOException e){
                    return true;
            return false;
    Checking the ip in the YML file:

    String ip = p.getAddress().getAddress().getHostAddress();
    if(Main.ipbancfg.get(BanIP.BannedIP) == ip){
                e.disallow(PlayerLoginEvent.Result.KICK_BANNED, "§f§lFLASH§cMC"+"\n"+"§cVocê esta permanentemente banido de nosso servidor!"+"\n"+"§fMotivo: §c"+Main.ipbancfg.getString(BanIP.BannedIP+".MOTIVO")+"\n"+"§fAutor: §c"+Main.ipbancfg.getString(BanIP.BannedIP+".AUTOR"));


    [19:59:14 ERROR]: Could not pass event PlayerLoginEvent to FlashMC v1.5
    at$1.execute( ~[craftbukkit.jar:git-Bukkit-33d5de3]
    at org.bukkit.plugin.RegisteredListener.callEvent( ~[craftbukkit.jar:git-Bukkit-33d5de3]
    at org.bukkit.plugin.SimplePluginManager.fireEvent( [craftbukkit.jar:git-Bukkit-33d5de3]
    at org.bukkit.plugin.SimplePluginManager.callEvent( [craftbukkit.jar:git-Bukkit-33d5de3]
    at net.minecraft.server.v1_8_R1.PlayerList.attemptLogin( [craftbukkit.jar:git-Bukkit-33d5de3]
    at net.minecraft.server.v1_8_R1.LoginListener.b( [craftbukkit.jar:git-Bukkit-33d5de3]
    at net.minecraft.server.v1_8_R1.LoginListener.c( [craftbukkit.jar:git-Bukkit-33d5de3]
    at net.minecraft.server.v1_8_R1.NetworkManager.a( [craftbukkit.jar:git-Bukkit-33d5de3]
    at net.minecraft.server.v1_8_R1.ServerConnection.c(SourceFile:151) [craftbukkit.jar:git-Bukkit-33d5de3]
    at net.minecraft.server.v1_8_R1.MinecraftServer.z( [craftbukkit.jar:git-Bukkit-33d5de3]
    at net.minecraft.server.v1_8_R1.DedicatedServer.z( [craftbukkit.jar:git-Bukkit-33d5de3]
    at net.minecraft.server.v1_8_R1.MinecraftServer.y( [craftbukkit.jar:git-Bukkit-33d5de3]
    at [craftbukkit.jar:git-Bukkit-33d5de3]
    at Source) [?:1.8.0_201]
    Caused by: java.lang.NullPointerException
    at Eventos.CheckPlayer.checkConnection( ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_201]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_201]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_201]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_201]
    at$1.execute( ~[craftbukkit.jar:git-Bukkit-33d5de3]
    ... 13 more

    Last edited: Feb 10, 2019
  2. Offline


    @idkG0D What is the error in the console?
    EDIT: Also, to compare strings use '.equals()', not '=='.
  3. Offline


    The error is happening here:
    at Eventos.CheckPlayer.checkConnection(
    Go to the CheckPlayer class on line 25 - there is a null object there.
    Post the code on line 25.
    Mind posting the CheckPlayer class code and your Main class code?
Thread Status:
Not open for further replies.

Share This Page