fix language loader
This commit is contained in:
parent
19d223a16c
commit
d66155ec87
@ -7,7 +7,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>me.xginko.VillagerOptimizer</groupId>
|
<groupId>me.xginko.VillagerOptimizer</groupId>
|
||||||
<artifactId>VillagerOptimizer</artifactId>
|
<artifactId>VillagerOptimizer</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>1.16.5</artifactId>
|
<artifactId>1.16.5</artifactId>
|
||||||
|
@ -126,7 +126,7 @@ public final class VillagerOptimizer extends JavaPlugin {
|
|||||||
Component.text("│ ").style(plugin_style)
|
Component.text("│ ").style(plugin_style)
|
||||||
.append(Component.text(" "+localeString).color(NamedTextColor.WHITE).decorate(TextDecoration.BOLD))
|
.append(Component.text(" "+localeString).color(NamedTextColor.WHITE).decorate(TextDecoration.BOLD))
|
||||||
.append(Component.text(" │").style(plugin_style)));
|
.append(Component.text(" │").style(plugin_style)));
|
||||||
else logger.info(String.format("Found language file for %s", localeString));
|
else logger.info("Found language file for " + localeString);
|
||||||
LanguageCache langCache = new LanguageCache(localeString);
|
LanguageCache langCache = new LanguageCache(localeString);
|
||||||
languageCacheMap.put(localeString, langCache);
|
languageCacheMap.put(localeString, langCache);
|
||||||
}
|
}
|
||||||
@ -140,7 +140,7 @@ public final class VillagerOptimizer extends JavaPlugin {
|
|||||||
Component.text("│ ").style(plugin_style)
|
Component.text("│ ").style(plugin_style)
|
||||||
.append(Component.text(" "+localeString).color(NamedTextColor.WHITE).decorate(TextDecoration.BOLD))
|
.append(Component.text(" "+localeString).color(NamedTextColor.WHITE).decorate(TextDecoration.BOLD))
|
||||||
.append(Component.text(" │").style(plugin_style)));
|
.append(Component.text(" │").style(plugin_style)));
|
||||||
else logger.info(String.format("Found language file for %s", localeString));
|
else logger.info("Found language file for " + localeString);
|
||||||
LanguageCache langCache = new LanguageCache(localeString);
|
LanguageCache langCache = new LanguageCache(localeString);
|
||||||
languageCacheMap.put(localeString, langCache);
|
languageCacheMap.put(localeString, langCache);
|
||||||
}
|
}
|
||||||
|
@ -56,84 +56,85 @@ public class OptVillagersRadius implements VillagerOptimizerCommand, TabComplete
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sender.hasPermission(Permissions.Commands.OPTIMIZE_RADIUS.get())) {
|
if (!sender.hasPermission(Permissions.Commands.OPTIMIZE_RADIUS.get())) {
|
||||||
if (args.length != 1) {
|
sender.sendMessage(VillagerOptimizer.getLang(sender).no_permission);
|
||||||
VillagerOptimizer.getLang(player.locale()).command_specify_radius.forEach(player::sendMessage);
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length != 1) {
|
||||||
|
VillagerOptimizer.getLang(player.locale()).command_specify_radius.forEach(player::sendMessage);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
int specifiedRadius = Integer.parseInt(args[0]);
|
||||||
|
|
||||||
|
if (specifiedRadius > max_radius) {
|
||||||
|
final TextReplacementConfig limit = TextReplacementConfig.builder()
|
||||||
|
.matchLiteral("%distance%")
|
||||||
|
.replacement(Integer.toString(max_radius))
|
||||||
|
.build();
|
||||||
|
VillagerOptimizer.getLang(player.locale()).command_radius_limit_exceed.forEach(line -> player.sendMessage(line.replaceText(limit)));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
VillagerCache villagerCache = VillagerOptimizer.getCache();
|
||||||
int specifiedRadius = Integer.parseInt(args[0]);
|
int successCount = 0;
|
||||||
|
int failCount = 0;
|
||||||
|
final boolean player_has_cooldown_bypass = player.hasPermission(Permissions.Bypass.COMMAND_COOLDOWN.get());
|
||||||
|
|
||||||
if (specifiedRadius > max_radius) {
|
for (Entity entity : player.getNearbyEntities(specifiedRadius, specifiedRadius, specifiedRadius)) {
|
||||||
final TextReplacementConfig limit = TextReplacementConfig.builder()
|
if (!entity.getType().equals(EntityType.VILLAGER)) continue;
|
||||||
.matchLiteral("%distance%")
|
Villager villager = (Villager) entity;
|
||||||
.replacement(Integer.toString(max_radius))
|
Villager.Profession profession = villager.getProfession();
|
||||||
.build();
|
if (profession.equals(Villager.Profession.NITWIT) || profession.equals(Villager.Profession.NONE)) continue;
|
||||||
VillagerOptimizer.getLang(player.locale()).command_radius_limit_exceed.forEach(line -> player.sendMessage(line.replaceText(limit)));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
VillagerCache villagerCache = VillagerOptimizer.getCache();
|
WrappedVillager wVillager = villagerCache.getOrAdd(villager);
|
||||||
int successCount = 0;
|
|
||||||
int failCount = 0;
|
|
||||||
final boolean player_has_cooldown_bypass = player.hasPermission(Permissions.Bypass.COMMAND_COOLDOWN.get());
|
|
||||||
|
|
||||||
for (Entity entity : player.getNearbyEntities(specifiedRadius, specifiedRadius, specifiedRadius)) {
|
if (player_has_cooldown_bypass || wVillager.canOptimize(cooldown)) {
|
||||||
if (!entity.getType().equals(EntityType.VILLAGER)) continue;
|
VillagerOptimizeEvent optimizeEvent = new VillagerOptimizeEvent(wVillager, OptimizationType.COMMAND, player);
|
||||||
Villager villager = (Villager) entity;
|
if (optimizeEvent.callEvent()) {
|
||||||
Villager.Profession profession = villager.getProfession();
|
wVillager.setOptimization(optimizeEvent.getOptimizationType());
|
||||||
if (profession.equals(Villager.Profession.NITWIT) || profession.equals(Villager.Profession.NONE)) continue;
|
wVillager.saveOptimizeTime();
|
||||||
|
successCount++;
|
||||||
WrappedVillager wVillager = villagerCache.getOrAdd(villager);
|
|
||||||
|
|
||||||
if (player_has_cooldown_bypass || wVillager.canOptimize(cooldown)) {
|
|
||||||
VillagerOptimizeEvent optimizeEvent = new VillagerOptimizeEvent(wVillager, OptimizationType.COMMAND, player);
|
|
||||||
if (optimizeEvent.callEvent()) {
|
|
||||||
wVillager.setOptimization(optimizeEvent.getOptimizationType());
|
|
||||||
wVillager.saveOptimizeTime();
|
|
||||||
successCount++;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
failCount++;
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
failCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (successCount <= 0 && failCount <= 0) {
|
|
||||||
final TextReplacementConfig radius = TextReplacementConfig.builder()
|
|
||||||
.matchLiteral("%radius%")
|
|
||||||
.replacement(Integer.toString(specifiedRadius))
|
|
||||||
.build();
|
|
||||||
VillagerOptimizer.getLang(player.locale()).command_no_villagers_nearby.forEach(line -> player.sendMessage(line.replaceText(radius)));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (successCount > 0) {
|
|
||||||
final TextReplacementConfig success_amount = TextReplacementConfig.builder()
|
|
||||||
.matchLiteral("%amount%")
|
|
||||||
.replacement(Integer.toString(successCount))
|
|
||||||
.build();
|
|
||||||
final TextReplacementConfig radius = TextReplacementConfig.builder()
|
|
||||||
.matchLiteral("%radius%")
|
|
||||||
.replacement(Integer.toString(specifiedRadius))
|
|
||||||
.build();
|
|
||||||
VillagerOptimizer.getLang(player.locale()).command_optimize_success.forEach(line -> player.sendMessage(line
|
|
||||||
.replaceText(success_amount)
|
|
||||||
.replaceText(radius)
|
|
||||||
));
|
|
||||||
}
|
|
||||||
if (failCount > 0) {
|
|
||||||
final TextReplacementConfig alreadyOptimized = TextReplacementConfig.builder()
|
|
||||||
.matchLiteral("%amount%")
|
|
||||||
.replacement(Integer.toString(failCount))
|
|
||||||
.build();
|
|
||||||
VillagerOptimizer.getLang(player.locale()).command_optimize_fail.forEach(line -> player.sendMessage(line.replaceText(alreadyOptimized)));
|
|
||||||
}
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
VillagerOptimizer.getLang(player.locale()).command_radius_invalid.forEach(player::sendMessage);
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
sender.sendMessage(VillagerOptimizer.getLang(sender).no_permission);
|
if (successCount <= 0 && failCount <= 0) {
|
||||||
|
final TextReplacementConfig radius = TextReplacementConfig.builder()
|
||||||
|
.matchLiteral("%radius%")
|
||||||
|
.replacement(Integer.toString(specifiedRadius))
|
||||||
|
.build();
|
||||||
|
VillagerOptimizer.getLang(player.locale()).command_no_villagers_nearby.forEach(line -> player.sendMessage(line.replaceText(radius)));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (successCount > 0) {
|
||||||
|
final TextReplacementConfig success_amount = TextReplacementConfig.builder()
|
||||||
|
.matchLiteral("%amount%")
|
||||||
|
.replacement(Integer.toString(successCount))
|
||||||
|
.build();
|
||||||
|
final TextReplacementConfig radius = TextReplacementConfig.builder()
|
||||||
|
.matchLiteral("%radius%")
|
||||||
|
.replacement(Integer.toString(specifiedRadius))
|
||||||
|
.build();
|
||||||
|
VillagerOptimizer.getLang(player.locale()).command_optimize_success.forEach(line -> player.sendMessage(line
|
||||||
|
.replaceText(success_amount)
|
||||||
|
.replaceText(radius)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if (failCount > 0) {
|
||||||
|
final TextReplacementConfig alreadyOptimized = TextReplacementConfig.builder()
|
||||||
|
.matchLiteral("%amount%")
|
||||||
|
.replacement(Integer.toString(failCount))
|
||||||
|
.build();
|
||||||
|
VillagerOptimizer.getLang(player.locale()).command_optimize_fail.forEach(line -> player.sendMessage(line.replaceText(alreadyOptimized)));
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
VillagerOptimizer.getLang(player.locale()).command_radius_invalid.forEach(player::sendMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -50,69 +50,70 @@ public class UnOptVillagersRadius implements VillagerOptimizerCommand, TabComple
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sender.hasPermission(Permissions.Commands.UNOPTIMIZE_RADIUS.get())) {
|
if (!sender.hasPermission(Permissions.Commands.UNOPTIMIZE_RADIUS.get())) {
|
||||||
if (args.length != 1) {
|
sender.sendMessage(VillagerOptimizer.getLang(sender).no_permission);
|
||||||
VillagerOptimizer.getLang(player.locale()).command_specify_radius.forEach(player::sendMessage);
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length != 1) {
|
||||||
|
VillagerOptimizer.getLang(player.locale()).command_specify_radius.forEach(player::sendMessage);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
int specifiedRadius = Integer.parseInt(args[0]);
|
||||||
|
|
||||||
|
if (specifiedRadius > max_radius) {
|
||||||
|
final TextReplacementConfig limit = TextReplacementConfig.builder()
|
||||||
|
.matchLiteral("%distance%")
|
||||||
|
.replacement(Integer.toString(max_radius))
|
||||||
|
.build();
|
||||||
|
VillagerOptimizer.getLang(player.locale()).command_radius_limit_exceed.forEach(line -> player.sendMessage(line.replaceText(limit)));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
VillagerCache villagerCache = VillagerOptimizer.getCache();
|
||||||
int specifiedRadius = Integer.parseInt(args[0]);
|
int successCount = 0;
|
||||||
|
|
||||||
if (specifiedRadius > max_radius) {
|
for (Entity entity : player.getNearbyEntities(specifiedRadius, specifiedRadius, specifiedRadius)) {
|
||||||
final TextReplacementConfig limit = TextReplacementConfig.builder()
|
if (!entity.getType().equals(EntityType.VILLAGER)) continue;
|
||||||
.matchLiteral("%distance%")
|
Villager villager = (Villager) entity;
|
||||||
.replacement(Integer.toString(max_radius))
|
Villager.Profession profession = villager.getProfession();
|
||||||
.build();
|
if (profession.equals(Villager.Profession.NITWIT) || profession.equals(Villager.Profession.NONE)) continue;
|
||||||
VillagerOptimizer.getLang(player.locale()).command_radius_limit_exceed.forEach(line -> player.sendMessage(line.replaceText(limit)));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
VillagerCache villagerCache = VillagerOptimizer.getCache();
|
WrappedVillager wVillager = villagerCache.getOrAdd(villager);
|
||||||
int successCount = 0;
|
|
||||||
|
|
||||||
for (Entity entity : player.getNearbyEntities(specifiedRadius, specifiedRadius, specifiedRadius)) {
|
if (wVillager.isOptimized()) {
|
||||||
if (!entity.getType().equals(EntityType.VILLAGER)) continue;
|
VillagerUnoptimizeEvent unOptimizeEvent = new VillagerUnoptimizeEvent(wVillager, player, OptimizationType.COMMAND);
|
||||||
Villager villager = (Villager) entity;
|
if (unOptimizeEvent.callEvent()) {
|
||||||
Villager.Profession profession = villager.getProfession();
|
wVillager.setOptimization(OptimizationType.NONE);
|
||||||
if (profession.equals(Villager.Profession.NITWIT) || profession.equals(Villager.Profession.NONE)) continue;
|
successCount++;
|
||||||
|
|
||||||
WrappedVillager wVillager = villagerCache.getOrAdd(villager);
|
|
||||||
|
|
||||||
if (wVillager.isOptimized()) {
|
|
||||||
VillagerUnoptimizeEvent unOptimizeEvent = new VillagerUnoptimizeEvent(wVillager, player, OptimizationType.COMMAND);
|
|
||||||
if (unOptimizeEvent.callEvent()) {
|
|
||||||
wVillager.setOptimization(OptimizationType.NONE);
|
|
||||||
successCount++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (successCount <= 0) {
|
|
||||||
final TextReplacementConfig radius = TextReplacementConfig.builder()
|
|
||||||
.matchLiteral("%radius%")
|
|
||||||
.replacement(Integer.toString(specifiedRadius))
|
|
||||||
.build();
|
|
||||||
VillagerOptimizer.getLang(player.locale()).command_no_villagers_nearby.forEach(line -> player.sendMessage(line.replaceText(radius)));
|
|
||||||
} else {
|
|
||||||
final TextReplacementConfig success_amount = TextReplacementConfig.builder()
|
|
||||||
.matchLiteral("%amount%")
|
|
||||||
.replacement(Integer.toString(successCount))
|
|
||||||
.build();
|
|
||||||
final TextReplacementConfig radius = TextReplacementConfig.builder()
|
|
||||||
.matchLiteral("%radius%")
|
|
||||||
.replacement(Integer.toString(specifiedRadius))
|
|
||||||
.build();
|
|
||||||
VillagerOptimizer.getLang(player.locale()).command_unoptimize_success.forEach(line -> player.sendMessage(line
|
|
||||||
.replaceText(success_amount)
|
|
||||||
.replaceText(radius)
|
|
||||||
));
|
|
||||||
}
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
VillagerOptimizer.getLang(player.locale()).command_radius_invalid.forEach(player::sendMessage);
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
sender.sendMessage(VillagerOptimizer.getLang(sender).no_permission);
|
if (successCount <= 0) {
|
||||||
|
final TextReplacementConfig radius = TextReplacementConfig.builder()
|
||||||
|
.matchLiteral("%radius%")
|
||||||
|
.replacement(Integer.toString(specifiedRadius))
|
||||||
|
.build();
|
||||||
|
VillagerOptimizer.getLang(player.locale()).command_no_villagers_nearby.forEach(line -> player.sendMessage(line.replaceText(radius)));
|
||||||
|
} else {
|
||||||
|
final TextReplacementConfig success_amount = TextReplacementConfig.builder()
|
||||||
|
.matchLiteral("%amount%")
|
||||||
|
.replacement(Integer.toString(successCount))
|
||||||
|
.build();
|
||||||
|
final TextReplacementConfig radius = TextReplacementConfig.builder()
|
||||||
|
.matchLiteral("%radius%")
|
||||||
|
.replacement(Integer.toString(specifiedRadius))
|
||||||
|
.build();
|
||||||
|
VillagerOptimizer.getLang(player.locale()).command_unoptimize_success.forEach(line -> player.sendMessage(line
|
||||||
|
.replaceText(success_amount)
|
||||||
|
.replaceText(radius)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
VillagerOptimizer.getLang(player.locale()).command_radius_invalid.forEach(player::sendMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -31,11 +31,9 @@ public class Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ConfigFile loadConfig(File ymlFile) throws Exception {
|
private ConfigFile loadConfig(File ymlFile) throws Exception {
|
||||||
File parent = new File(ymlFile.getParent());
|
File parent = ymlFile.getParentFile();
|
||||||
if (!parent.exists() && !parent.mkdir())
|
if (!parent.exists() && !parent.mkdir())
|
||||||
VillagerOptimizer.getLog().severe("Unable to create plugin config directory.");
|
VillagerOptimizer.getLog().severe("Unable to create plugin config directory.");
|
||||||
if (!ymlFile.exists())
|
|
||||||
ymlFile.createNewFile(); // Result can be ignored because this method only returns false if the file already exists
|
|
||||||
return ConfigFile.loadConfig(ymlFile);
|
return ConfigFile.loadConfig(ymlFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ import java.util.List;
|
|||||||
public class LanguageCache {
|
public class LanguageCache {
|
||||||
|
|
||||||
private final @NotNull ConfigFile lang;
|
private final @NotNull ConfigFile lang;
|
||||||
private final @NotNull MiniMessage miniMessage;
|
|
||||||
|
|
||||||
public final @NotNull Component no_permission;
|
public final @NotNull Component no_permission;
|
||||||
public final @NotNull List<Component> nametag_optimize_success, nametag_on_optimize_cooldown, nametag_unoptimize_success,
|
public final @NotNull List<Component> nametag_optimize_success, nametag_on_optimize_cooldown, nametag_unoptimize_success,
|
||||||
@ -22,9 +21,18 @@ public class LanguageCache {
|
|||||||
command_specify_radius, command_radius_invalid, command_no_villagers_nearby,
|
command_specify_radius, command_radius_invalid, command_no_villagers_nearby,
|
||||||
trades_restocked, optimize_for_trading, villager_leveling_up;
|
trades_restocked, optimize_for_trading, villager_leveling_up;
|
||||||
|
|
||||||
public LanguageCache(String lang) throws Exception {
|
public LanguageCache(String locale) throws Exception {
|
||||||
this.lang = loadLang(new File(VillagerOptimizer.getInstance().getDataFolder() + File.separator + "lang", lang + ".yml"));
|
VillagerOptimizer plugin = VillagerOptimizer.getInstance();
|
||||||
this.miniMessage = MiniMessage.miniMessage();
|
File langYML = new File(plugin.getDataFolder() + File.separator + "lang", locale + ".yml");
|
||||||
|
// 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.");
|
||||||
|
// 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);
|
||||||
|
// Finally load the lang file with configmaster
|
||||||
|
this.lang = ConfigFile.loadConfig(langYML);
|
||||||
|
|
||||||
// General
|
// General
|
||||||
this.no_permission = getTranslation("messages.no-permission",
|
this.no_permission = getTranslation("messages.no-permission",
|
||||||
@ -72,20 +80,6 @@ public class LanguageCache {
|
|||||||
this.command_no_villagers_nearby = getListTranslation("messages.command.no-villagers-nearby",
|
this.command_no_villagers_nearby = getListTranslation("messages.command.no-villagers-nearby",
|
||||||
List.of("<gray>Couldn't find any employed villagers within a radius of %radius%."));
|
List.of("<gray>Couldn't find any employed villagers within a radius of %radius%."));
|
||||||
|
|
||||||
saveLang();
|
|
||||||
}
|
|
||||||
|
|
||||||
private ConfigFile loadLang(File ymlFile) throws Exception {
|
|
||||||
File parent = new File(ymlFile.getParent());
|
|
||||||
if (!parent.exists())
|
|
||||||
if (!parent.mkdir())
|
|
||||||
VillagerOptimizer.getLog().severe("Unable to create lang directory.");
|
|
||||||
if (!ymlFile.exists())
|
|
||||||
ymlFile.createNewFile(); // Result can be ignored because this method only returns false if the file already exists
|
|
||||||
return ConfigFile.loadConfig(ymlFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void saveLang() {
|
|
||||||
try {
|
try {
|
||||||
lang.save();
|
lang.save();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -95,21 +89,21 @@ public class LanguageCache {
|
|||||||
|
|
||||||
public @NotNull Component getTranslation(@NotNull String path, @NotNull String defaultTranslation) {
|
public @NotNull Component getTranslation(@NotNull String path, @NotNull String defaultTranslation) {
|
||||||
lang.addDefault(path, defaultTranslation);
|
lang.addDefault(path, defaultTranslation);
|
||||||
return miniMessage.deserialize(lang.getString(path, defaultTranslation));
|
return MiniMessage.miniMessage().deserialize(lang.getString(path, defaultTranslation));
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull Component getTranslation(@NotNull String path, @NotNull String defaultTranslation, @NotNull String comment) {
|
public @NotNull Component getTranslation(@NotNull String path, @NotNull String defaultTranslation, @NotNull String comment) {
|
||||||
lang.addDefault(path, defaultTranslation, comment);
|
lang.addDefault(path, defaultTranslation, comment);
|
||||||
return miniMessage.deserialize(lang.getString(path, defaultTranslation));
|
return MiniMessage.miniMessage().deserialize(lang.getString(path, defaultTranslation));
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull List<Component> getListTranslation(@NotNull String path, @NotNull List<String> defaultTranslation) {
|
public @NotNull List<Component> getListTranslation(@NotNull String path, @NotNull List<String> defaultTranslation) {
|
||||||
lang.addDefault(path, defaultTranslation);
|
lang.addDefault(path, defaultTranslation);
|
||||||
return lang.getStringList(path).stream().map(miniMessage::deserialize).toList();
|
return lang.getStringList(path).stream().map(MiniMessage.miniMessage()::deserialize).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull List<Component> getListTranslation(@NotNull String path, @NotNull List<String> defaultTranslation, @NotNull String comment) {
|
public @NotNull List<Component> getListTranslation(@NotNull String path, @NotNull List<String> defaultTranslation, @NotNull String comment) {
|
||||||
lang.addDefault(path, defaultTranslation, comment);
|
lang.addDefault(path, defaultTranslation, comment);
|
||||||
return lang.getStringList(path).stream().map(miniMessage::deserialize).toList();
|
return lang.getStringList(path).stream().map(MiniMessage.miniMessage()::deserialize).toList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>me.xginko.VillagerOptimizer</groupId>
|
<groupId>me.xginko.VillagerOptimizer</groupId>
|
||||||
<artifactId>VillagerOptimizer</artifactId>
|
<artifactId>VillagerOptimizer</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>1.20.2</artifactId>
|
<artifactId>1.20.2</artifactId>
|
||||||
|
@ -126,7 +126,7 @@ public final class VillagerOptimizer extends JavaPlugin {
|
|||||||
Component.text("│ ").style(plugin_style)
|
Component.text("│ ").style(plugin_style)
|
||||||
.append(Component.text(" "+localeString).color(NamedTextColor.WHITE).decorate(TextDecoration.BOLD))
|
.append(Component.text(" "+localeString).color(NamedTextColor.WHITE).decorate(TextDecoration.BOLD))
|
||||||
.append(Component.text(" │").style(plugin_style)));
|
.append(Component.text(" │").style(plugin_style)));
|
||||||
else logger.info(String.format("Found language file for %s", localeString));
|
else logger.info("Found language file for " + localeString);
|
||||||
LanguageCache langCache = new LanguageCache(localeString);
|
LanguageCache langCache = new LanguageCache(localeString);
|
||||||
languageCacheMap.put(localeString, langCache);
|
languageCacheMap.put(localeString, langCache);
|
||||||
}
|
}
|
||||||
@ -140,7 +140,7 @@ public final class VillagerOptimizer extends JavaPlugin {
|
|||||||
Component.text("│ ").style(plugin_style)
|
Component.text("│ ").style(plugin_style)
|
||||||
.append(Component.text(" "+localeString).color(NamedTextColor.WHITE).decorate(TextDecoration.BOLD))
|
.append(Component.text(" "+localeString).color(NamedTextColor.WHITE).decorate(TextDecoration.BOLD))
|
||||||
.append(Component.text(" │").style(plugin_style)));
|
.append(Component.text(" │").style(plugin_style)));
|
||||||
else logger.info(String.format("Found language file for %s", localeString));
|
else logger.info("Found language file for " + localeString);
|
||||||
LanguageCache langCache = new LanguageCache(localeString);
|
LanguageCache langCache = new LanguageCache(localeString);
|
||||||
languageCacheMap.put(localeString, langCache);
|
languageCacheMap.put(localeString, langCache);
|
||||||
}
|
}
|
||||||
|
@ -56,84 +56,85 @@ public class OptVillagersRadius implements VillagerOptimizerCommand, TabComplete
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sender.hasPermission(Permissions.Commands.OPTIMIZE_RADIUS.get())) {
|
if (!sender.hasPermission(Permissions.Commands.OPTIMIZE_RADIUS.get())) {
|
||||||
if (args.length != 1) {
|
sender.sendMessage(VillagerOptimizer.getLang(sender).no_permission);
|
||||||
VillagerOptimizer.getLang(player.locale()).command_specify_radius.forEach(player::sendMessage);
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length != 1) {
|
||||||
|
VillagerOptimizer.getLang(player.locale()).command_specify_radius.forEach(player::sendMessage);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
int specifiedRadius = Integer.parseInt(args[0]);
|
||||||
|
|
||||||
|
if (specifiedRadius > max_radius) {
|
||||||
|
final TextReplacementConfig limit = TextReplacementConfig.builder()
|
||||||
|
.matchLiteral("%distance%")
|
||||||
|
.replacement(Integer.toString(max_radius))
|
||||||
|
.build();
|
||||||
|
VillagerOptimizer.getLang(player.locale()).command_radius_limit_exceed.forEach(line -> player.sendMessage(line.replaceText(limit)));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
VillagerCache villagerCache = VillagerOptimizer.getCache();
|
||||||
int specifiedRadius = Integer.parseInt(args[0]);
|
int successCount = 0;
|
||||||
|
int failCount = 0;
|
||||||
|
final boolean player_has_cooldown_bypass = player.hasPermission(Permissions.Bypass.COMMAND_COOLDOWN.get());
|
||||||
|
|
||||||
if (specifiedRadius > max_radius) {
|
for (Entity entity : player.getNearbyEntities(specifiedRadius, specifiedRadius, specifiedRadius)) {
|
||||||
final TextReplacementConfig limit = TextReplacementConfig.builder()
|
if (!entity.getType().equals(EntityType.VILLAGER)) continue;
|
||||||
.matchLiteral("%distance%")
|
Villager villager = (Villager) entity;
|
||||||
.replacement(Integer.toString(max_radius))
|
Villager.Profession profession = villager.getProfession();
|
||||||
.build();
|
if (profession.equals(Villager.Profession.NITWIT) || profession.equals(Villager.Profession.NONE)) continue;
|
||||||
VillagerOptimizer.getLang(player.locale()).command_radius_limit_exceed.forEach(line -> player.sendMessage(line.replaceText(limit)));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
VillagerCache villagerCache = VillagerOptimizer.getCache();
|
WrappedVillager wVillager = villagerCache.getOrAdd(villager);
|
||||||
int successCount = 0;
|
|
||||||
int failCount = 0;
|
|
||||||
final boolean player_has_cooldown_bypass = player.hasPermission(Permissions.Bypass.COMMAND_COOLDOWN.get());
|
|
||||||
|
|
||||||
for (Entity entity : player.getNearbyEntities(specifiedRadius, specifiedRadius, specifiedRadius)) {
|
if (player_has_cooldown_bypass || wVillager.canOptimize(cooldown)) {
|
||||||
if (!entity.getType().equals(EntityType.VILLAGER)) continue;
|
VillagerOptimizeEvent optimizeEvent = new VillagerOptimizeEvent(wVillager, OptimizationType.COMMAND, player);
|
||||||
Villager villager = (Villager) entity;
|
if (optimizeEvent.callEvent()) {
|
||||||
Villager.Profession profession = villager.getProfession();
|
wVillager.setOptimization(optimizeEvent.getOptimizationType());
|
||||||
if (profession.equals(Villager.Profession.NITWIT) || profession.equals(Villager.Profession.NONE)) continue;
|
wVillager.saveOptimizeTime();
|
||||||
|
successCount++;
|
||||||
WrappedVillager wVillager = villagerCache.getOrAdd(villager);
|
|
||||||
|
|
||||||
if (player_has_cooldown_bypass || wVillager.canOptimize(cooldown)) {
|
|
||||||
VillagerOptimizeEvent optimizeEvent = new VillagerOptimizeEvent(wVillager, OptimizationType.COMMAND, player);
|
|
||||||
if (optimizeEvent.callEvent()) {
|
|
||||||
wVillager.setOptimization(optimizeEvent.getOptimizationType());
|
|
||||||
wVillager.saveOptimizeTime();
|
|
||||||
successCount++;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
failCount++;
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
failCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (successCount <= 0 && failCount <= 0) {
|
|
||||||
final TextReplacementConfig radius = TextReplacementConfig.builder()
|
|
||||||
.matchLiteral("%radius%")
|
|
||||||
.replacement(Integer.toString(specifiedRadius))
|
|
||||||
.build();
|
|
||||||
VillagerOptimizer.getLang(player.locale()).command_no_villagers_nearby.forEach(line -> player.sendMessage(line.replaceText(radius)));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (successCount > 0) {
|
|
||||||
final TextReplacementConfig success_amount = TextReplacementConfig.builder()
|
|
||||||
.matchLiteral("%amount%")
|
|
||||||
.replacement(Integer.toString(successCount))
|
|
||||||
.build();
|
|
||||||
final TextReplacementConfig radius = TextReplacementConfig.builder()
|
|
||||||
.matchLiteral("%radius%")
|
|
||||||
.replacement(Integer.toString(specifiedRadius))
|
|
||||||
.build();
|
|
||||||
VillagerOptimizer.getLang(player.locale()).command_optimize_success.forEach(line -> player.sendMessage(line
|
|
||||||
.replaceText(success_amount)
|
|
||||||
.replaceText(radius)
|
|
||||||
));
|
|
||||||
}
|
|
||||||
if (failCount > 0) {
|
|
||||||
final TextReplacementConfig alreadyOptimized = TextReplacementConfig.builder()
|
|
||||||
.matchLiteral("%amount%")
|
|
||||||
.replacement(Integer.toString(failCount))
|
|
||||||
.build();
|
|
||||||
VillagerOptimizer.getLang(player.locale()).command_optimize_fail.forEach(line -> player.sendMessage(line.replaceText(alreadyOptimized)));
|
|
||||||
}
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
VillagerOptimizer.getLang(player.locale()).command_radius_invalid.forEach(player::sendMessage);
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
sender.sendMessage(VillagerOptimizer.getLang(sender).no_permission);
|
if (successCount <= 0 && failCount <= 0) {
|
||||||
|
final TextReplacementConfig radius = TextReplacementConfig.builder()
|
||||||
|
.matchLiteral("%radius%")
|
||||||
|
.replacement(Integer.toString(specifiedRadius))
|
||||||
|
.build();
|
||||||
|
VillagerOptimizer.getLang(player.locale()).command_no_villagers_nearby.forEach(line -> player.sendMessage(line.replaceText(radius)));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (successCount > 0) {
|
||||||
|
final TextReplacementConfig success_amount = TextReplacementConfig.builder()
|
||||||
|
.matchLiteral("%amount%")
|
||||||
|
.replacement(Integer.toString(successCount))
|
||||||
|
.build();
|
||||||
|
final TextReplacementConfig radius = TextReplacementConfig.builder()
|
||||||
|
.matchLiteral("%radius%")
|
||||||
|
.replacement(Integer.toString(specifiedRadius))
|
||||||
|
.build();
|
||||||
|
VillagerOptimizer.getLang(player.locale()).command_optimize_success.forEach(line -> player.sendMessage(line
|
||||||
|
.replaceText(success_amount)
|
||||||
|
.replaceText(radius)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if (failCount > 0) {
|
||||||
|
final TextReplacementConfig alreadyOptimized = TextReplacementConfig.builder()
|
||||||
|
.matchLiteral("%amount%")
|
||||||
|
.replacement(Integer.toString(failCount))
|
||||||
|
.build();
|
||||||
|
VillagerOptimizer.getLang(player.locale()).command_optimize_fail.forEach(line -> player.sendMessage(line.replaceText(alreadyOptimized)));
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
VillagerOptimizer.getLang(player.locale()).command_radius_invalid.forEach(player::sendMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -50,69 +50,70 @@ public class UnOptVillagersRadius implements VillagerOptimizerCommand, TabComple
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sender.hasPermission(Permissions.Commands.UNOPTIMIZE_RADIUS.get())) {
|
if (!sender.hasPermission(Permissions.Commands.UNOPTIMIZE_RADIUS.get())) {
|
||||||
if (args.length != 1) {
|
sender.sendMessage(VillagerOptimizer.getLang(sender).no_permission);
|
||||||
VillagerOptimizer.getLang(player.locale()).command_specify_radius.forEach(player::sendMessage);
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length != 1) {
|
||||||
|
VillagerOptimizer.getLang(player.locale()).command_specify_radius.forEach(player::sendMessage);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
int specifiedRadius = Integer.parseInt(args[0]);
|
||||||
|
|
||||||
|
if (specifiedRadius > max_radius) {
|
||||||
|
final TextReplacementConfig limit = TextReplacementConfig.builder()
|
||||||
|
.matchLiteral("%distance%")
|
||||||
|
.replacement(Integer.toString(max_radius))
|
||||||
|
.build();
|
||||||
|
VillagerOptimizer.getLang(player.locale()).command_radius_limit_exceed.forEach(line -> player.sendMessage(line.replaceText(limit)));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
VillagerCache villagerCache = VillagerOptimizer.getCache();
|
||||||
int specifiedRadius = Integer.parseInt(args[0]);
|
int successCount = 0;
|
||||||
|
|
||||||
if (specifiedRadius > max_radius) {
|
for (Entity entity : player.getNearbyEntities(specifiedRadius, specifiedRadius, specifiedRadius)) {
|
||||||
final TextReplacementConfig limit = TextReplacementConfig.builder()
|
if (!entity.getType().equals(EntityType.VILLAGER)) continue;
|
||||||
.matchLiteral("%distance%")
|
Villager villager = (Villager) entity;
|
||||||
.replacement(Integer.toString(max_radius))
|
Villager.Profession profession = villager.getProfession();
|
||||||
.build();
|
if (profession.equals(Villager.Profession.NITWIT) || profession.equals(Villager.Profession.NONE)) continue;
|
||||||
VillagerOptimizer.getLang(player.locale()).command_radius_limit_exceed.forEach(line -> player.sendMessage(line.replaceText(limit)));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
VillagerCache villagerCache = VillagerOptimizer.getCache();
|
WrappedVillager wVillager = villagerCache.getOrAdd(villager);
|
||||||
int successCount = 0;
|
|
||||||
|
|
||||||
for (Entity entity : player.getNearbyEntities(specifiedRadius, specifiedRadius, specifiedRadius)) {
|
if (wVillager.isOptimized()) {
|
||||||
if (!entity.getType().equals(EntityType.VILLAGER)) continue;
|
VillagerUnoptimizeEvent unOptimizeEvent = new VillagerUnoptimizeEvent(wVillager, player, OptimizationType.COMMAND);
|
||||||
Villager villager = (Villager) entity;
|
if (unOptimizeEvent.callEvent()) {
|
||||||
Villager.Profession profession = villager.getProfession();
|
wVillager.setOptimization(OptimizationType.NONE);
|
||||||
if (profession.equals(Villager.Profession.NITWIT) || profession.equals(Villager.Profession.NONE)) continue;
|
successCount++;
|
||||||
|
|
||||||
WrappedVillager wVillager = villagerCache.getOrAdd(villager);
|
|
||||||
|
|
||||||
if (wVillager.isOptimized()) {
|
|
||||||
VillagerUnoptimizeEvent unOptimizeEvent = new VillagerUnoptimizeEvent(wVillager, player, OptimizationType.COMMAND);
|
|
||||||
if (unOptimizeEvent.callEvent()) {
|
|
||||||
wVillager.setOptimization(OptimizationType.NONE);
|
|
||||||
successCount++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (successCount <= 0) {
|
|
||||||
final TextReplacementConfig radius = TextReplacementConfig.builder()
|
|
||||||
.matchLiteral("%radius%")
|
|
||||||
.replacement(Integer.toString(specifiedRadius))
|
|
||||||
.build();
|
|
||||||
VillagerOptimizer.getLang(player.locale()).command_no_villagers_nearby.forEach(line -> player.sendMessage(line.replaceText(radius)));
|
|
||||||
} else {
|
|
||||||
final TextReplacementConfig success_amount = TextReplacementConfig.builder()
|
|
||||||
.matchLiteral("%amount%")
|
|
||||||
.replacement(Integer.toString(successCount))
|
|
||||||
.build();
|
|
||||||
final TextReplacementConfig radius = TextReplacementConfig.builder()
|
|
||||||
.matchLiteral("%radius%")
|
|
||||||
.replacement(Integer.toString(specifiedRadius))
|
|
||||||
.build();
|
|
||||||
VillagerOptimizer.getLang(player.locale()).command_unoptimize_success.forEach(line -> player.sendMessage(line
|
|
||||||
.replaceText(success_amount)
|
|
||||||
.replaceText(radius)
|
|
||||||
));
|
|
||||||
}
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
VillagerOptimizer.getLang(player.locale()).command_radius_invalid.forEach(player::sendMessage);
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
sender.sendMessage(VillagerOptimizer.getLang(sender).no_permission);
|
if (successCount <= 0) {
|
||||||
|
final TextReplacementConfig radius = TextReplacementConfig.builder()
|
||||||
|
.matchLiteral("%radius%")
|
||||||
|
.replacement(Integer.toString(specifiedRadius))
|
||||||
|
.build();
|
||||||
|
VillagerOptimizer.getLang(player.locale()).command_no_villagers_nearby.forEach(line -> player.sendMessage(line.replaceText(radius)));
|
||||||
|
} else {
|
||||||
|
final TextReplacementConfig success_amount = TextReplacementConfig.builder()
|
||||||
|
.matchLiteral("%amount%")
|
||||||
|
.replacement(Integer.toString(successCount))
|
||||||
|
.build();
|
||||||
|
final TextReplacementConfig radius = TextReplacementConfig.builder()
|
||||||
|
.matchLiteral("%radius%")
|
||||||
|
.replacement(Integer.toString(specifiedRadius))
|
||||||
|
.build();
|
||||||
|
VillagerOptimizer.getLang(player.locale()).command_unoptimize_success.forEach(line -> player.sendMessage(line
|
||||||
|
.replaceText(success_amount)
|
||||||
|
.replaceText(radius)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
VillagerOptimizer.getLang(player.locale()).command_radius_invalid.forEach(player::sendMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -31,11 +31,9 @@ public class Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ConfigFile loadConfig(File ymlFile) throws Exception {
|
private ConfigFile loadConfig(File ymlFile) throws Exception {
|
||||||
File parent = new File(ymlFile.getParent());
|
File parent = ymlFile.getParentFile();
|
||||||
if (!parent.exists() && !parent.mkdir())
|
if (!parent.exists() && !parent.mkdir())
|
||||||
VillagerOptimizer.getLog().severe("Unable to create plugin config directory.");
|
VillagerOptimizer.getLog().severe("Unable to create plugin config directory.");
|
||||||
if (!ymlFile.exists())
|
|
||||||
ymlFile.createNewFile(); // Result can be ignored because this method only returns false if the file already exists
|
|
||||||
return ConfigFile.loadConfig(ymlFile);
|
return ConfigFile.loadConfig(ymlFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ import java.util.List;
|
|||||||
public class LanguageCache {
|
public class LanguageCache {
|
||||||
|
|
||||||
private final @NotNull ConfigFile lang;
|
private final @NotNull ConfigFile lang;
|
||||||
private final @NotNull MiniMessage miniMessage;
|
|
||||||
|
|
||||||
public final @NotNull Component no_permission;
|
public final @NotNull Component no_permission;
|
||||||
public final @NotNull List<Component> nametag_optimize_success, nametag_on_optimize_cooldown, nametag_unoptimize_success,
|
public final @NotNull List<Component> nametag_optimize_success, nametag_on_optimize_cooldown, nametag_unoptimize_success,
|
||||||
@ -22,9 +21,18 @@ public class LanguageCache {
|
|||||||
command_specify_radius, command_radius_invalid, command_no_villagers_nearby,
|
command_specify_radius, command_radius_invalid, command_no_villagers_nearby,
|
||||||
trades_restocked, optimize_for_trading, villager_leveling_up;
|
trades_restocked, optimize_for_trading, villager_leveling_up;
|
||||||
|
|
||||||
public LanguageCache(String lang) throws Exception {
|
public LanguageCache(String locale) throws Exception {
|
||||||
this.lang = loadLang(new File(VillagerOptimizer.getInstance().getDataFolder() + File.separator + "lang", lang + ".yml"));
|
VillagerOptimizer plugin = VillagerOptimizer.getInstance();
|
||||||
this.miniMessage = MiniMessage.miniMessage();
|
File langYML = new File(plugin.getDataFolder() + File.separator + "lang", locale + ".yml");
|
||||||
|
// 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.");
|
||||||
|
// 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);
|
||||||
|
// Finally load the lang file with configmaster
|
||||||
|
this.lang = ConfigFile.loadConfig(langYML);
|
||||||
|
|
||||||
// General
|
// General
|
||||||
this.no_permission = getTranslation("messages.no-permission",
|
this.no_permission = getTranslation("messages.no-permission",
|
||||||
@ -72,20 +80,6 @@ public class LanguageCache {
|
|||||||
this.command_no_villagers_nearby = getListTranslation("messages.command.no-villagers-nearby",
|
this.command_no_villagers_nearby = getListTranslation("messages.command.no-villagers-nearby",
|
||||||
List.of("<gray>Couldn't find any employed villagers within a radius of %radius%."));
|
List.of("<gray>Couldn't find any employed villagers within a radius of %radius%."));
|
||||||
|
|
||||||
saveLang();
|
|
||||||
}
|
|
||||||
|
|
||||||
private ConfigFile loadLang(File ymlFile) throws Exception {
|
|
||||||
File parent = new File(ymlFile.getParent());
|
|
||||||
if (!parent.exists())
|
|
||||||
if (!parent.mkdir())
|
|
||||||
VillagerOptimizer.getLog().severe("Unable to create lang directory.");
|
|
||||||
if (!ymlFile.exists())
|
|
||||||
ymlFile.createNewFile(); // Result can be ignored because this method only returns false if the file already exists
|
|
||||||
return ConfigFile.loadConfig(ymlFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void saveLang() {
|
|
||||||
try {
|
try {
|
||||||
lang.save();
|
lang.save();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -95,21 +89,21 @@ public class LanguageCache {
|
|||||||
|
|
||||||
public @NotNull Component getTranslation(@NotNull String path, @NotNull String defaultTranslation) {
|
public @NotNull Component getTranslation(@NotNull String path, @NotNull String defaultTranslation) {
|
||||||
lang.addDefault(path, defaultTranslation);
|
lang.addDefault(path, defaultTranslation);
|
||||||
return miniMessage.deserialize(lang.getString(path, defaultTranslation));
|
return MiniMessage.miniMessage().deserialize(lang.getString(path, defaultTranslation));
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull Component getTranslation(@NotNull String path, @NotNull String defaultTranslation, @NotNull String comment) {
|
public @NotNull Component getTranslation(@NotNull String path, @NotNull String defaultTranslation, @NotNull String comment) {
|
||||||
lang.addDefault(path, defaultTranslation, comment);
|
lang.addDefault(path, defaultTranslation, comment);
|
||||||
return miniMessage.deserialize(lang.getString(path, defaultTranslation));
|
return MiniMessage.miniMessage().deserialize(lang.getString(path, defaultTranslation));
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull List<Component> getListTranslation(@NotNull String path, @NotNull List<String> defaultTranslation) {
|
public @NotNull List<Component> getListTranslation(@NotNull String path, @NotNull List<String> defaultTranslation) {
|
||||||
lang.addDefault(path, defaultTranslation);
|
lang.addDefault(path, defaultTranslation);
|
||||||
return lang.getStringList(path).stream().map(miniMessage::deserialize).toList();
|
return lang.getStringList(path).stream().map(MiniMessage.miniMessage()::deserialize).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull List<Component> getListTranslation(@NotNull String path, @NotNull List<String> defaultTranslation, @NotNull String comment) {
|
public @NotNull List<Component> getListTranslation(@NotNull String path, @NotNull List<String> defaultTranslation, @NotNull String comment) {
|
||||||
lang.addDefault(path, defaultTranslation, comment);
|
lang.addDefault(path, defaultTranslation, comment);
|
||||||
return lang.getStringList(path).stream().map(miniMessage::deserialize).toList();
|
return lang.getStringList(path).stream().map(MiniMessage.miniMessage()::deserialize).toList();
|
||||||
}
|
}
|
||||||
}
|
}
|
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>me.xginko.VillagerOptimizer</groupId>
|
<groupId>me.xginko.VillagerOptimizer</groupId>
|
||||||
<artifactId>VillagerOptimizer</artifactId>
|
<artifactId>VillagerOptimizer</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.1</version>
|
||||||
<modules>
|
<modules>
|
||||||
<module>VillagerOptimizer-1.20.2</module>
|
<module>VillagerOptimizer-1.20.2</module>
|
||||||
<module>VillagerOptimizer-1.16.5</module>
|
<module>VillagerOptimizer-1.16.5</module>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user