Hi spigot I trying to prevent people from using a command if they are on the same internet. The have i done with player.getAddress() but then i use that it give me 2 different ips's(only the last number is different for the other), The weird ting of it is that i'm sitting with 2 minecraft acoounts on the same pc, so i have same internet and all that things. Should i use a different method than player.getAddress() or do i do anything wrong? //Water
With the onjoin event, check if a player online has the same ip as someone joining, then set the onJoin event to be cancelled.
@kyle1264x I know all about that, but the ip is not the same, still then i use the same computer to the two players.
Seeing as neither PlayerJoinEvent, nor PlayerLoginEvent implement Cancellable, you're going to have a tough time doing that. Untested, but an example of user IP management: https://gist.github.com/Curspex/96429f5e71fe67627830
Code (Text): Player p = (Player) sender; if(p.getAddress().toString() != Bukkit.getServer().getPlayer(args[0]).getAddress().toString()){ p.sendMessage(p.getAddress().toString()); p.sendMessage(Bukkit.getServer().getPlayer(args[0]).getAddress().toString()); Bukkit.getServer().getPlayer(args[0]).sendMessage(ChatColor.GREEN + "You have been referer by " + sender.getName() + "!"); return true; } else { sender.sendMessage(ChatColor.RED + "You can't refer a person that are on the same ip as you"); return true; }
@Waterman2707 Aside that you should not compare Strings with == or != but with equals instead, where did you test the code?
Not a fix for your problem but you should check that the object returned by the getPlayer method isn't null. You might also want to check whether the sender is a player.
Yeah i know, i don't know why i have forgot it here The code is tested in a command, i haven't included it all because it's this that not work, and this code con't use anything from other places It's another place in the code it's not include in this i have given
.getAddress().toString() also contains the port the player is connecting from. Split by ":" and take only the first part to compare.