forked from GeyserMC/Geyser
start plugin stuff
This commit is contained in:
parent
6f3c00c6ab
commit
abdd207406
4 changed files with 35 additions and 1 deletions
18
api/src/main/java/org/geysermc/api/Geyser.java
Normal file
18
api/src/main/java/org/geysermc/api/Geyser.java
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
package org.geysermc.api;
|
||||||
|
|
||||||
|
import org.geysermc.api.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Geyser {
|
||||||
|
private static final List<Plugin> plugins = new ArrayList<>();
|
||||||
|
|
||||||
|
public static List<Plugin> getPlugins() {
|
||||||
|
return new ArrayList<>(plugins);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void add(Plugin p) {
|
||||||
|
plugins.add(p);
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,4 +8,8 @@ public class Plugin {
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onLoad() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import org.geysermc.connector.command.GeyserCommandMap;
|
||||||
import org.geysermc.connector.configuration.GeyserConfiguration;
|
import org.geysermc.connector.configuration.GeyserConfiguration;
|
||||||
import org.geysermc.connector.console.ConsoleCommandReader;
|
import org.geysermc.connector.console.ConsoleCommandReader;
|
||||||
import org.geysermc.connector.console.GeyserLogger;
|
import org.geysermc.connector.console.GeyserLogger;
|
||||||
|
import org.geysermc.connector.plugin.Loader;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
@ -93,6 +94,9 @@ public class GeyserConnector {
|
||||||
logger.severe("Failed to create config.yml! Make sure it's up to date and writable!");
|
logger.severe("Failed to create config.yml! Make sure it's up to date and writable!");
|
||||||
shutdown();
|
shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loader.start();
|
||||||
|
|
||||||
commandMap = new GeyserCommandMap(this);
|
commandMap = new GeyserCommandMap(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package org.geysermc.connector.plugin;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
|
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
|
||||||
|
import org.geysermc.api.Geyser;
|
||||||
import org.geysermc.api.plugin.Plugin;
|
import org.geysermc.api.plugin.Plugin;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -58,7 +59,11 @@ public class Loader extends ClassLoader {
|
||||||
|
|
||||||
is.close();
|
is.close();
|
||||||
|
|
||||||
((Plugin) Class.forName(yml.main, true, l).newInstance()).onEnable();
|
Plugin plugin = (Plugin) Class.forName(yml.main, true, l).newInstance();
|
||||||
|
|
||||||
|
plugin.onLoad();
|
||||||
|
|
||||||
|
Geyser.add(plugin);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("Error loading plugin " + f.getName());
|
System.out.println("Error loading plugin " + f.getName());
|
||||||
|
@ -66,6 +71,9 @@ public class Loader extends ClassLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for(Plugin p : Geyser.getPlugins()) {
|
||||||
|
p.onEnable();
|
||||||
|
}
|
||||||
LOADER = l;
|
LOADER = l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue