mirror of
https://gitlab.com/SamB440/rpgregions-2.git
synced 2025-12-28 03:09:14 +00:00
Use enum for default values and generation
This commit is contained in:
@@ -8,6 +8,7 @@ import net.islandearth.rpgregions.api.RPGRegionsAPI;
|
||||
import net.islandearth.rpgregions.listener.ConnectionListener;
|
||||
import net.islandearth.rpgregions.listener.MoveListener;
|
||||
import net.islandearth.rpgregions.managers.RPGRegionsManagers;
|
||||
import net.islandearth.rpgregions.translation.Translations;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
@@ -49,33 +50,7 @@ public final class RPGRegions extends JavaPlugin implements RPGRegionsAPI, Langu
|
||||
}
|
||||
|
||||
private void generateLang() {
|
||||
File lang = new File(this.getDataFolder() + "/lang/");
|
||||
if (!lang.exists()) lang.mkdirs();
|
||||
|
||||
for (Language language : Language.values()) {
|
||||
File file = new File(getDataFolder() + "/lang/" + language.getCode() + ".yml");
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
config.options().copyDefaults(true);
|
||||
config.addDefault("toggled", "&aYour map has been toggled.");
|
||||
config.addDefault("invalid_cursor", "&cInvalid cursor type.");
|
||||
config.addDefault("location_saved", "&aMap location saved.");
|
||||
config.addDefault("cursor_removed", "&aThe cursor has been removed.");
|
||||
config.addDefault("location_not_saved", "&cYour current location is not saved as a cursor.");
|
||||
|
||||
try {
|
||||
config.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
Translations.generateLang(this);
|
||||
}
|
||||
|
||||
private void createConfig() {
|
||||
|
||||
@@ -1,14 +1,29 @@
|
||||
package net.islandearth.rpgregions.translation;
|
||||
|
||||
import net.islandearth.languagy.language.Language;
|
||||
import net.islandearth.rpgregions.RPGRegions;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public enum Translations {
|
||||
DISCOVERED;
|
||||
DISCOVERED("Region discovered!");
|
||||
|
||||
private final String defaultValue;
|
||||
|
||||
Translations(String defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public String getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
private String getPath() {
|
||||
return this.toString().toLowerCase();
|
||||
}
|
||||
@@ -58,4 +73,32 @@ public enum Translations {
|
||||
RPGRegions plugin = JavaPlugin.getPlugin(RPGRegions.class);
|
||||
return plugin.getTranslator().getTranslationListFor(player, this.getPath());
|
||||
}
|
||||
|
||||
public static void generateLang(RPGRegions plugin) {
|
||||
File lang = new File(plugin.getDataFolder() + "/lang/");
|
||||
if (!lang.exists()) lang.mkdirs();
|
||||
|
||||
for (Language language : Language.values()) {
|
||||
File file = new File(plugin.getDataFolder() + "/lang/" + language.getCode() + ".yml");
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
config.options().copyDefaults(true);
|
||||
for (Translations key : values()) {
|
||||
config.addDefault(key.toString().toLowerCase(), key.getDefaultValue());
|
||||
}
|
||||
|
||||
try {
|
||||
config.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user