Code: Code: @EventHandler(priority=EventPriority.HIGHEST) public void onLogin(PlayerLoginEvent event) throws MalformedURLException, IOException { Player p = event.getPlayer(); if (Main.c.getBoolean("CHECKPROXY") == Boolean.valueOf(true).booleanValue()) { try { String url = "http://botscout.com/test/?ip=" + event.getAddress().getHostAddress(); @SuppressWarnings("resource") Scanner scanner = new Scanner(new URL(url).openStream()); if (scanner.findInLine("N") != null) { event.allow(); event.setResult(PlayerLoginEvent.Result.ALLOWED); p.setWhitelisted(true); } } catch (MalformedURLException localMalformedURLException) {}catch (IOException LocalIOException) {} }else{ try { String url = "http://botscout.com/test/?ip=" + event.getAddress().getHostAddress(); Scanner scanner = new Scanner(new URL(url).openStream()); if (scanner.findInLine("Y") != null) { event.setResult(PlayerLoginEvent.Result.KICK_OTHER); event.disallow(PlayerLoginEvent.Result.KICK_OTHER, ChatColor.RED + "You are using a proxy!"); p.setWhitelisted(false); } scanner.close(); } catch (MalformedURLException localMalformedURLException) {}catch (IOException LocalIOException) {} } } Problem:. It checks if a player has proxy and if it returns Y means that it has, but if the player doesn't have proxy, it still returns Y, so i added "else" so that if he doesn't use a proxy he is allowed to join, but it doesn't do anything, it still returns as a Y. What you can do to recreate the problem:. Easy, copy-pasta Possible problematic line(s):. The whole code. Error message (If any): . Nothing What you have tried: . I explained up at "Problem" P.S. if the Main.class is needed, i can give it. And yes it is "AntiBot-Ultra"
Don't abuse static. Pass the main instance of the main class through constructors. Also, don't name your main classes 'Main'. Instead the main class should be called the name of the plugin. You can delete all of this. Because: You do not need to test booleans for if statements. If the boolean is true, it will treat as though you have "boolean == true;". Boolean.valueof(Boolean) makes no sense. It is already a boolean. Boolean.booleanValue also does not make any sense. It is already a boolean as well. Don't catch exceptions and never print it out. This is why you are not receiving any errors. You have not closed the scanner. It's been a while since I used Scanner, but isn't it case sensitive? Are you sure the 'N' that is returned is upper case?
Adding a 'else' statement will never fix it if the 'if' statement before the 'else' statement is true. Other thing what do you mean with 'Easy, copy-pasta'? Did you code it yourself or did you just copy past it without knowing what it does?
Tried what you said and i cleaned up a little, but if i replace the FIRST N with Y and the END Y with N, it would detect all the IP'S as a proxy. I have used http://botscout.com/test/?ip=(my ip) and it returned a N (means that i don't use proxy) but the code detected it as a Y. Code. Code: @EventHandler(priority=EventPriority.HIGHEST) public void onLogin(PlayerLoginEvent event) throws MalformedURLException, IOException { Player p = event.getPlayer(); if (Main.c.getBoolean("CHECKPROXY")) { String url = "http://botscout.com/test/?ip=" + event.getAddress().getHostAddress(); Scanner Scanner = new Scanner(new URL(url).openStream()); if (Scanner.findInLine("Y") != null) { event.setResult(PlayerLoginEvent.Result.KICK_OTHER); event.disallow(PlayerLoginEvent.Result.KICK_OTHER, ChatColor.RED + "You are using a proxy!"); p.setWhitelisted(false); } Scanner.close(); } else { String url = "http://botscout.com/test/?ip=" + event.getAddress().getHostAddress(); Scanner Scanner = new Scanner(new URL(url).openStream()); if (Scanner.findInLine("N") != null) { event.allow(); event.setResult(PlayerLoginEvent.Result.ALLOWED); p.setWhitelisted(true); } Scanner.close(); } }
That must mean that even though the IP does not contain a "Y", it does return an object. Try seeing what the scanner returns.
@Kermit_23 You could try scanner.nextLine().startsWith("N") instead. This just checks the beginning. But yes, the output from scanner.nextLine() before the findInLine check would help a lot. Also you should follow naming conventions and make "Scanner" lowercase as it is a variable.
@I Al Istannen So i did what you told me and it WORKED, but now it threw another error EDIT: I restarted server and now it detects that i'm using a proxy, but like i said up, i did again the ip test with the api and it detects as a "N". I'm confused that my friend can join, but i can't Code: [08:34:56] [Server thread/WARN]: [AntiBotUltra] Task #57 for AntiBotUltra v1.81.9 generated an exception java.lang.ClassCastException: java.util.Collections$UnmodifiableRandomAccessList cannot be cast to org.bukkit.command.CommandSender at ittrio.antibotultra.light.source.AutoWhite$1.run(AutoWhite.java:35) ~[?:?] at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftTask.run(CraftTask.java:71) ~[spigot_server.jar:git-Spigot-db6de12-18fbb24] at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:350) [spigot_server.jar:git-Spigot-db6de12-18fbb24] at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:723) [spigot_server.jar:git-Spigot-db6de12-18fbb24] at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot_server.jar:git-Spigot-db6de12-18fbb24] at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot_server.jar:git-Spigot-db6de12-18fbb24] at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot_server.jar:git-Spigot-db6de12-18fbb24] at java.lang.Thread.run(Unknown Source) [?:1.8.0_74] Here is the AutoWhite code: Code: public class AutoWhite implements Listener { @EventHandler(priority=EventPriority.HIGHEST) public void login(PlayerLoginEvent event) { String kick = Main.c.getString("WHITELIST_MESSAGE"); if (event.getResult() == PlayerLoginEvent.Result.KICK_WHITELIST) { event.setKickMessage(kick); } else if ((event.getResult() == PlayerLoginEvent.Result.ALLOWED) && (!event.getPlayer().isWhitelisted())) { final Player pla = event.getPlayer(); Main.r.getServer().getScheduler().runTask(Main.r, new Runnable() { public void run() { if ((pla.isOnline()) && (!pla.isWhitelisted())) { pla.setWhitelisted(true); Collection<? extends Player> arrayOfPlayer; int j = (arrayOfPlayer = Bukkit.getOnlinePlayers()).size(); for (int i = 0; i < j; i++) { Collection<? extends Player> o = arrayOfPlayer; if (pla.hasPermission(new Permission("Antibot.spy"))) { ((CommandSender) o).sendMessage(ChatColor.RED + "[BOT] ADDED " + ChatColor.BLUE + pla.getPlayer().getDisplayName() + ChatColor.YELLOW + "TO THE WHITELIST"); } } } } }); } } }
You are casting a Collection of Players to a CommandSender object. That's obviously not allowed. Please learn to read your stack traces, they contain lots of useful information.
@Lolmewn Is it good now? Code: public class Whitelist implements Listener { public void login(PlayerLoginEvent event) { String kick = AntiBotUltra.c.getString("WHITELIST_MESSAGE"); if (event.getResult() == PlayerLoginEvent.Result.KICK_WHITELIST) { event.setKickMessage(kick); } else if ((event.getResult() == PlayerLoginEvent.Result.ALLOWED) && (!event.getPlayer().isWhitelisted())) { final Player pla = event.getPlayer(); AntiBotUltra.r.getServer().getScheduler().runTask(AntiBotUltra.r, new Runnable() { public void run() { if ((pla.isOnline()) && (!pla.isWhitelisted())) { try { pla.setWhitelisted(true); int j = (Bukkit.getOnlinePlayers()).size(); for (int i = 0; i < j; i++) { if (pla.hasPermission(new Permission("Antibot.spy"))) { pla.sendMessage(pla.getDisplayName() + AntiBotUltra.c.getString("ADDEDTOWHITELISTMSG")); } } } catch (CommandException Exception) {} } } }); } } }