overall improvements
This commit is contained in:
parent
d66155ec87
commit
f45ac252c6
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>me.xginko.VillagerOptimizer</groupId>
|
||||
<artifactId>VillagerOptimizer</artifactId>
|
||||
<version>1.0.1</version>
|
||||
<version>1.0.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>1.16.5</artifactId>
|
||||
|
@ -39,7 +39,7 @@ public final class VillagerCache {
|
||||
}
|
||||
|
||||
public @NotNull WrappedVillager add(@NotNull Villager villager) {
|
||||
return add(new WrappedVillager(villager));
|
||||
return this.add(new WrappedVillager(villager));
|
||||
}
|
||||
|
||||
public boolean contains(@NotNull UUID uuid) {
|
||||
|
@ -19,14 +19,13 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
||||
public final class VillagerOptimizer extends JavaPlugin {
|
||||
|
||||
@ -118,56 +117,51 @@ public final class VillagerOptimizer extends JavaPlugin {
|
||||
languageCacheMap = new HashMap<>();
|
||||
ConsoleCommandSender console = getServer().getConsoleSender();
|
||||
try {
|
||||
File langDirectory = new File(getDataFolder() + "/lang");
|
||||
File langDirectory = new File(getDataFolder() + File.separator + "lang");
|
||||
Files.createDirectories(langDirectory.toPath());
|
||||
for (String fileName : getDefaultLanguageFiles()) {
|
||||
String localeString = fileName.substring(fileName.lastIndexOf('/') + 1, fileName.lastIndexOf('.'));
|
||||
final String localeString = fileName.substring(fileName.lastIndexOf(File.separator) + 1, fileName.lastIndexOf('.'));
|
||||
if (startup) console.sendMessage(
|
||||
Component.text("│ ").style(plugin_style)
|
||||
.append(Component.text(" "+localeString).color(NamedTextColor.WHITE).decorate(TextDecoration.BOLD))
|
||||
.append(Component.text(" │").style(plugin_style)));
|
||||
else logger.info("Found language file for " + localeString);
|
||||
LanguageCache langCache = new LanguageCache(localeString);
|
||||
languageCacheMap.put(localeString, langCache);
|
||||
.append(Component.text(" "+localeString).color(NamedTextColor.WHITE).decorate(TextDecoration.BOLD))
|
||||
.append(Component.text(" │").style(plugin_style)));
|
||||
else logger.info(String.format("Found language file for %s", localeString));
|
||||
languageCacheMap.put(localeString, new LanguageCache(localeString));
|
||||
}
|
||||
Pattern langPattern = Pattern.compile("([a-z]{1,3}_[a-z]{1,3})(\\.yml)", Pattern.CASE_INSENSITIVE);
|
||||
final Pattern langPattern = Pattern.compile("([a-z]{1,3}_[a-z]{1,3})(\\.yml)", Pattern.CASE_INSENSITIVE);
|
||||
for (File langFile : langDirectory.listFiles()) {
|
||||
Matcher langMatcher = langPattern.matcher(langFile.getName());
|
||||
final Matcher langMatcher = langPattern.matcher(langFile.getName());
|
||||
if (langMatcher.find()) {
|
||||
String localeString = langMatcher.group(1).toLowerCase();
|
||||
if (!languageCacheMap.containsKey(localeString)) { // make sure it wasn't a default file that we already loaded
|
||||
if (startup) console.sendMessage(
|
||||
Component.text("│ ").style(plugin_style)
|
||||
.append(Component.text(" "+localeString).color(NamedTextColor.WHITE).decorate(TextDecoration.BOLD))
|
||||
.append(Component.text(" │").style(plugin_style)));
|
||||
else logger.info("Found language file for " + localeString);
|
||||
LanguageCache langCache = new LanguageCache(localeString);
|
||||
languageCacheMap.put(localeString, langCache);
|
||||
.append(Component.text(" "+localeString).color(NamedTextColor.WHITE).decorate(TextDecoration.BOLD))
|
||||
.append(Component.text(" │").style(plugin_style)));
|
||||
else logger.info(String.format("Found language file for %s", localeString));
|
||||
languageCacheMap.put(localeString, new LanguageCache(localeString));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (startup) console.sendMessage(
|
||||
Component.text("│ ").style(plugin_style)
|
||||
.append(Component.text("LANG ERROR").color(NamedTextColor.RED).decorate(TextDecoration.BOLD))
|
||||
.append(Component.text(" │").style(plugin_style)));
|
||||
.append(Component.text("LANG ERROR").color(NamedTextColor.RED).decorate(TextDecoration.BOLD))
|
||||
.append(Component.text(" │").style(plugin_style)));
|
||||
else logger.severe("Error loading language files! Language files will not reload to avoid errors, make sure to correct this before restarting the server!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private Set<String> getDefaultLanguageFiles() {
|
||||
Set<String> languageFiles = new HashSet<>();
|
||||
try (JarFile jarFile = new JarFile(this.getFile())) {
|
||||
jarFile.entries().asIterator().forEachRemaining(jarFileEntry -> {
|
||||
final String path = jarFileEntry.getName();
|
||||
if (path.startsWith("lang/") && path.endsWith(".yml"))
|
||||
languageFiles.add(path);
|
||||
});
|
||||
try (final JarFile pluginJarFile = new JarFile(this.getFile())) {
|
||||
return pluginJarFile.stream()
|
||||
.map(ZipEntry::getName)
|
||||
.filter(name -> name.startsWith("lang" + File.separator) && name.endsWith(".yml"))
|
||||
.collect(Collectors.toSet());
|
||||
} catch (IOException e) {
|
||||
logger.severe("Error while getting default language files! - " + e.getLocalizedMessage());
|
||||
e.printStackTrace();
|
||||
logger.severe("Failed getting default lang files! - "+e.getLocalizedMessage());
|
||||
return Collections.emptySet();
|
||||
}
|
||||
return languageFiles;
|
||||
}
|
||||
}
|
||||
|
@ -18,58 +18,58 @@ public class Config {
|
||||
public final long cache_keep_time_seconds;
|
||||
|
||||
public Config() throws Exception {
|
||||
this.config = loadConfig(new File(VillagerOptimizer.getInstance().getDataFolder(), "config.yml"));
|
||||
// Create plugin folder first if it does not exist yet
|
||||
File pluginFolder = VillagerOptimizer.getInstance().getDataFolder();
|
||||
if (!pluginFolder.exists() && !pluginFolder.mkdir())
|
||||
VillagerOptimizer.getLog().severe("Failed to create plugin directory.");
|
||||
// Load config.yml with ConfigMaster
|
||||
this.config = ConfigFile.loadConfig(new File(pluginFolder, "config.yml"));
|
||||
|
||||
structureConfig();
|
||||
|
||||
this.default_lang = Locale.forLanguageTag(
|
||||
getString("general.default-language", "en_us",
|
||||
"The default language that will be used if auto-language is false or no matching language file was found.")
|
||||
.replace("_", "-"));
|
||||
.replace("_", "-"));
|
||||
this.auto_lang = getBoolean("general.auto-language", true,
|
||||
"If set to true, will display messages based on client language");
|
||||
this.cache_keep_time_seconds = getInt("general.cache-keep-time-seconds", 30,
|
||||
"The amount of time in seconds a villager will be kept in the plugin's cache.");
|
||||
}
|
||||
|
||||
private ConfigFile loadConfig(File ymlFile) throws Exception {
|
||||
File parent = ymlFile.getParentFile();
|
||||
if (!parent.exists() && !parent.mkdir())
|
||||
VillagerOptimizer.getLog().severe("Unable to create plugin config directory.");
|
||||
return ConfigFile.loadConfig(ymlFile);
|
||||
}
|
||||
|
||||
public void saveConfig() {
|
||||
try {
|
||||
config.save();
|
||||
this.config.save();
|
||||
} catch (Exception e) {
|
||||
VillagerOptimizer.getLog().severe("Failed to save config file! - " + e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void structureConfig() {
|
||||
config.addDefault("config-version", 1.00);
|
||||
createTitledSection("General", "general");
|
||||
createTitledSection("Optimization", "optimization-methods");
|
||||
config.addDefault("optimization-methods.commands.unoptimizevillagers", null);
|
||||
config.addComment("optimization-methods.commands", """
|
||||
this.config.addDefault("config-version", 1.00);
|
||||
this.createTitledSection("General", "general");
|
||||
this.createTitledSection("Optimization", "optimization-methods");
|
||||
this.config.addDefault("optimization-methods.commands.unoptimizevillagers", null);
|
||||
this.config.addComment("optimization-methods.commands", """
|
||||
If you want to disable commands, negate the following permissions:\s
|
||||
villageroptimizer.cmd.optimize\s
|
||||
villageroptimizer.cmd.unoptimize
|
||||
""");
|
||||
config.addDefault("optimization-methods.nametag-optimization.enable", true);
|
||||
createTitledSection("Villager Chunk Limit", "villager-chunk-limit");
|
||||
createTitledSection("Gameplay", "gameplay");
|
||||
config.addDefault("gameplay.restock-optimized-trades", null);
|
||||
config.addDefault("gameplay.level-optimized-profession", null);
|
||||
config.addDefault("gameplay.rename-optimized-villagers.enable", true);
|
||||
config.addDefault("gameplay.villagers-spawn-as-adults.enable", false);
|
||||
config.addDefault("gameplay.prevent-trading-with-unoptimized.enable", false);
|
||||
config.addDefault("gameplay.prevent-entities-from-targeting-optimized.enable", true);
|
||||
config.addDefault("gameplay.prevent-damage-to-optimized.enable", true);
|
||||
this.config.addDefault("optimization-methods.nametag-optimization.enable", true);
|
||||
this.createTitledSection("Villager Chunk Limit", "villager-chunk-limit");
|
||||
this.createTitledSection("Gameplay", "gameplay");
|
||||
this.config.addDefault("gameplay.restock-optimized-trades", null);
|
||||
this.config.addDefault("gameplay.level-optimized-profession", null);
|
||||
this.config.addDefault("gameplay.rename-optimized-villagers.enable", true);
|
||||
this.config.addDefault("gameplay.villagers-spawn-as-adults.enable", false);
|
||||
this.config.addDefault("gameplay.prevent-trading-with-unoptimized.enable", false);
|
||||
this.config.addDefault("gameplay.prevent-entities-from-targeting-optimized.enable", true);
|
||||
this.config.addDefault("gameplay.prevent-damage-to-optimized.enable", true);
|
||||
}
|
||||
|
||||
public void createTitledSection(@NotNull String title, @NotNull String path) {
|
||||
config.addSection(title);
|
||||
config.addDefault(path, null);
|
||||
this.config.addSection(title);
|
||||
this.config.addDefault(path, null);
|
||||
}
|
||||
|
||||
public @NotNull ConfigFile master() {
|
||||
@ -77,70 +77,70 @@ public class Config {
|
||||
}
|
||||
|
||||
public boolean getBoolean(@NotNull String path, boolean def, @NotNull String comment) {
|
||||
config.addDefault(path, def, comment);
|
||||
return config.getBoolean(path, def);
|
||||
this.config.addDefault(path, def, comment);
|
||||
return this.config.getBoolean(path, def);
|
||||
}
|
||||
|
||||
public boolean getBoolean(@NotNull String path, boolean def) {
|
||||
config.addDefault(path, def);
|
||||
return config.getBoolean(path, def);
|
||||
this.config.addDefault(path, def);
|
||||
return this.config.getBoolean(path, def);
|
||||
}
|
||||
|
||||
public @NotNull String getString(@NotNull String path, @NotNull String def, @NotNull String comment) {
|
||||
config.addDefault(path, def, comment);
|
||||
return config.getString(path, def);
|
||||
this.config.addDefault(path, def, comment);
|
||||
return this.config.getString(path, def);
|
||||
}
|
||||
|
||||
public @NotNull String getString(@NotNull String path, @NotNull String def) {
|
||||
config.addDefault(path, def);
|
||||
return config.getString(path, def);
|
||||
this.config.addDefault(path, def);
|
||||
return this.config.getString(path, def);
|
||||
}
|
||||
|
||||
public double getDouble(@NotNull String path, @NotNull Double def, @NotNull String comment) {
|
||||
config.addDefault(path, def, comment);
|
||||
return config.getDouble(path, def);
|
||||
this.config.addDefault(path, def, comment);
|
||||
return this.config.getDouble(path, def);
|
||||
}
|
||||
|
||||
public double getDouble(@NotNull String path, @NotNull Double def) {
|
||||
config.addDefault(path, def);
|
||||
return config.getDouble(path, def);
|
||||
this.config.addDefault(path, def);
|
||||
return this.config.getDouble(path, def);
|
||||
}
|
||||
|
||||
public int getInt(@NotNull String path, int def, @NotNull String comment) {
|
||||
config.addDefault(path, def, comment);
|
||||
return config.getInteger(path, def);
|
||||
this.config.addDefault(path, def, comment);
|
||||
return this.config.getInteger(path, def);
|
||||
}
|
||||
|
||||
public int getInt(@NotNull String path, int def) {
|
||||
config.addDefault(path, def);
|
||||
return config.getInteger(path, def);
|
||||
this.config.addDefault(path, def);
|
||||
return this.config.getInteger(path, def);
|
||||
}
|
||||
|
||||
public @NotNull List<String> getList(@NotNull String path, @NotNull List<String> def, @NotNull String comment) {
|
||||
config.addDefault(path, def, comment);
|
||||
return config.getStringList(path);
|
||||
this.config.addDefault(path, def, comment);
|
||||
return this.config.getStringList(path);
|
||||
}
|
||||
|
||||
public @NotNull List<String> getList(@NotNull String path, @NotNull List<String> def) {
|
||||
config.addDefault(path, def);
|
||||
return config.getStringList(path);
|
||||
this.config.addDefault(path, def);
|
||||
return this.config.getStringList(path);
|
||||
}
|
||||
|
||||
public @NotNull ConfigSection getConfigSection(@NotNull String path, @NotNull Map<String, Object> defaultKeyValue) {
|
||||
config.addDefault(path, null);
|
||||
config.makeSectionLenient(path);
|
||||
defaultKeyValue.forEach((string, object) -> config.addExample(path+"."+string, object));
|
||||
return config.getConfigSection(path);
|
||||
this.config.addDefault(path, null);
|
||||
this.config.makeSectionLenient(path);
|
||||
defaultKeyValue.forEach((string, object) -> this.config.addExample(path+"."+string, object));
|
||||
return this.config.getConfigSection(path);
|
||||
}
|
||||
|
||||
public @NotNull ConfigSection getConfigSection(@NotNull String path, @NotNull Map<String, Object> defaultKeyValue, @NotNull String comment) {
|
||||
config.addDefault(path, null, comment);
|
||||
config.makeSectionLenient(path);
|
||||
defaultKeyValue.forEach((string, object) -> config.addExample(path+"."+string, object));
|
||||
return config.getConfigSection(path);
|
||||
this.config.addDefault(path, null, comment);
|
||||
this.config.makeSectionLenient(path);
|
||||
defaultKeyValue.forEach((string, object) -> this.config.addExample(path+"."+string, object));
|
||||
return this.config.getConfigSection(path);
|
||||
}
|
||||
|
||||
public void addComment(@NotNull String path, @NotNull String comment) {
|
||||
config.addComment(path, comment);
|
||||
this.config.addComment(path, comment);
|
||||
}
|
||||
}
|
||||
}
|
@ -27,7 +27,7 @@ public class LanguageCache {
|
||||
// Check if the lang folder has already been created
|
||||
File parent = langYML.getParentFile();
|
||||
if (!parent.exists() && !parent.mkdir())
|
||||
VillagerOptimizer.getLog().severe("Unable to create lang directory.");
|
||||
VillagerOptimizer.getLog().severe("Failed to create lang directory.");
|
||||
// Check if the file already exists and save the one from the plugins resources folder if it does not
|
||||
if (!langYML.exists())
|
||||
plugin.saveResource("lang/" + locale + ".yml", false);
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>me.xginko.VillagerOptimizer</groupId>
|
||||
<artifactId>VillagerOptimizer</artifactId>
|
||||
<version>1.0.1</version>
|
||||
<version>1.0.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>1.20.2</artifactId>
|
||||
|
@ -39,7 +39,7 @@ public final class VillagerCache {
|
||||
}
|
||||
|
||||
public @NotNull WrappedVillager add(@NotNull Villager villager) {
|
||||
return add(new WrappedVillager(villager));
|
||||
return this.add(new WrappedVillager(villager));
|
||||
}
|
||||
|
||||
public boolean contains(@NotNull UUID uuid) {
|
||||
|
@ -19,14 +19,13 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
||||
public final class VillagerOptimizer extends JavaPlugin {
|
||||
|
||||
@ -118,56 +117,51 @@ public final class VillagerOptimizer extends JavaPlugin {
|
||||
languageCacheMap = new HashMap<>();
|
||||
ConsoleCommandSender console = getServer().getConsoleSender();
|
||||
try {
|
||||
File langDirectory = new File(getDataFolder() + "/lang");
|
||||
File langDirectory = new File(getDataFolder() + File.separator + "lang");
|
||||
Files.createDirectories(langDirectory.toPath());
|
||||
for (String fileName : getDefaultLanguageFiles()) {
|
||||
String localeString = fileName.substring(fileName.lastIndexOf('/') + 1, fileName.lastIndexOf('.'));
|
||||
final String localeString = fileName.substring(fileName.lastIndexOf(File.separator) + 1, fileName.lastIndexOf('.'));
|
||||
if (startup) console.sendMessage(
|
||||
Component.text("│ ").style(plugin_style)
|
||||
.append(Component.text(" "+localeString).color(NamedTextColor.WHITE).decorate(TextDecoration.BOLD))
|
||||
.append(Component.text(" │").style(plugin_style)));
|
||||
else logger.info("Found language file for " + localeString);
|
||||
LanguageCache langCache = new LanguageCache(localeString);
|
||||
languageCacheMap.put(localeString, langCache);
|
||||
.append(Component.text(" "+localeString).color(NamedTextColor.WHITE).decorate(TextDecoration.BOLD))
|
||||
.append(Component.text(" │").style(plugin_style)));
|
||||
else logger.info(String.format("Found language file for %s", localeString));
|
||||
languageCacheMap.put(localeString, new LanguageCache(localeString));
|
||||
}
|
||||
Pattern langPattern = Pattern.compile("([a-z]{1,3}_[a-z]{1,3})(\\.yml)", Pattern.CASE_INSENSITIVE);
|
||||
final Pattern langPattern = Pattern.compile("([a-z]{1,3}_[a-z]{1,3})(\\.yml)", Pattern.CASE_INSENSITIVE);
|
||||
for (File langFile : langDirectory.listFiles()) {
|
||||
Matcher langMatcher = langPattern.matcher(langFile.getName());
|
||||
final Matcher langMatcher = langPattern.matcher(langFile.getName());
|
||||
if (langMatcher.find()) {
|
||||
String localeString = langMatcher.group(1).toLowerCase();
|
||||
if (!languageCacheMap.containsKey(localeString)) { // make sure it wasn't a default file that we already loaded
|
||||
if (startup) console.sendMessage(
|
||||
Component.text("│ ").style(plugin_style)
|
||||
.append(Component.text(" "+localeString).color(NamedTextColor.WHITE).decorate(TextDecoration.BOLD))
|
||||
.append(Component.text(" │").style(plugin_style)));
|
||||
else logger.info("Found language file for " + localeString);
|
||||
LanguageCache langCache = new LanguageCache(localeString);
|
||||
languageCacheMap.put(localeString, langCache);
|
||||
.append(Component.text(" "+localeString).color(NamedTextColor.WHITE).decorate(TextDecoration.BOLD))
|
||||
.append(Component.text(" │").style(plugin_style)));
|
||||
else logger.info(String.format("Found language file for %s", localeString));
|
||||
languageCacheMap.put(localeString, new LanguageCache(localeString));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (startup) console.sendMessage(
|
||||
Component.text("│ ").style(plugin_style)
|
||||
.append(Component.text("LANG ERROR").color(NamedTextColor.RED).decorate(TextDecoration.BOLD))
|
||||
.append(Component.text(" │").style(plugin_style)));
|
||||
.append(Component.text("LANG ERROR").color(NamedTextColor.RED).decorate(TextDecoration.BOLD))
|
||||
.append(Component.text(" │").style(plugin_style)));
|
||||
else logger.severe("Error loading language files! Language files will not reload to avoid errors, make sure to correct this before restarting the server!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private Set<String> getDefaultLanguageFiles() {
|
||||
Set<String> languageFiles = new HashSet<>();
|
||||
try (JarFile jarFile = new JarFile(this.getFile())) {
|
||||
jarFile.entries().asIterator().forEachRemaining(jarFileEntry -> {
|
||||
final String path = jarFileEntry.getName();
|
||||
if (path.startsWith("lang/") && path.endsWith(".yml"))
|
||||
languageFiles.add(path);
|
||||
});
|
||||
try (final JarFile pluginJarFile = new JarFile(this.getFile())) {
|
||||
return pluginJarFile.stream()
|
||||
.map(ZipEntry::getName)
|
||||
.filter(name -> name.startsWith("lang" + File.separator) && name.endsWith(".yml"))
|
||||
.collect(Collectors.toSet());
|
||||
} catch (IOException e) {
|
||||
logger.severe("Error while getting default language files! - " + e.getLocalizedMessage());
|
||||
e.printStackTrace();
|
||||
logger.severe("Failed getting default lang files! - "+e.getLocalizedMessage());
|
||||
return Collections.emptySet();
|
||||
}
|
||||
return languageFiles;
|
||||
}
|
||||
}
|
||||
|
@ -18,58 +18,58 @@ public class Config {
|
||||
public final long cache_keep_time_seconds;
|
||||
|
||||
public Config() throws Exception {
|
||||
this.config = loadConfig(new File(VillagerOptimizer.getInstance().getDataFolder(), "config.yml"));
|
||||
// Create plugin folder first if it does not exist yet
|
||||
File pluginFolder = VillagerOptimizer.getInstance().getDataFolder();
|
||||
if (!pluginFolder.exists() && !pluginFolder.mkdir())
|
||||
VillagerOptimizer.getLog().severe("Failed to create plugin directory.");
|
||||
// Load config.yml with ConfigMaster
|
||||
this.config = ConfigFile.loadConfig(new File(pluginFolder, "config.yml"));
|
||||
|
||||
structureConfig();
|
||||
|
||||
this.default_lang = Locale.forLanguageTag(
|
||||
getString("general.default-language", "en_us",
|
||||
"The default language that will be used if auto-language is false or no matching language file was found.")
|
||||
.replace("_", "-"));
|
||||
.replace("_", "-"));
|
||||
this.auto_lang = getBoolean("general.auto-language", true,
|
||||
"If set to true, will display messages based on client language");
|
||||
this.cache_keep_time_seconds = getInt("general.cache-keep-time-seconds", 30,
|
||||
"The amount of time in seconds a villager will be kept in the plugin's cache.");
|
||||
}
|
||||
|
||||
private ConfigFile loadConfig(File ymlFile) throws Exception {
|
||||
File parent = ymlFile.getParentFile();
|
||||
if (!parent.exists() && !parent.mkdir())
|
||||
VillagerOptimizer.getLog().severe("Unable to create plugin config directory.");
|
||||
return ConfigFile.loadConfig(ymlFile);
|
||||
}
|
||||
|
||||
public void saveConfig() {
|
||||
try {
|
||||
config.save();
|
||||
this.config.save();
|
||||
} catch (Exception e) {
|
||||
VillagerOptimizer.getLog().severe("Failed to save config file! - " + e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void structureConfig() {
|
||||
config.addDefault("config-version", 1.00);
|
||||
createTitledSection("General", "general");
|
||||
createTitledSection("Optimization", "optimization-methods");
|
||||
config.addDefault("optimization-methods.commands.unoptimizevillagers", null);
|
||||
config.addComment("optimization-methods.commands", """
|
||||
this.config.addDefault("config-version", 1.00);
|
||||
this.createTitledSection("General", "general");
|
||||
this.createTitledSection("Optimization", "optimization-methods");
|
||||
this.config.addDefault("optimization-methods.commands.unoptimizevillagers", null);
|
||||
this.config.addComment("optimization-methods.commands", """
|
||||
If you want to disable commands, negate the following permissions:\s
|
||||
villageroptimizer.cmd.optimize\s
|
||||
villageroptimizer.cmd.unoptimize
|
||||
""");
|
||||
config.addDefault("optimization-methods.nametag-optimization.enable", true);
|
||||
createTitledSection("Villager Chunk Limit", "villager-chunk-limit");
|
||||
createTitledSection("Gameplay", "gameplay");
|
||||
config.addDefault("gameplay.restock-optimized-trades", null);
|
||||
config.addDefault("gameplay.level-optimized-profession", null);
|
||||
config.addDefault("gameplay.rename-optimized-villagers.enable", true);
|
||||
config.addDefault("gameplay.villagers-spawn-as-adults.enable", false);
|
||||
config.addDefault("gameplay.prevent-trading-with-unoptimized.enable", false);
|
||||
config.addDefault("gameplay.prevent-entities-from-targeting-optimized.enable", true);
|
||||
config.addDefault("gameplay.prevent-damage-to-optimized.enable", true);
|
||||
this.config.addDefault("optimization-methods.nametag-optimization.enable", true);
|
||||
this.createTitledSection("Villager Chunk Limit", "villager-chunk-limit");
|
||||
this.createTitledSection("Gameplay", "gameplay");
|
||||
this.config.addDefault("gameplay.restock-optimized-trades", null);
|
||||
this.config.addDefault("gameplay.level-optimized-profession", null);
|
||||
this.config.addDefault("gameplay.rename-optimized-villagers.enable", true);
|
||||
this.config.addDefault("gameplay.villagers-spawn-as-adults.enable", false);
|
||||
this.config.addDefault("gameplay.prevent-trading-with-unoptimized.enable", false);
|
||||
this.config.addDefault("gameplay.prevent-entities-from-targeting-optimized.enable", true);
|
||||
this.config.addDefault("gameplay.prevent-damage-to-optimized.enable", true);
|
||||
}
|
||||
|
||||
public void createTitledSection(@NotNull String title, @NotNull String path) {
|
||||
config.addSection(title);
|
||||
config.addDefault(path, null);
|
||||
this.config.addSection(title);
|
||||
this.config.addDefault(path, null);
|
||||
}
|
||||
|
||||
public @NotNull ConfigFile master() {
|
||||
@ -77,70 +77,70 @@ public class Config {
|
||||
}
|
||||
|
||||
public boolean getBoolean(@NotNull String path, boolean def, @NotNull String comment) {
|
||||
config.addDefault(path, def, comment);
|
||||
return config.getBoolean(path, def);
|
||||
this.config.addDefault(path, def, comment);
|
||||
return this.config.getBoolean(path, def);
|
||||
}
|
||||
|
||||
public boolean getBoolean(@NotNull String path, boolean def) {
|
||||
config.addDefault(path, def);
|
||||
return config.getBoolean(path, def);
|
||||
this.config.addDefault(path, def);
|
||||
return this.config.getBoolean(path, def);
|
||||
}
|
||||
|
||||
public @NotNull String getString(@NotNull String path, @NotNull String def, @NotNull String comment) {
|
||||
config.addDefault(path, def, comment);
|
||||
return config.getString(path, def);
|
||||
this.config.addDefault(path, def, comment);
|
||||
return this.config.getString(path, def);
|
||||
}
|
||||
|
||||
public @NotNull String getString(@NotNull String path, @NotNull String def) {
|
||||
config.addDefault(path, def);
|
||||
return config.getString(path, def);
|
||||
this.config.addDefault(path, def);
|
||||
return this.config.getString(path, def);
|
||||
}
|
||||
|
||||
public double getDouble(@NotNull String path, @NotNull Double def, @NotNull String comment) {
|
||||
config.addDefault(path, def, comment);
|
||||
return config.getDouble(path, def);
|
||||
this.config.addDefault(path, def, comment);
|
||||
return this.config.getDouble(path, def);
|
||||
}
|
||||
|
||||
public double getDouble(@NotNull String path, @NotNull Double def) {
|
||||
config.addDefault(path, def);
|
||||
return config.getDouble(path, def);
|
||||
this.config.addDefault(path, def);
|
||||
return this.config.getDouble(path, def);
|
||||
}
|
||||
|
||||
public int getInt(@NotNull String path, int def, @NotNull String comment) {
|
||||
config.addDefault(path, def, comment);
|
||||
return config.getInteger(path, def);
|
||||
this.config.addDefault(path, def, comment);
|
||||
return this.config.getInteger(path, def);
|
||||
}
|
||||
|
||||
public int getInt(@NotNull String path, int def) {
|
||||
config.addDefault(path, def);
|
||||
return config.getInteger(path, def);
|
||||
this.config.addDefault(path, def);
|
||||
return this.config.getInteger(path, def);
|
||||
}
|
||||
|
||||
public @NotNull List<String> getList(@NotNull String path, @NotNull List<String> def, @NotNull String comment) {
|
||||
config.addDefault(path, def, comment);
|
||||
return config.getStringList(path);
|
||||
this.config.addDefault(path, def, comment);
|
||||
return this.config.getStringList(path);
|
||||
}
|
||||
|
||||
public @NotNull List<String> getList(@NotNull String path, @NotNull List<String> def) {
|
||||
config.addDefault(path, def);
|
||||
return config.getStringList(path);
|
||||
this.config.addDefault(path, def);
|
||||
return this.config.getStringList(path);
|
||||
}
|
||||
|
||||
public @NotNull ConfigSection getConfigSection(@NotNull String path, @NotNull Map<String, Object> defaultKeyValue) {
|
||||
config.addDefault(path, null);
|
||||
config.makeSectionLenient(path);
|
||||
defaultKeyValue.forEach((string, object) -> config.addExample(path+"."+string, object));
|
||||
return config.getConfigSection(path);
|
||||
this.config.addDefault(path, null);
|
||||
this.config.makeSectionLenient(path);
|
||||
defaultKeyValue.forEach((string, object) -> this.config.addExample(path+"."+string, object));
|
||||
return this.config.getConfigSection(path);
|
||||
}
|
||||
|
||||
public @NotNull ConfigSection getConfigSection(@NotNull String path, @NotNull Map<String, Object> defaultKeyValue, @NotNull String comment) {
|
||||
config.addDefault(path, null, comment);
|
||||
config.makeSectionLenient(path);
|
||||
defaultKeyValue.forEach((string, object) -> config.addExample(path+"."+string, object));
|
||||
return config.getConfigSection(path);
|
||||
this.config.addDefault(path, null, comment);
|
||||
this.config.makeSectionLenient(path);
|
||||
defaultKeyValue.forEach((string, object) -> this.config.addExample(path+"."+string, object));
|
||||
return this.config.getConfigSection(path);
|
||||
}
|
||||
|
||||
public void addComment(@NotNull String path, @NotNull String comment) {
|
||||
config.addComment(path, comment);
|
||||
this.config.addComment(path, comment);
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public class LanguageCache {
|
||||
// Check if the lang folder has already been created
|
||||
File parent = langYML.getParentFile();
|
||||
if (!parent.exists() && !parent.mkdir())
|
||||
VillagerOptimizer.getLog().severe("Unable to create lang directory.");
|
||||
VillagerOptimizer.getLog().severe("Failed to create lang directory.");
|
||||
// Check if the file already exists and save the one from the plugins resources folder if it does not
|
||||
if (!langYML.exists())
|
||||
plugin.saveResource("lang/" + locale + ".yml", false);
|
||||
|
Loading…
x
Reference in New Issue
Block a user