Make file provider accept plugin to get correct resource file

This commit is contained in:
天クマ 2026-05-25 21:45:33 -03:00
commit 632993678e
5 changed files with 7 additions and 18 deletions

View file

@ -31,6 +31,6 @@ public class B1_7_3Registrar implements VersionedServiceRegistrar {
factory.register(ConfigurationProvider.class, "b1_7_3", Configuration::new);
factory.register(TextColorProvider.class, "b1_7_3", TextColor::new);
factory.register(LoggerProvider.class, "b1_7_3", Logger::new);
factory.register(FileProvider.class, "b1_7_3", () -> new File(plugin));
factory.register(FileProvider.class, "b1_7_3", File::new);
}
}

View file

@ -8,21 +8,15 @@ import java.io.IOException;
import java.io.InputStream;
public class File implements FileProvider {
private final JavaPlugin plugin;
public File(JavaPlugin plugin) {
this.plugin = plugin;
}
@Override
public void saveResource(String resourcePath, boolean replace) throws IOException {
public void saveResource(String resourcePath, boolean replace, JavaPlugin plugin) throws IOException {
java.io.File file = new java.io.File(plugin.getDataFolder(), resourcePath);
if (!file.exists() || replace) {
file.getParentFile().mkdirs();
InputStream in = this.getClass().getResourceAsStream("/" + resourcePath);
InputStream in = plugin.getClass().getResourceAsStream("/" + resourcePath);
if (in == null) {
throw new IllegalArgumentException("Resource not found: " + resourcePath);

View file

@ -1,6 +1,7 @@
package org.adrianvictor.lib.file.provider;
import org.adrianvictor.lib.Main;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.IOException;
@ -9,5 +10,5 @@ public interface FileProvider {
return Main.getServiceFactory().getService(FileProvider.class);
}
void saveResource(String resourcePath, boolean replace) throws IOException;
void saveResource(String resourcePath, boolean replace, JavaPlugin plugin) throws IOException;
}

View file

@ -31,6 +31,6 @@ public class R1_21Registrar implements VersionedServiceRegistrar {
factory.register(ConfigurationProvider.class, "r1_1", Configuration::new);
factory.register(TextColorProvider.class, "r1_16_5", TextColor::new);
factory.register(LoggerProvider.class, "r1_21", Logger::new);
factory.register(FileProvider.class, "r1_3", () -> new File(plugin));
factory.register(FileProvider.class, "r1_21", File::new);
}
}

View file

@ -4,14 +4,8 @@ import org.adrianvictor.lib.file.provider.FileProvider;
import org.bukkit.plugin.java.JavaPlugin;
public class File implements FileProvider {
private final JavaPlugin plugin;
public File(JavaPlugin plugin) {
this.plugin = plugin;
}
@Override
public void saveResource(String resourcePath, boolean replace) {
public void saveResource(String resourcePath, boolean replace, JavaPlugin plugin) {
plugin.saveResource(resourcePath, replace);
}
}