Fix ip reporting

This commit is contained in:
Electroid 2017-08-27 16:21:42 -07:00
parent 0eebdeed01
commit 5375c4fa98
3 changed files with 20 additions and 7 deletions

View File

@ -49,10 +49,14 @@ public interface ServerDoc {
@Nullable String bungee_name();
}
@Serialize
interface Port extends Partial {
Integer current_port();
}
@Serialize
interface Ip extends Partial {
String ip();
Integer current_port();
}
@Serialize
@ -96,7 +100,7 @@ public interface ServerDoc {
* Startup info sent to the API
*/
@Serialize
interface Startup extends Online, Ip {
interface Startup extends Online, Port {
@Nullable DeployInfo deploy_info();
Map<String, String> plugin_versions();
Set<Integer> protocol_versions();

View File

@ -2,6 +2,8 @@ package tc.oc.api.minecraft;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -150,6 +152,14 @@ public class MinecraftServiceImpl implements MinecraftService, MessageListener,
handleLocalReconfigure(serverService.update(apiConfiguration.serverId(), startupDocument).get());
logger.info("Connected to API as server." + getLocalServer()._id());
if(apiConfiguration.publishIp()) {
String oldIp = server.ip(), newIp = startupDocument.ip();
if(!Objects.equals(oldIp, newIp)) {
updateLocalServer((ServerDoc.Ip) () -> newIp).get();
logger.info("Changed ip from " + oldIp + " to " + newIp);
}
}
} catch (Exception e) {
this.processIntoIOException(e);
}

View File

@ -72,11 +72,6 @@ public class StartupServerDocument implements ServerDoc.Startup {
return true;
}
@Override
public String ip() {
return configuration.publishIp() ? ip.get() : null;
}
@Override public Integer current_port() {
return minecraftServer.getAddress().getPort();
}
@ -92,4 +87,8 @@ public class StartupServerDocument implements ServerDoc.Startup {
@Override public Set<Integer> protocol_versions() {
return minecraftServer.getProtocolVersions();
}
public String ip() {
return ip.get();
}
}