Open ZizzyZizzy opened 5 years ago
I'm not 100% sure, but this looks like it could be the culprit:
public boolean load(String file, int type, ConfigSection defaultMap) {
this.correct = true;
this.type = type;
this.file = new File(file);
if (!this.file.exists()) {
try {
this.file.getParentFile().mkdirs();
this.file.createNewFile();
} catch (IOException var7) {
MainLogger.getLogger().error("Could not create Config " + this.file.toString(), var7);
}
In particular, this line:
this.file.getParentFile().mkdirs();
If you chase the rabbit down the rabbit hole, there is no mention of dataFolder. It appears to just use the path relative to the location of the loaded plugin.
Somewhere between saveDefaultConfig and getConfig, the dataFolder is either ignored or reverted to the location of the loaded plugin.
Here are the first three lines of the test plugin's onEnable function:
this.getServer().getLogger().info("[MY PLUGIN] Data folder = " + this.getDataFolder());
this.saveDefaultConfig();
pluginConfig = getConfig();
The call to saveDefaultConfig DOES work properly! The default config.yml is placed in the plugin's data folder under the /plugins/ folder of the server as expected. getConfig seems to be where it breaks.
After a bunch of debugging, I found the cause and a work-around.
I was changing the plugin dataFolder with reflection after the plugin was loaded, which was sufficient for how Spigot loads plugins. Nukkit looks similar but does things a little differently.
When the plugin was actually loaded by Nukkit, the configFile had already been set by the init function (PluginBase.class:79) using a dataFolder path that was set to the folder where the plugin .jar was loaded. That means setting only dataFolder after the plugin loads is not sufficient for Nukkit.
this.configFile = new File(this.dataFolder, "config.yml");
The work-around was to set both the dataFolder and configFile using reflection. That fixed my problem, but may not be a 100% solution.
Expected Behavior
All plugin functions functions should honor dataFolder.
Actual Behavior
Even though the plugin itself is reporting the correct dataFolder, either utils.Config or plugin.PluginBase.reloadConfig is getting the folder based on the location from which the plugin .jar was loaded.
Steps to Reproduce
Create a plugin that loads "other" plugins from a different folder.
After loading the plugin, use reflection to alter dataFolder. In this case, I'm altering the dataFolder from a shared folder where the plugin.jar is located to the server's normal /plugin/ folder.
However, one of the Nukkit config related functions is not honoring the dataFolder, but others are. For example, when the custom plugin loader first loads the "other" plugin, the plugin's data folder and config.yml ARE created as expected and in the correct location. When getConfig is called, suddenly the dataFolder has reverted to the location from where the plugin.jar was loaded.
NOTE: This works perfectly with Spigot using almost the exact same code.
Debug information
NOTE: [MY PLUGIN] output below is in the FIRST line in the MyTestPlugin's onEnable function, proving that when the plugin is enabled the dataFolder has been changed as expected.
Checklist:
/debugpaste
link