Skip to content

Commit

Permalink
Fix for Lang not being loaded on Windows machines
Browse files Browse the repository at this point in the history
  • Loading branch information
KillerOfPie committed Jan 11, 2022
1 parent 00a6724 commit 202d801
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.17.1-R0.1-SNAPSHOT</version>
<version>1.18.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/shanerx/tradeshop/TradeShop.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ public void onEnable() {
}

getLanguage();
if (!language.isLoaded()) {
getServer().getPluginManager().disablePlugin(this);
return;
}

getSettingManager().reload();
getMessageManager().reload();

Expand Down
21 changes: 18 additions & 3 deletions src/main/java/org/shanerx/tradeshop/utils/config/Language.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,22 @@

import org.bukkit.configuration.file.YamlConfiguration;
import org.shanerx.tradeshop.TradeShop;
import org.shanerx.tradeshop.enumys.DebugLevels;

import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Objects;

public class Language {

private final String LANG_FILE = "Lang" + File.separator,
private final String LANG_FILE = "Lang/",//.replace("/", File.separator), // Not replacing since getResource and Windows File Separator don't seem to be compatible
defaultLang = "en-us";
private final TradeShop PLUGIN;
private String lang = defaultLang;
private YamlConfiguration langYAML;
private boolean loaded = false;

public Language(TradeShop plugin) {
this.PLUGIN = plugin;
Expand All @@ -56,7 +58,16 @@ public void reload() {
changeLang(messageConfig.getString("language"));
}

langYAML = YamlConfiguration.loadConfiguration(new InputStreamReader(Objects.requireNonNull(PLUGIN.getResource(LANG_FILE + lang + ".yml"))));
InputStream is = PLUGIN.getResource(LANG_FILE + lang + ".yml");

if (is != null) {
langYAML = YamlConfiguration.loadConfiguration(new InputStreamReader(is));
} else {
PLUGIN.getDebugger().log("Lang file `" + LANG_FILE + lang + ".yml" + "` could not be loaded.", DebugLevels.DATA_ERROR);
loaded = false;
}

loaded = true;
}

public void changeLang(String newLang) {
Expand Down Expand Up @@ -96,6 +107,10 @@ public String getPostComment(LangSection section, String path) {
return langYAML.getString(section + "." + path + ".post-comment", "");
}

public boolean isLoaded() {
return loaded;
}


public enum LangSection {
MESSAGE_SECTION,
Expand Down

0 comments on commit 202d801

Please sign in to comment.