diff --git a/connector/src/main/java/org/geysermc/connector/console/LoggingOutputStream.java b/connector/src/main/java/org/geysermc/connector/console/LoggingOutputStream.java index 6afbd3e9..2652fc42 100644 --- a/connector/src/main/java/org/geysermc/connector/console/LoggingOutputStream.java +++ b/connector/src/main/java/org/geysermc/connector/console/LoggingOutputStream.java @@ -14,11 +14,10 @@ package org.geysermc.connector.console; -import com.google.common.base.Charsets; - import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.util.logging.Level; import java.util.logging.Logger; @@ -37,7 +36,7 @@ public class LoggingOutputStream extends ByteArrayOutputStream { super.write(b); try { - String contents = toString(Charsets.UTF_8.name()); + String contents = toString(StandardCharsets.UTF_8.name()); if (!contents.isEmpty() && !contents.equals(System.getProperty("line.separator"))) logger.logp(level, "", "", contents); } catch (UnsupportedEncodingException ex) { @@ -47,7 +46,7 @@ public class LoggingOutputStream extends ByteArrayOutputStream { @Override public synchronized void flush() throws IOException { - String contents = toString(Charsets.UTF_8.name()); + String contents = toString(StandardCharsets.UTF_8.name()); super.reset(); if (!contents.isEmpty() && !contents.equals(System.getProperty("line.separator"))) diff --git a/connector/src/main/java/org/geysermc/connector/plugin/Loader.java b/connector/src/main/java/org/geysermc/connector/plugin/Loader.java new file mode 100644 index 00000000..4775a6a4 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/plugin/Loader.java @@ -0,0 +1,81 @@ +package org.geysermc.connector.plugin; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; +import org.geysermc.api.plugin.Plugin; + +import java.io.File; +import java.io.InputStream; +import java.util.Map; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +public class Loader extends ClassLoader { + static { + System.out.println("a"); + Loader l = new Loader(); + System.out.println("b"); + File dir = new File("plugins"); + System.out.println(dir.getAbsoluteFile()); + + if(!dir.exists()) { + dir.mkdir(); + } + + for(File f : dir.listFiles()) { + if(f.getName().endsWith(".jar")) { + try { + ZipFile file = new ZipFile(f); + + ZipEntry e = file.getEntry("plugin.yml"); + + if(e == null || e.isDirectory()) { + System.err.println("Plugin " + f.getName() + " has no valid plugin.yml!"); + continue; + } + + file.stream().forEach((x) -> { + if(x.getName().endsWith(".class")) { + try { + InputStream is = file.getInputStream(x); + byte[] b = new byte[is.available()]; + is.read(b); + l.defineClass(x.getName().replace(".class", "").replaceAll("/", "."), b, 0, b.length); + is.close(); + } catch (Exception e1) { + e1.printStackTrace(); + } + } + }); + + ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); + + InputStream is = file.getInputStream(e); + + PluginYML yml; + + yml = mapper.readValue(is, PluginYML.class); + + is.close(); + + ((Plugin) Class.forName(yml.main, true, l).newInstance()).onEnable(); + + } catch (Exception e) { + System.out.println("Error loading plugin " + f.getName()); + e.printStackTrace(); + } + } + } + LOADER = l; + } + + public static final Loader LOADER; + + public static void start() { + + } + + private Loader() { + + } +} diff --git a/connector/src/main/java/org/geysermc/connector/plugin/PluginYML.java b/connector/src/main/java/org/geysermc/connector/plugin/PluginYML.java new file mode 100644 index 00000000..9552bcb5 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/plugin/PluginYML.java @@ -0,0 +1,14 @@ +package org.geysermc.connector.plugin; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class PluginYML { + @JsonProperty("name") + String name; + + @JsonProperty("version") + String version; + + @JsonProperty("main") + String main; +}