Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
Plugin: load all localization files at init
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFaser committed Nov 8, 2023
1 parent 05eff4c commit e737113
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/main/java/net/flectone/chat/manager/FileManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import lombok.Setter;
import net.flectone.chat.FlectoneChat;
import net.flectone.chat.model.file.FConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.io.InputStream;
Expand Down Expand Up @@ -35,8 +37,11 @@ public class FileManager {
public static void init() {
config = Type.CONFIG.load();

Type.LOCALE.setFileName(config.getString("plugin.language"));
locale = Type.LOCALE.load();
Type.LOCALE_EN.load();
Type.LOCALE_RU.load();

Type localeType = Type.fromString(config.getString("plugin.language"));
locale = localeType != null ? localeType.getFile() : Type.LOCALE_EN.getFile();

modules = Type.MODULES.load();
commands = Type.COMMANDS.load();
Expand Down Expand Up @@ -128,7 +133,8 @@ public static int compareVersions(@NotNull String firstVersion, @NotNull String
public enum Type {

CONFIG("", "config"),
LOCALE(LANGUAGES_FOLDER, "en"),
LOCALE_EN(LANGUAGES_FOLDER, "en"),
LOCALE_RU(LANGUAGES_FOLDER, "ru"),
MODULES(SETTINGS_FOLDER, "modules"),
COMMANDS(SETTINGS_FOLDER, "commands"),
SOUNDS(SETTINGS_FOLDER, "sounds"),
Expand Down Expand Up @@ -183,5 +189,13 @@ public void update() {

file.save();
}

@Nullable
public static Type fromString(@NotNull String string) {
return Arrays.stream(Type.values())
.filter(type -> type.getFileName().equalsIgnoreCase(string))
.findAny()
.orElse(null);
}
}
}

0 comments on commit e737113

Please sign in to comment.