Solved Getting the server name.

Discussion in 'BungeeCord Plugin Development' started by MangoCodes, May 21, 2016.

  1. Code (Text):

    public String serverName(CommandSender sender) {
            if (sender instanceof ProxiedPlayer) {
                ProxiedPlayer player = (ProxiedPlayer) sender;
                return player.getServer().getInfo().getName();
            }
            return "None";
        }
     
    I made this method to get the server name but all it does is just return "none" on my Hub Scoreboard any ideas on how I can fix this?
     
  2. "return "None";"
     
  3. Yes but If I remove that it gives me an error, and I tried to return it to serverName but that doesn't work since I can't access the Player.
     
  4. Try declaring ProxiedPlayer before your if statement, currently your if statement can't see what ProxiedPlayer is.

    Code (Text):
    public String serverName(CommandSender sender) {
        ProxiedPlayer player = (ProxiedPlayer) sender;
            if (sender instanceof ProxiedPlayer) {
                return player.getServer().getInfo().getName();
            }
            return "None";
        }
     
     
    • Agree Agree x 1
  5. Sorry, didn't see that, LOL. but look at jack's way, it works like that.
     
  6. YOu're casting the sender to a player before checking it's actually a player..

    Code (Text):
        public String serverName(CommandSender sender) {
            if (sender instanceof ProxiedPlayer) {
                return ( (ProxiedPlayer) sender ).getServer().getInfo().getName();
            }
            return "None";
        }
     
     
  7. It's still returning "None";
     
  8. Debugging will fix your issue then. Make sure the commandsender is a player.
     
  9. MangoCodes you need to declare ProxiedPlayer before you try and do something with it
     
  10. No? Thats wrong
    Try to log the class of "sender"
     
  11. I didn't test it, but you get the idea
     
  12. Try this:

    Code (Java):

    public String serverName(CommandSender sender) {
            System.out.println("DEBUG: The sender's name is " + sender.getName() + "!");
            if (sender instanceof ProxiedPlayer) {
                return ( (ProxiedPlayer) sender ).getServer().getInfo().getName();
            }
            return "None";
        }
     
    If it says The sender's name is CONSOLE then something is wrong with how you're calling that method.