From 5375c4fa98dfec72a94b17a4c896e6c6ccf7262b Mon Sep 17 00:00:00 2001 From: Electroid Date: Sun, 27 Aug 2017 16:21:42 -0700 Subject: [PATCH] Fix ip reporting --- .../main/java/tc/oc/api/docs/virtual/ServerDoc.java | 8 ++++++-- .../java/tc/oc/api/minecraft/MinecraftServiceImpl.java | 10 ++++++++++ .../api/minecraft/servers/StartupServerDocument.java | 9 ++++----- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/API/api/src/main/java/tc/oc/api/docs/virtual/ServerDoc.java b/API/api/src/main/java/tc/oc/api/docs/virtual/ServerDoc.java index fd6adcb..5bf6b54 100644 --- a/API/api/src/main/java/tc/oc/api/docs/virtual/ServerDoc.java +++ b/API/api/src/main/java/tc/oc/api/docs/virtual/ServerDoc.java @@ -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 plugin_versions(); Set protocol_versions(); diff --git a/API/minecraft/src/main/java/tc/oc/api/minecraft/MinecraftServiceImpl.java b/API/minecraft/src/main/java/tc/oc/api/minecraft/MinecraftServiceImpl.java index b1a78b9..ba94104 100644 --- a/API/minecraft/src/main/java/tc/oc/api/minecraft/MinecraftServiceImpl.java +++ b/API/minecraft/src/main/java/tc/oc/api/minecraft/MinecraftServiceImpl.java @@ -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); } diff --git a/API/minecraft/src/main/java/tc/oc/api/minecraft/servers/StartupServerDocument.java b/API/minecraft/src/main/java/tc/oc/api/minecraft/servers/StartupServerDocument.java index f7ea9f5..9b66bfd 100644 --- a/API/minecraft/src/main/java/tc/oc/api/minecraft/servers/StartupServerDocument.java +++ b/API/minecraft/src/main/java/tc/oc/api/minecraft/servers/StartupServerDocument.java @@ -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 protocol_versions() { return minecraftServer.getProtocolVersions(); } + + public String ip() { + return ip.get(); + } }