mirror of
https://github.com/Xiao-MoMi/Custom-Fishing.git
synced 2025-12-19 15:09:24 +00:00
Improve locales
This commit is contained in:
@@ -24,6 +24,7 @@ import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@@ -40,7 +41,7 @@ public class FishingBagHolder implements InventoryHolder {
|
||||
* @param owner the UUID of the player who owns this fishing bag.
|
||||
*/
|
||||
public FishingBagHolder(UUID owner) {
|
||||
this.owner = owner;
|
||||
this.owner = Objects.requireNonNull(owner, "uuid should be nonnull");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -37,7 +37,8 @@ import java.util.stream.Stream;
|
||||
|
||||
public class TranslationManager {
|
||||
|
||||
public static final Locale DEFAULT_LOCALE = Locale.ENGLISH;
|
||||
private static final Locale DEFAULT_LOCALE = Locale.ENGLISH;
|
||||
private static Locale FORCE_LOCALE = null;
|
||||
private static final List<String> locales = List.of("en", "zh_cn");
|
||||
private static TranslationManager instance;
|
||||
|
||||
@@ -52,6 +53,10 @@ public class TranslationManager {
|
||||
instance = this;
|
||||
}
|
||||
|
||||
public static void forceLocale(Locale locale) {
|
||||
FORCE_LOCALE = locale;
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
// remove any previous registry
|
||||
if (this.registry != null) {
|
||||
@@ -73,6 +78,9 @@ public class TranslationManager {
|
||||
}
|
||||
|
||||
public static String miniMessageTranslation(String key, @Nullable Locale locale) {
|
||||
if (FORCE_LOCALE != null) {
|
||||
return instance.registry.miniMessageTranslation(key, FORCE_LOCALE);
|
||||
}
|
||||
if (locale == null) {
|
||||
locale = Locale.getDefault();
|
||||
if (locale == null) {
|
||||
@@ -87,6 +95,9 @@ public class TranslationManager {
|
||||
}
|
||||
|
||||
public static Component render(Component component, @Nullable Locale locale) {
|
||||
if (FORCE_LOCALE != null) {
|
||||
return MiniMessageTranslator.render(component, FORCE_LOCALE);
|
||||
}
|
||||
if (locale == null) {
|
||||
locale = Locale.getDefault();
|
||||
if (locale == null) {
|
||||
@@ -134,7 +145,7 @@ public class TranslationManager {
|
||||
|
||||
Locale localLocale = Locale.getDefault();
|
||||
if (!this.installed.contains(localLocale)) {
|
||||
plugin.getPluginLogger().warn(localLocale.toString().toLowerCase(Locale.ENGLISH) + ".yml not exists, using en.yml as default locale.");
|
||||
plugin.getPluginLogger().warn(localLocale.toString().toLowerCase(Locale.ENGLISH) + ".yml not exists, using " + DEFAULT_LOCALE.toString().toLowerCase(Locale.ENGLISH) + ".yml as default locale.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,6 +196,6 @@ public class TranslationManager {
|
||||
}
|
||||
|
||||
public static @Nullable Locale parseLocale(@Nullable String locale) {
|
||||
return locale == null ? null : Translator.parseLocale(locale);
|
||||
return locale == null || locale.isEmpty() ? null : Translator.parseLocale(locale);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import dev.dejvokep.boostedyaml.YamlDocument;
|
||||
import dev.dejvokep.boostedyaml.block.implementation.Section;
|
||||
import dev.dejvokep.boostedyaml.dvs.versioning.BasicVersioning;
|
||||
import dev.dejvokep.boostedyaml.libs.org.snakeyaml.engine.v2.common.ScalarStyle;
|
||||
import dev.dejvokep.boostedyaml.libs.org.snakeyaml.engine.v2.exceptions.ConstructorException;
|
||||
import dev.dejvokep.boostedyaml.libs.org.snakeyaml.engine.v2.nodes.Tag;
|
||||
import dev.dejvokep.boostedyaml.settings.dumper.DumperSettings;
|
||||
import dev.dejvokep.boostedyaml.settings.general.GeneralSettings;
|
||||
@@ -71,6 +72,7 @@ import net.momirealms.customfishing.common.helper.AdventureHelper;
|
||||
import net.momirealms.customfishing.common.helper.VersionHelper;
|
||||
import net.momirealms.customfishing.common.item.AbstractItem;
|
||||
import net.momirealms.customfishing.common.item.Item;
|
||||
import net.momirealms.customfishing.common.locale.TranslationManager;
|
||||
import net.momirealms.customfishing.common.util.*;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.BlockFace;
|
||||
@@ -259,6 +261,8 @@ public class BukkitConfigManager extends ConfigManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TranslationManager.forceLocale(TranslationManager.parseLocale(config.getString("force-locale", "")));
|
||||
}
|
||||
|
||||
private void loadConfigs() {
|
||||
@@ -279,11 +283,15 @@ public class BukkitConfigManager extends ConfigManager {
|
||||
if (subFile.isDirectory()) {
|
||||
fileDeque.push(subFile);
|
||||
} else if (subFile.isFile() && subFile.getName().endsWith(".yml")) {
|
||||
YamlDocument document = plugin.getConfigManager().loadData(subFile);
|
||||
for (Map.Entry<String, Object> entry : document.getStringRouteMappedValues(false).entrySet()) {
|
||||
if (entry.getValue() instanceof Section section) {
|
||||
type.parse(entry.getKey(), section, nodes);
|
||||
try {
|
||||
YamlDocument document = plugin.getConfigManager().loadData(subFile);
|
||||
for (Map.Entry<String, Object> entry : document.getStringRouteMappedValues(false).entrySet()) {
|
||||
if (entry.getValue() instanceof Section section) {
|
||||
type.parse(entry.getKey(), section, nodes);
|
||||
}
|
||||
}
|
||||
} catch (ConstructorException e) {
|
||||
plugin.getPluginLogger().warn("Could not load config file: " + subFile.getAbsolutePath() + ". Is it a corrupted file?");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public class BukkitIntegrationManager implements IntegrationManager {
|
||||
if (isHooked("NeigeItems")) {
|
||||
registerItemProvider(new NeigeItemsItemProvider());
|
||||
}
|
||||
if (isHooked("MythicMobs")) {
|
||||
if (isHooked("MythicMobs", "5")) {
|
||||
registerItemProvider(new MythicMobsItemProvider());
|
||||
registerEntityProvider(new MythicEntityProvider());
|
||||
}
|
||||
@@ -127,7 +127,7 @@ public class BukkitIntegrationManager implements IntegrationManager {
|
||||
registerSeasonProvider(new RealisticSeasonsProvider());
|
||||
} else if (isHooked("AdvancedSeasons")) {
|
||||
registerSeasonProvider(new AdvancedSeasonsProvider());
|
||||
} else if (isHooked("CustomCrops")) {
|
||||
} else if (isHooked("CustomCrops", "3.4", "3.5", "3.6")) {
|
||||
registerSeasonProvider(new CustomCropsSeasonProvider());
|
||||
}
|
||||
if (isHooked("Vault")) {
|
||||
@@ -162,12 +162,15 @@ public class BukkitIntegrationManager implements IntegrationManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isHooked(String hooked, String versionPrefix) {
|
||||
private boolean isHooked(String hooked, String... versionPrefix) {
|
||||
Plugin p = Bukkit.getPluginManager().getPlugin(hooked);
|
||||
if (p != null) {
|
||||
if (p.getDescription().getVersion().startsWith(versionPrefix)) {
|
||||
plugin.getPluginLogger().info(hooked + " hooked!");
|
||||
return true;
|
||||
String ver = p.getDescription().getVersion();
|
||||
for (String prefix : versionPrefix) {
|
||||
if (ver.startsWith(prefix)) {
|
||||
plugin.getPluginLogger().info(hooked + " hooked!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -7,6 +7,8 @@ debug: false
|
||||
metrics: true
|
||||
# Check updates
|
||||
update-checker: true
|
||||
# Force locale, for instance zh_cn
|
||||
force-locale: ''
|
||||
|
||||
# Mechanic settings
|
||||
mechanics:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Project settings
|
||||
# Rule: [major update].[feature update].[bug fix]
|
||||
project_version=2.2.10
|
||||
config_version=34
|
||||
project_version=2.2.11
|
||||
config_version=35
|
||||
project_group=net.momirealms
|
||||
|
||||
# Dependency settings
|
||||
@@ -17,7 +17,7 @@ h2_driver_version=2.2.224
|
||||
sqlite_driver_version=3.46.0.0
|
||||
adventure_bundle_version=4.17.0
|
||||
adventure_platform_version=4.3.3
|
||||
sparrow_heart_version=0.33
|
||||
sparrow_heart_version=0.34
|
||||
cloud_core_version=2.0.0-rc.2
|
||||
cloud_services_version=2.0.0-rc.2
|
||||
cloud_brigadier_version=2.0.0-beta.9
|
||||
|
||||
Reference in New Issue
Block a user