From 25be0efbd851716fb2ac0fd9dcf2fd38c5a542d1 Mon Sep 17 00:00:00 2001 From: Risto Lahtela <24460436+AuroraLS3@users.noreply.github.com> Date: Fri, 9 Jul 2021 19:22:43 +0300 Subject: [PATCH] Implement Abstraction layer (except runnable factory) --- .../StandalonePlatformAbstractionLayer.java | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/Plan/standalone/src/main/java/net/playeranalytics/plugin/StandalonePlatformAbstractionLayer.java b/Plan/standalone/src/main/java/net/playeranalytics/plugin/StandalonePlatformAbstractionLayer.java index 1348e8f8b..c5a750e53 100644 --- a/Plan/standalone/src/main/java/net/playeranalytics/plugin/StandalonePlatformAbstractionLayer.java +++ b/Plan/standalone/src/main/java/net/playeranalytics/plugin/StandalonePlatformAbstractionLayer.java @@ -4,7 +4,13 @@ import net.playeranalytics.plugin.scheduling.RunnableFactory; import net.playeranalytics.plugin.server.JavaUtilPluginLogger; import net.playeranalytics.plugin.server.Listeners; import net.playeranalytics.plugin.server.PluginLogger; +import org.apache.commons.lang3.StringUtils; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URISyntaxException; +import java.nio.file.Files; import java.util.logging.Logger; public class StandalonePlatformAbstractionLayer implements PlatformAbstractionLayer { @@ -42,6 +48,31 @@ public class StandalonePlatformAbstractionLayer implements PlatformAbstractionLa @Override public PluginInformation getPluginInformation() { - return null; + return new PluginInformation() { + @Override + public InputStream getResourceFromJar(String s) { + return getClass().getResourceAsStream(s); + } + + @Override + public File getDataFolder() { + return new File("Plan"); + } + + @Override + public String getVersion() { + try { + return readVersionFromPluginYml(); + } catch (IOException | URISyntaxException e) { + return e.toString(); + } + } + + private String readVersionFromPluginYml() throws IOException, URISyntaxException { + String pluginYmlContents = new String(Files.readAllBytes(new File(getClass().getResource("plugin.yml").toURI()).toPath())); + String versionHalf = StringUtils.split(pluginYmlContents, "version:")[1]; + return StringUtils.split(versionHalf, "\n")[0]; + } + }; } }