Skip to content

Commit

Permalink
Merge pull request #104 from WaterArchery/module-enhance
Browse files Browse the repository at this point in the history
Fixed lang not load issue
  • Loading branch information
poyrazinan authored Sep 29, 2024
2 parents 45f8ce9 + 122e143 commit 36d37ed
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/main/java/xyz/geik/farmer/modules/FarmerModule.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package xyz.geik.farmer.modules;

import jdk.internal.loader.BootLoader;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.plugin.java.JavaPlugin;
Expand All @@ -10,19 +9,14 @@
import xyz.geik.farmer.helpers.ModuleHelper;
import xyz.geik.farmer.model.Farmer;
import xyz.geik.farmer.shades.storage.Config;
import xyz.geik.glib.GLib;
import xyz.geik.glib.module.GModule;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Objects;

/**
* Module system of Farmer
Expand Down Expand Up @@ -56,8 +50,7 @@ public abstract class FarmerModule extends GModule {
public void setLang(String langName, Class<?> targetClass) {
langName += ".yml";
String filePath = "plugins/" + Main.getInstance().getDescription().getName() + "/modules/" + this.getName().toLowerCase() + "/lang";
lang = new Config(langName, filePath, getResourceAsStream(langName, targetClass));

lang = new Config(langName, filePath, getFileFromResourceAsStream(langName, targetClass));
}

public void setLang(String langName, JavaPlugin plugin) {
Expand All @@ -69,12 +62,20 @@ public void setLang(String langName, JavaPlugin plugin) {

/**
* Gets inputstream of file
* @param name name of file
* @param fileName name of file
* @param targetClass instance of target class
* @return InputStream object
*/
public InputStream getResourceAsStream(String name, Class<?> target) {
InputStream inputStream = target.getResourceAsStream(name);
return inputStream;
private InputStream getFileFromResourceAsStream(String fileName, Class<?> targetClass) {
final String path = targetClass.getSimpleName().toLowerCase() + "/lang/" + fileName;
ClassLoader classLoader = targetClass.getClassLoader();
InputStream inputStream = classLoader.getResourceAsStream(path);

if (inputStream == null) {
throw new IllegalArgumentException("Resource not found: " + path);
} else {
return inputStream;
}
}

/**
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 36d37ed

Please sign in to comment.