Bukkit Coding IPs

Discussion in 'Plugin Development' started by benzimmer123, Apr 11, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    benzimmer123

    I recently made this command /alt I see no problems, maybe yo guys can. The problem is when an alt is online it still says the same message "(Playername) has no alts online". I'm really confused!
    Thanks in advance!

    Code:java
    1. final Player p = (Player) sender;
    2. if (!p.hasPermission("CommandCentral.kick")) {
    3. p.sendMessage(ChatColor.RED + "You don't Have Permission!");
    4. } else {
    5. if (args.length == 0) {
    6. p.sendMessage(ChatColor.RED + "Please Specify a Player!");
    7. }
    8. if (args.length == 1) {
    9. Player player = Bukkit.getPlayerExact(args[0]);
    10. if (player != null) {
    11. String playerip = player.getAddress().getAddress().getHostAddress();
    12. for (Player online : Bukkit.getOnlinePlayers()) {
    13. String olip = online.getAddress().getAddress().getHostAddress();
    14. if (playerip == olip) {
    15. p.sendMessage(ChatColor.RED + online.getName() + " is " + player.getName() + "'s alt.");
    16. return true;
    17. } else {
    18. return true;
    19. }
    20. }
    21. p.sendMessage(ChatColor.RED + player.getName() + " has no alts online.");
    22. } else {
    23. p.sendMessage(ChatColor.RED + "Couldn't find that player!");
    24. }
    25. } else {
    26. p.sendMessage(ChatColor.RED + "Usage: /alt <playername>");
    27. }
    28. }
     
  2. We need more code and indentation please ;)
     
  3. Offline

    kreashenz

    Doesn't the .getHostAddress() return a port too? The ports would all be different to each player even if they're on the same IP. Try removing the bit after the colon in the string, as in "123.45.567.89:35363" and turning it into "123.45.678.89".
     
  4. Offline

    Konkz

    Why don't you just do
    Code:
    player.getAddress();
    I believe that would work.
     
  5. Offline

    benzimmer123

    kreashenz
    Seems to be working better, at first it goes "benzimmer123 is benzimmer123's alt," So I changed it to this...
    Code:java
    1. if (playerip == olip && !(player == online))

    Now it says the same problem as the first one!
     
  6. Offline

    kreashenz

    benzimmer123 Debug and print out each of the .getHostAddress() and you should be able to figure it out from there.
     
  7. Offline

    benzimmer123

    Konkz
    Yes that works but didn't fix the issue. :p

    kreashenz
    How would I do that?:p

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  8. Offline

    Konkz

    Before every statement do
    Code:
    Bukkit.broadcastMessage(TheHostIPThing + " Check 1");
    That will broadcast message telling you what is going on and area that is causing the problem

    benzimmer123
     
  9. Offline

    benzimmer123

    Konkz
    Done, all the checks come up but it broadcasts the port. It shows a different port for each player even though there on the same IP how do I remove the port?
     
  10. Offline

    Konkz

    I see what I've done wrong!

    Instead of like I said before doing
    Code:
    player.getAddress();
    Do
    Code:
    player.getAddress().getAddress().getHostAddress();
    That returns the IP without port.

    benzimmer123
     
Thread Status:
Not open for further replies.

Share This Page