Error when I try to pick a banned IP

Discussion in 'Plugin Development' started by idkG0D, Feb 10, 2019 at 9:31 AM.

  1. Offline

    idkG0D

    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?

    ipBanCommand:
    Code:
    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;
    
    import java.io.IOException;
    
    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)){
                if(!p.hasPermission(perm)){
                    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);
                    try{
                        Main.ipbancfg.save(Main.IPbanned);
                    }catch (IOException e){
                        e.printStackTrace();
                    }
                    return true;
    
    
                }
            }
    
    
    
            return false;
        }
    }
    
    Checking the ip in the YML file:

    Code:
    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"));
                return;
            }
    [EDIT]

    CONSOLE ERROR:

    [19:59:14 ERROR]: Could not pass event PlayerLoginEvent to FlashMC v1.5
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:297) ~[craftbukkit.jar:git-Bukkit-33d5de3]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-33d5de3]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit.jar:git-Bukkit-33d5de3]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-33d5de3]
    at net.minecraft.server.v1_8_R1.PlayerList.attemptLogin(PlayerList.java:409) [craftbukkit.jar:git-Bukkit-33d5de3]
    at net.minecraft.server.v1_8_R1.LoginListener.b(LoginListener.java:69) [craftbukkit.jar:git-Bukkit-33d5de3]
    at net.minecraft.server.v1_8_R1.LoginListener.c(LoginListener.java:41) [craftbukkit.jar:git-Bukkit-33d5de3]
    at net.minecraft.server.v1_8_R1.NetworkManager.a(NetworkManager.java:150) [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(MinecraftServer.java:733) [craftbukkit.jar:git-Bukkit-33d5de3]
    at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:284) [craftbukkit.jar:git-Bukkit-33d5de3]
    at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:609) [craftbukkit.jar:git-Bukkit-33d5de3]
    at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:517) [craftbukkit.jar:git-Bukkit-33d5de3]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_201]
    Caused by: java.lang.NullPointerException
    at Eventos.CheckPlayer.checkConnection(CheckPlayer.java:25) ~[?:?]
    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 org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:295) ~[craftbukkit.jar:git-Bukkit-33d5de3]
    ... 13 more

    @KarimAKL
     
    Last edited: Feb 10, 2019 at 2:07 PM
  2. Online

    KarimAKL

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

    0-o

    The error is happening here:
    at Eventos.CheckPlayer.checkConnection(CheckPlayer.java:25)
    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?
     

Share This Page