mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-26 18:53:16 +08:00
Add plugin data folders
This commit is contained in:
parent
91a2a55ed9
commit
dc26f9e232
@ -4,6 +4,7 @@ import emu.grasscutter.Grasscutter;
|
|||||||
import emu.grasscutter.plugin.api.ServerHook;
|
import emu.grasscutter.plugin.api.ServerHook;
|
||||||
import emu.grasscutter.server.game.GameServer;
|
import emu.grasscutter.server.game.GameServer;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
|
|
||||||
@ -15,6 +16,7 @@ public abstract class Plugin {
|
|||||||
|
|
||||||
private PluginIdentifier identifier;
|
private PluginIdentifier identifier;
|
||||||
private URLClassLoader classLoader;
|
private URLClassLoader classLoader;
|
||||||
|
private File dataFolder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is reflected into.
|
* This method is reflected into.
|
||||||
@ -23,11 +25,19 @@ public abstract class Plugin {
|
|||||||
* @param identifier The plugin's identifier.
|
* @param identifier The plugin's identifier.
|
||||||
*/
|
*/
|
||||||
private void initializePlugin(PluginIdentifier identifier, URLClassLoader classLoader) {
|
private void initializePlugin(PluginIdentifier identifier, URLClassLoader classLoader) {
|
||||||
if(this.identifier == null)
|
if(this.identifier != null) {
|
||||||
this.identifier = identifier;
|
Grasscutter.getLogger().warn(this.identifier.name + " had a reinitialization attempt.");
|
||||||
if(this.classLoader == null)
|
return;
|
||||||
this.classLoader = classLoader;
|
}
|
||||||
else Grasscutter.getLogger().warn(this.identifier.name + " had a reinitialization attempt.");
|
|
||||||
|
this.identifier = identifier;
|
||||||
|
this.classLoader = classLoader;
|
||||||
|
this.dataFolder = new File(Grasscutter.getConfig().PLUGINS_FOLDER, identifier.name);
|
||||||
|
|
||||||
|
if(!this.dataFolder.exists() && !this.dataFolder.mkdirs()) {
|
||||||
|
Grasscutter.getLogger().warn("Failed to create plugin data folder for " + this.identifier.name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,6 +86,14 @@ public abstract class Plugin {
|
|||||||
return this.classLoader.getResourceAsStream(resourceName);
|
return this.classLoader.getResourceAsStream(resourceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a directory where plugins can store data files.
|
||||||
|
* @return A directory on the file system.
|
||||||
|
*/
|
||||||
|
public final File getDataFolder() {
|
||||||
|
return this.dataFolder;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the server hook.
|
* Returns the server hook.
|
||||||
* @return A server hook singleton.
|
* @return A server hook singleton.
|
||||||
|
Loading…
Reference in New Issue
Block a user