Added getting resources from the JAR

This commit is contained in:
KingRainbow44
2022-04-26 21:24:09 -04:00
parent 54658afe68
commit 34c358669b
2 changed files with 32 additions and 6 deletions

View File

@@ -1,13 +1,20 @@
package emu.grasscutter.plugin;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.plugin.api.ServerHook;
import emu.grasscutter.server.game.GameServer;
import java.io.InputStream;
import java.net.URLClassLoader;
/**
* The base class for all plugins to extend.
*/
public abstract class Plugin {
private final ServerHook server = ServerHook.getInstance();
private PluginIdentifier identifier;
private URLClassLoader classLoader;
/**
* This method is reflected into.
@@ -15,9 +22,11 @@ public abstract class Plugin {
* Set plugin variables.
* @param identifier The plugin's identifier.
*/
private void initializePlugin(PluginIdentifier identifier) {
private void initializePlugin(PluginIdentifier identifier, URLClassLoader classLoader) {
if(this.identifier == null)
this.identifier = identifier;
if(this.classLoader == null)
this.classLoader = classLoader;
else Grasscutter.getLogger().warn(this.identifier.name + " had a reinitialization attempt.");
}
@@ -55,7 +64,24 @@ public abstract class Plugin {
* @return A server instance.
*/
public final GameServer getServer() {
return Grasscutter.getGameServer();
return this.server.getGameServer();
}
/**
* Returns an input stream for a resource in the JAR file.
* @param resourceName The name of the resource.
* @return An input stream.
*/
public final InputStream getResource(String resourceName) {
return this.classLoader.getResourceAsStream(resourceName);
}
/**
* Returns the server hook.
* @return A server hook singleton.
*/
public final ServerHook getHandle() {
return this.server;
}
/* Called when the plugin is first loaded. */