Implement Abstraction layer (except runnable factory)

This commit is contained in:
Risto Lahtela 2021-07-09 19:22:43 +03:00
parent a5f49fb237
commit 25be0efbd8

View File

@ -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];
}
};
}
}