Same computer but different ip's???

Discussion in 'Spigot Plugin Development' started by Waterman2707, May 26, 2015.

  1. 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?

  2. With the onjoin event, check if a player online has the same ip as someone joining, then set the onJoin event to be cancelled.
  3. @kyle1264x I know all about that, but the ip is not the same, still then i use the same computer to the two players.
  4. Omnivion


    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:
  5. Can we see your code?
  6. Code (Text):
    Player p = (Player) sender;
                            if(p.getAddress().toString() != 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;
  7. @Waterman2707 Aside that you should not compare Strings with == or != but with equals instead, where did you test the code?
  8. 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.
  9. Yeah i know, i don't know why i have forgot it here :p 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 ;)
  10. .getAddress().toString() also contains the port the player is connecting from. Split by ":" and take only the first part to compare.
  11. Ohhh thanks why haven't i thinked of that :p But many thank you ;)