start migration to lang file
This commit is contained in:
67
src/main/java/cc/fascinated/config/Lang.java
Normal file
67
src/main/java/cc/fascinated/config/Lang.java
Normal file
@ -0,0 +1,67 @@
|
||||
package cc.fascinated.config;
|
||||
|
||||
import cc.fascinated.Aetheria;
|
||||
import cc.fascinated.utils.io.Config;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
public enum Lang {
|
||||
|
||||
HELP_COMMAND("help-command");
|
||||
|
||||
/**
|
||||
* The path of the lang in the lang.yml file.
|
||||
*/
|
||||
private final String path;
|
||||
|
||||
Lang(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache of the lang values.
|
||||
*/
|
||||
private final HashMap<String, Object> cache = new HashMap<>();
|
||||
|
||||
/**
|
||||
* The lang configuration.
|
||||
*/
|
||||
private final Config langConfig = new Config(Aetheria.INSTANCE, "lang.yml", null);
|
||||
|
||||
/**
|
||||
* Gets as an object.
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
public Object get() {
|
||||
return cache.computeIfAbsent(path, key -> {
|
||||
FileConfiguration configuration = langConfig.getFileConfiguration();
|
||||
if (configuration.get(path) == null) {
|
||||
throw new IllegalArgumentException("Path " + path + " does not exist in the lang.yml file.");
|
||||
}
|
||||
return configuration.get(path);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets as a string.
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
public String getAsString() {
|
||||
return (String) get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets as a string list.
|
||||
*
|
||||
* @return the string list
|
||||
*/
|
||||
public List<String> getAsStringList() {
|
||||
return (List<String>) get();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user