When a player joins my server, the plugin should onduct a check to see if their ip is banned or if they have used up the max number of accounts per ip. I am being given a nullpounterexception on this line: Code: File file = new File("plugins//MasCore//IP//" + e.getPlayer().getAddress().getAddress() + ".yml") That line makes the file variable with the players'd ip address. I am also having an issue with displaying a player's ip. I have been using .getAddress().getHostName(), but it displays some other stuff about the users ISP Could someone tell me how to fix this? EDIT: Full stacktrace: Code: [12:01:59 ERROR]: Could not pass event PlayerLoginEvent to MasCore v1.0.0 org.bukkit.event.EventException at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[craftbukkit.jar:git-Bukkit-18fbb24] at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-18fbb24] at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit.jar:git-Bukkit-18fbb24] at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-18fbb24] at net.minecraft.server.v1_8_R3.PlayerList.attemptLogin(PlayerList.java:439) [craftbukkit.jar:git-Bukkit-18fbb24] at net.minecraft.server.v1_8_R3.LoginListener.b(LoginListener.java:89) [craftbukkit.jar:git-Bukkit-18fbb24] at net.minecraft.server.v1_8_R3.LoginListener.c(LoginListener.java:53) [craftbukkit.jar:git-Bukkit-18fbb24] at net.minecraft.server.v1_8_R3.NetworkManager.a(NetworkManager.java:222) [craftbukkit.jar:git-Bukkit-18fbb24] at net.minecraft.server.v1_8_R3.ServerConnection.c(SourceFile:168) [craftbukkit.jar:git-Bukkit-18fbb24] at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:745) [craftbukkit.jar:git-Bukkit-18fbb24] at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:335) [craftbukkit.jar:git-Bukkit-18fbb24] at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:629) [craftbukkit.jar:git-Bukkit-18fbb24] at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:537) [craftbukkit.jar:git-Bukkit-18fbb24] at java.lang.Thread.run(Unknown Source) [?:1.7.0_79] Caused by: java.lang.NullPointerException at me.mas.core.IPManager.IPLimiter.onJoin(IPLimiter.java:17) ~[?:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_79] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_79] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_79] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_79] at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:300) ~[craftbukkit.jar:git-Bukkit-18fbb24] ... 13 more
@ItsMas_ Don't hard code your File locations like that. Get the plugin's data folder and create File objects using this constructor. https://docs.oracle.com/javase/7/docs/api/java/io/File.html#File(java.io.File,%20java.lang.String) If the NPE is happening on that line then it's not a problem with your File object. Find out what's null on the line and you can prevent the NPE from happening.
The null is to do with getting the player's ip. I am using this method: Code: public static String getPlayerIp(Player player){ return player.getAddress().toString().substring(1).split(":")[0]; } When using that method to display the user's ip in a chat message, it works fine, however when including it in a file object, it returns null. Line that gives error: Code: File file = new File("plugins//MasCore//IP//" + getPlayerIp(e.getPlayer()) + ".yml"); I really can't figure out why ^_^
@ItsMas_ Isn't the / a path separator? So your directory would be "plugins"/null/"MasCore"/null/"IP"/null/"{IP}.yml", why aren't you using Plugin#getDataFolder() to get the folder? And why're you hard coding "/" rather than using File.separator? Try fixing your file path and seeing it if fixes the error.
Okay, I will try changing it to the things you said. I have done it my current way many times before in this same project and it has worked though ^-^ @Xerox262 New code: Code: file = new File(plugin.getDataFolder() + file.separator + "IP" + file.separator + getPlayerIp(e.getPlayer()) + ".yml"); This time the error is on this line: Code: return player.getAddress().toString().substring(1).split(":")[0];
@ItsMas_ And what is the error? Is it still null pointer? Also, why're you using split rather than just modifying your substring?
@ItsMas_ No, the actual error, you said Which I assume means different from the one in the original post. So what is the exception? Is it still a null pointer? Can you post the new stack trace
New stacktrace: Code: [16:45:38 ERROR]: Could not pass event PlayerLoginEvent to MasCore v1.0.0 org.bukkit.event.EventException at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[craftbukkit.jar:git-Bukkit-18fbb24] at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-18fbb24] at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit.jar:git-Bukkit-18fbb24] at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-18fbb24] at net.minecraft.server.v1_8_R3.PlayerList.attemptLogin(PlayerList.java:439) [craftbukkit.jar:git-Bukkit-18fbb24] at net.minecraft.server.v1_8_R3.LoginListener.b(LoginListener.java:89) [craftbukkit.jar:git-Bukkit-18fbb24] at net.minecraft.server.v1_8_R3.LoginListener.c(LoginListener.java:53) [craftbukkit.jar:git-Bukkit-18fbb24] at net.minecraft.server.v1_8_R3.NetworkManager.a(NetworkManager.java:222) [craftbukkit.jar:git-Bukkit-18fbb24] at net.minecraft.server.v1_8_R3.ServerConnection.c(SourceFile:168) [craftbukkit.jar:git-Bukkit-18fbb24] at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:745) [craftbukkit.jar:git-Bukkit-18fbb24] at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:335) [craftbukkit.jar:git-Bukkit-18fbb24] at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:629) [craftbukkit.jar:git-Bukkit-18fbb24] at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:537) [craftbukkit.jar:git-Bukkit-18fbb24] at java.lang.Thread.run(Unknown Source) [?:1.7.0_79] Caused by: java.lang.NullPointerException at me.mas.core.IPManager.IPLimiter.getPlayerIp(IPLimiter.java:24) ~[?:?] at me.mas.core.IPManager.IPLimiter.onJoin(IPLimiter.java:31) ~[?:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_79] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_79] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_79] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_79] at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:300) ~[craftbukkit.jar:git-Bukkit-18fbb24] ... 13 more
@ItsMas_ The only thing I can think is to split it up across multiple lines so you know what part is null.