From 90dabce0d28f8840c81da0ffbf542bcb6e4c4d7b Mon Sep 17 00:00:00 2001 From: Myles Date: Mon, 26 Sep 2016 11:48:06 +0100 Subject: [PATCH] Sponge: Fix dump, add load message, move loading, handle reload And fix travis --- .travis.yml | 2 +- TODOLIST | 7 ++++- .../java/us/myles/ViaVersion/ViaManager.java | 1 - .../us/myles/ViaVersion/SpongePlugin.java | 26 ++++++++++++++++--- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 74e44a99b..f87395083 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ sudo: false language: java -jdk: oraclejdk7 +jdk: oraclejdk8 cache: directories: diff --git a/TODOLIST b/TODOLIST index 7186f5903..e4e40f1b1 100644 --- a/TODOLIST +++ b/TODOLIST @@ -1,2 +1,7 @@ PORT STUFF TO GUAVA :D (so we dont need to include commons) -Test on SpongeForge, only tested SpongeVanilla \ No newline at end of file +Test on SpongeForge, only tested SpongeVanilla +Stop using new Gson() everywhere +Java docs (for platforms etc) +Config implementation for sponge +Port bukkit listeners to sponge maybe +Fix task ids, methods for sponge \ No newline at end of file diff --git a/common/src/main/java/us/myles/ViaVersion/ViaManager.java b/common/src/main/java/us/myles/ViaVersion/ViaManager.java index 951490e06..60a9254aa 100644 --- a/common/src/main/java/us/myles/ViaVersion/ViaManager.java +++ b/common/src/main/java/us/myles/ViaVersion/ViaManager.java @@ -57,7 +57,6 @@ public class ViaManager { // Mark as injected System.setProperty("ViaVersion", getPlatform().getPluginVersion()); // If successful - // TODO: This method might run in onLoad, ensure sync tasks can still run if plugin not enabled. platform.runSync(new Runnable() { @Override public void run() { diff --git a/sponge/src/main/java/us/myles/ViaVersion/SpongePlugin.java b/sponge/src/main/java/us/myles/ViaVersion/SpongePlugin.java index e4567df6c..b235d06be 100644 --- a/sponge/src/main/java/us/myles/ViaVersion/SpongePlugin.java +++ b/sponge/src/main/java/us/myles/ViaVersion/SpongePlugin.java @@ -1,10 +1,12 @@ package us.myles.ViaVersion; +import com.google.gson.Gson; import com.google.gson.JsonObject; import com.google.inject.Inject; import org.spongepowered.api.Game; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.event.Listener; +import org.spongepowered.api.event.game.state.GameAboutToStartServerEvent; import org.spongepowered.api.event.game.state.GameStartedServerEvent; import org.spongepowered.api.plugin.Plugin; import org.spongepowered.api.plugin.PluginContainer; @@ -16,9 +18,12 @@ import us.myles.ViaVersion.api.ViaVersionConfig; import us.myles.ViaVersion.api.command.ViaCommandSender; import us.myles.ViaVersion.api.configuration.ConfigurationProvider; import us.myles.ViaVersion.api.platform.ViaPlatform; +import us.myles.ViaVersion.dump.PluginInfo; import us.myles.ViaVersion.sponge.*; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import java.util.UUID; import java.util.concurrent.TimeUnit; import java.util.logging.Logger; @@ -42,7 +47,7 @@ public class SpongePlugin implements ViaPlatform { private Logger logger; @Listener - public void onServerStart(GameStartedServerEvent event) { + public void onServerStart(GameAboutToStartServerEvent event) { // Setup Logger logger = new LoggerWrapper(container.getLogger()); // Setup Plugin @@ -50,6 +55,7 @@ public class SpongePlugin implements ViaPlatform { asyncExecutor = game.getScheduler().createAsyncExecutor(this); SpongeCommandHandler commandHandler = new SpongeCommandHandler(); game.getCommandManager().register(this, commandHandler, Arrays.asList("viaversion", "viaver")); + getLogger().info("ViaVersion " + getPluginVersion() + " is now loaded, injecting!"); // Init platform Via.init(ViaManager.builder() .platform(this) @@ -153,11 +159,25 @@ public class SpongePlugin implements ViaPlatform { @Override public void onReload() { - // TODO: Warning? + getLogger().severe("ViaVersion is already loaded, this should work fine. If you get any console errors, try rebooting."); } @Override public JsonObject getDump() { - return new JsonObject(); + JsonObject platformSpecific = new JsonObject(); + + List plugins = new ArrayList<>(); + for (PluginContainer p : game.getPluginManager().getPlugins()) { + plugins.add(new PluginInfo( + true, + p.getName(), + p.getVersion().orElse("Unknown Version"), + p.getInstance().isPresent() ? p.getInstance().get().getClass().getCanonicalName() : "Unknown", + p.getAuthors() + )); + } + platformSpecific.add("plugins", new Gson().toJsonTree(plugins)); + + return platformSpecific; } }