1

I'm making a plugin for my staff that can help them with some basic information. I'm trying to add a /ip for the server that will show the server ip, instead of the dns that they connect to.

I'm trying something like this

var InfoIP = Bukkit.getIp();
player.sendMessage("Server Ip: " + InfoIP);

Apparently it does work with Bukkit.getPort(); but it doesnt work with the ip. Is there another way to fix this?

I'm not looking for anything like this

var myip = "0.0.0.0";
player.sendMessage("Server Ip:" + myip);

I want the myip to be filled by the getIp instead of manually filling it.

Hopefully someone has a solution for this :) tnx.

Kheera
  • 21
  • 1
  • 4
  • So you want it to show `***.***.***.***:port`? *EX: 182.118.145.123:25562* – Jojodmo Apr 07 '14 at 21:46
  • You could use InetAddress.getLocalHost().getHostName(), but the name it returns may not be what you are looking for. Here's more: http://stackoverflow.com/questions/7348711/recommended-way-to-get-hostname-in-java – Darius X. Apr 08 '14 at 15:32

4 Answers4

3

In order to use the getIP method you must define it in your server properties.

there should be a line called server ip. once you have defined your ip in the properties it will return the ip. when you use the getIP method.

NullReference
  • 311
  • 5
  • 20
1

Or you could use:

player.sendMessage(getServer().getAddress() + ":" + getServer().getPort());

hope this helped

~~ AceStudios

AcePlugins
  • 11
  • 6
0

Or this:

if (!getServer().getPort() == "25565") {
player.sendMessage(getServer().getAddress() + ":" + getServer().getPort());
}
else {
player.sendMessage(getServer.getAddress());
0

Instead of using Bukkit.getIP(); try using Bukkit.getServer().getAddress();

HippoMC
  • 1
  • 6