Skip to content

Commit

Permalink
Update locale and fix wrong localization
Browse files Browse the repository at this point in the history
  • Loading branch information
rainbowdashlabs committed Mar 9, 2025
1 parent 951a562 commit 3c10a10
Show file tree
Hide file tree
Showing 16 changed files with 211 additions and 217 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group = "de.eldoria"
version = "2.7.3"
version = "2.7.4"

var publishModules = setOf(
"schematicbrushreborn-api",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import de.eldoria.schematicbrush.brush.config.provider.Mutator;
import de.eldoria.schematicbrush.brush.config.provider.SettingProvider;
import de.eldoria.schematicbrush.brush.config.util.ComponentProvider;
import de.eldoria.schematicbrush.util.Colors;
import org.bukkit.permissions.Permissible;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import de.eldoria.schematicbrush.brush.config.builder.BrushBuilder;
import de.eldoria.schematicbrush.brush.config.builder.BrushBuilderSnapshot;
import de.eldoria.schematicbrush.brush.config.builder.BuildUtil;
import de.eldoria.schematicbrush.util.Colors;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.SerializableAs;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -91,9 +90,9 @@ public static Brush deserialize(Map<String, Object> objectMap) {
@NotNull
public Map<String, Object> serialize() {
return SerializationUtil.newBuilder()
.add("name", name)
.add("snapshot", snapshot)
.build();
.add("name", name)
.add("snapshot", snapshot)
.build();
}

/**
Expand Down Expand Up @@ -145,61 +144,75 @@ public int compareTo(@NotNull Brush o) {

public String simpleComponent(BrushSettingsRegistry registry) {
var sets = snapshot.schematicSets().stream()
.map(set -> " " + BuildUtil.renderProvider(set.selector()))
.toList();
.map(set -> " " + BuildUtil.renderProvider(set.selector()))
.toList();
return MessageComposer.create()
.text("<%s>%s", Colors.VALUE, description())
.newLine()
.text("<%s>Schematic Sets:", Colors.NAME)
.newLine()
.text(sets)
.newLine()
.text(simpleModifier(registry))
.build();
.text("<value>%s", description())
.newLine()
.text("<name>")
.localeCode("words.schematicSets")
.text(":")
.newLine()
.text(sets)
.newLine()
.text(simpleModifier(registry))
.build();
}

public String infoComponent(boolean global, boolean canDelete, BrushSettingsRegistry registry) {
var text = MessageComposer.create()
.text("<%s><hover:show_text:'%s'>%s</hover>", Colors.NAME, simpleComponent(registry), name())
.space()
.text("<%s><click:run_command:'/sbrbp info %s'>[Info]</click>", Colors.ADD, (global ? "g:" : "") + name())
.space()
.text("<%s><click:run_command:'/sbr loadbrush %s'>[Load]</click>", Colors.ADD, (global ? "g:" : "") + name());
.text("<name><hover:show_text:'%s'>%s</hover>", simpleComponent(registry), name())
.space()
.text("<add><click:run_command:'/sbrbp info %s'>[Info]</click>", (global ? "g:" : "") + name())
.space()
.text("<add><click:run_command:'/sbr loadbrush %s'>[Load]</click>", (global ? "g:" : "") + name());
if (canDelete) {
text.space().text("<%s><click:run_command:'/sbrbp remove %s %s'>[Remove]</click>", Colors.REMOVE, name(), global ? "-g" : "");
text.space().text("<remove><click:run_command:'/sbrbp remove %s %s'>[Remove]</click>", name(), global ? "-g" : "");
}

return text.build();
}

private List<String> simpleModifier(BrushSettingsRegistry registry) {
return snapshot.placementModifier().entrySet().stream()
.map(e -> registry.getPlacementModifier(e.getKey())
.map(mod -> String.format("<%s>%s: <%s>%s",
Colors.NAME, mod.modifier().name(), Colors.VALUE, e.getValue().descriptor()))
.orElse(null))
.filter(Objects::nonNull)
.toList();
.map(e -> registry.getPlacementModifier(e.getKey())
.map(mod -> String.format("<name>%s: <value>%s",
mod.modifier().name(), e.getValue().descriptor()))
.orElse(null))
.filter(Objects::nonNull)
.toList();
}

public String detailComponent(boolean global, BrushSettingsRegistry registry) {
var sets = snapshot.schematicSets().stream()
.map(set -> String.format(" <hover:show_text:'%s'>%s</hover>", set.infoComponent(), BuildUtil.renderProvider(set.selector())))
.collect(Collectors.toList());
.map(set -> String.format(" <hover:show_text:'%s'>%s</hover>", set.infoComponent(), BuildUtil.renderProvider(set.selector())))
.collect(Collectors.toList());

var modifier = simpleModifier(registry);

return MessageComposer.create()
.text("<%s>Information about brush <%s>%s", Colors.HEADING, Colors.NAME, name())
.newLine()
.text("<%s>Description: <%s>%s <click:suggest_command:'/sbrbp descr %s '><%s>[Change]</click>",
Colors.NAME, Colors.VALUE, description(), (global ? "g:" : "") + name(), Colors.CHANGE)
.newLine()
.text("<%s>Schematic Sets:", Colors.NAME)
.newLine()
.text(sets)
.newLine()
.text(modifier)
.build();
.text("<heading>").localeCode("components.brush.information")
.space()
.text(name())
.newLine()
.text("<name>")
.localeCode("words.description")
.text(": <value>")
.text(description())
.space()
.text("<click:suggest_command:'/sbrbp descr ")
.text((global ? "g:" : "") + name())
.text(" '><change>[")
.localeCode("words.change")
.text("]</click>")
.newLine()
.text("<name>")
.localeCode("words.schematicSets")
.text(":")
.newLine()
.text(sets)
.newLine()
.text(modifier)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import de.eldoria.eldoutilities.serialization.SerializationUtil;
import de.eldoria.schematicbrush.brush.config.builder.BuildUtil;
import de.eldoria.schematicbrush.brush.config.builder.SchematicSetBuilder;
import de.eldoria.schematicbrush.util.Colors;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.SerializableAs;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -73,12 +72,12 @@ public String name() {

public String infoComponent(boolean global, boolean canDelete) {
var text = MessageComposer.create()
.text("<%s><hover:show_text:'%s'>%s</hover>", Colors.NAME, simpleComponent(), name())
.text("<name><hover:show_text:'%s'>%s</hover>", simpleComponent(), name())
.space()
.text("<%s><click:run_command:'/sbrp info %s'>[Info]</click>", Colors.ADD, (global ? "g:" : "") + name());
.text("<add><click:run_command:'/sbrp info %s'>[Info]</click>", (global ? "g:" : "") + name());
if (canDelete) {
text.space()
.text("<%s><click:run_command:'/sbrp remove %s %s'>[Remove]</click>", Colors.REMOVE, name(), (global ? "-g" : ""));
.text("<remove><click:run_command:'/sbrp remove %s %s'>[Remove]</click>", name(), (global ? "-g" : ""));
}

return text.build();
Expand All @@ -90,12 +89,21 @@ public String detailComponent(boolean global) {
.collect(Collectors.toList());

return MessageComposer.create()
.text("<%s>Information about preset <%s>%s", Colors.HEADING, Colors.NAME, name())
.text("<heading>")
.localeCode("components.preset.information")
.text(" <name>%s", name())
.newLine()
.text("<%s>Description: <%s>%s <click:suggest_command:'/sbrp descr %s '><%s>[Change]</click>",
Colors.NAME, Colors.VALUE, description(), (global ? "g:" : "") + name(), Colors.CHANGE)
.text("<name>")
.localeCode("words.description")
.text(": <value>%s", description())
.space()
.text("<click:suggest_command:'/sbrp descr %s '><change>[", (global ? "g:" : "") + name())
.localeCode("words.change")
.text("]</click>")
.newLine()
.text("<%s>Schematic Sets:", Colors.NAME)
.text("<name>")
.localeCode("words.schematicSets")
.text(":")
.newLine()
.text(sets)
.build();
Expand All @@ -106,8 +114,8 @@ public String simpleComponent() {
.map(set -> " " + BuildUtil.renderProvider(set.selector()))
.collect(Collectors.joining("\n"));

var message = String.format("<%s>%s%n", Colors.VALUE, description());
message += String.format("<%s>Schematic Sets:%n%s", Colors.NAME, sets);
var message = String.format("<value>%s%n", description());
message += String.format("<name>Schematic Sets:%n%s", sets);
return message;
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
Expand All @@ -97,6 +100,7 @@
@SuppressWarnings("unused")
public class SchematicBrushRebornImpl extends SchematicBrushReborn {

private static final String[] LANGUAGES = new String[]{"de_DE", "en_US", "zh_TW"};
private BrushSettingsRegistryImpl settingsRegistry;
private SchematicRegistryImpl schematics;
private JacksonConfiguration configuration;
Expand Down Expand Up @@ -141,6 +145,18 @@ public void onPluginLoad() throws Throwable {
configuration.save();
}

if (base.version() == 1) {
// Required changes were made to language formats. reset files.
Path path = getDataFolder().toPath().resolve("messages");
for (String language : LANGUAGES) {
var file = path.resolve("messages_%s.properties".formatted(language));
Files.copy(file, path.resolve("messages_%s_old.properties".formatted(language)), StandardCopyOption.REPLACE_EXISTING);
Files.deleteIfExists(file);
}
base.version(2);
configuration.save();
}

var yamlStorage = new YamlStorage(configuration);
storageRegistry = new StorageRegistryImpl(yamlStorage, configuration);
storageRegistry.register(StorageRegistry.YAML, yamlStorage);
Expand All @@ -149,26 +165,26 @@ public void onPluginLoad() throws Throwable {
@Override
public void onPluginEnable() {
var localizer = Localizer.builder(this, configuration.general().language())
.setIncludedLocales("de_DE", "en_US", "zh_TW")
.build();
.setIncludedLocales(LANGUAGES)
.build();
MessageSender.builder(this)
.prefix("<gold>[SB]")
.messageColor(NamedTextColor.AQUA)
.addTag(tags -> tags
.tag("heading", Tag.styling(NamedTextColor.GOLD))
.tag("name", Tag.styling(NamedTextColor.AQUA))
.tag("value", Tag.styling(NamedTextColor.DARK_GREEN))
.tag("change", Tag.styling(NamedTextColor.YELLOW))
.tag("remove", Tag.styling(NamedTextColor.RED))
.tag("add", Tag.styling(NamedTextColor.GREEN))
.tag("warn", Tag.styling(NamedTextColor.RED))
.tag("neutral", Tag.styling(NamedTextColor.AQUA))
.tag("confirm", Tag.styling(NamedTextColor.GREEN))
.tag("delete", Tag.styling(NamedTextColor.RED))
.tag("inactive", Tag.styling(NamedTextColor.GRAY))
)
.localizer(localizer)
.register();
.prefix("<gold>[SB]")
.messageColor(NamedTextColor.AQUA)
.addTag(tags -> tags
.tag("heading", Tag.styling(NamedTextColor.GOLD))
.tag("name", Tag.styling(NamedTextColor.DARK_AQUA))
.tag("value", Tag.styling(NamedTextColor.DARK_GREEN))
.tag("change", Tag.styling(NamedTextColor.YELLOW))
.tag("remove", Tag.styling(NamedTextColor.RED))
.tag("add", Tag.styling(NamedTextColor.GREEN))
.tag("warn", Tag.styling(NamedTextColor.RED))
.tag("neutral", Tag.styling(NamedTextColor.AQUA))
.tag("confirm", Tag.styling(NamedTextColor.GREEN))
.tag("delete", Tag.styling(NamedTextColor.RED))
.tag("inactive", Tag.styling(NamedTextColor.GRAY))
)
.localizer(localizer)
.register();

schematics.register(SchematicCache.STORAGE, new SchematicBrushCache(this, configuration));

Expand Down Expand Up @@ -217,12 +233,12 @@ public void onPluginEnable() {
public Module platformModule() {
if (!getServer().getName().toLowerCase(Locale.ROOT).contains("spigot")) {
return JacksonPaper.builder()
.colorAsHex()
.build();
.colorAsHex()
.build();
}
return JacksonBukkit.builder()
.colorAsHex()
.build();
.colorAsHex()
.build();
}

/**
Expand Down Expand Up @@ -255,14 +271,14 @@ public SimpleModule schematicBrushModule() {
@Override
public ObjectMapper configureMapper(MapperBuilder<?, ?> builder) {
builder.addModule(platformModule())
.typeFactory(TypeFactory.defaultInstance().withClassLoader(getClassLoader()))
.addModule(schematicBrushModule())
.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS);
.typeFactory(TypeFactory.defaultInstance().withClassLoader(getClassLoader()))
.addModule(schematicBrushModule())
.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS);
if (builder instanceof YAMLMapper.Builder b) {
b.disable(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID)
.disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER);
.disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER);
}
return builder
.build()
Expand All @@ -274,11 +290,11 @@ public ObjectMapper configureMapper(MapperBuilder<?, ?> builder) {
public void onPostStart() throws Throwable {
if (configuration.general().isCheckUpdates() && UserData.get(this).isPremium()) {
Updater.lyna(LynaUpdateData.builder(this, 1)
.updateUrl("https://discord.gg/zRW9Vpu")
.notifyPermission(Permissions.Admin.RELOAD)
.notifyUpdate(true)
.build())
.start();
.updateUrl("https://discord.gg/zRW9Vpu")
.notifyPermission(Permissions.Admin.RELOAD)
.notifyUpdate(true)
.build())
.start();
}
}

Expand Down Expand Up @@ -327,11 +343,11 @@ private void enableMetrics() {

metrics.addCustomChart(new AdvancedPie("installed_add_ons",
() -> Arrays.stream(getServer().getPluginManager().getPlugins())
.filter(plugin -> {
var descr = plugin.getDescription();
return descr.getSoftDepend().contains("SchematicBrushReborn") || descr.getDepend()
.contains("SchematicBrushReborn");
}).collect(Collectors.toMap(e -> e.getDescription().getName(), e -> 1))));
.filter(plugin -> {
var descr = plugin.getDescription();
return descr.getSoftDepend().contains("SchematicBrushReborn") || descr.getDepend()
.contains("SchematicBrushReborn");
}).collect(Collectors.toMap(e -> e.getDescription().getName(), e -> 1))));

metrics.addCustomChart(new SimplePie("used_storage_type",
() -> configuration.general().storageType().name()));
Expand Down
Loading

0 comments on commit 3c10a10

Please sign in to comment.