8787import org .jetbrains .annotations .NotNull ;
8888
8989import java .io .File ;
90+ import java .nio .file .Files ;
91+ import java .nio .file .Path ;
92+ import java .nio .file .StandardCopyOption ;
9093import java .util .Arrays ;
9194import java .util .List ;
9295import java .util .Locale ;
97100@ SuppressWarnings ("unused" )
98101public class SchematicBrushRebornImpl extends SchematicBrushReborn {
99102
103+ private static final String [] LANGUAGES = new String []{"de_DE" , "en_US" , "zh_TW" };
100104 private BrushSettingsRegistryImpl settingsRegistry ;
101105 private SchematicRegistryImpl schematics ;
102106 private JacksonConfiguration configuration ;
@@ -141,6 +145,18 @@ public void onPluginLoad() throws Throwable {
141145 configuration .save ();
142146 }
143147
148+ if (base .version () == 1 ) {
149+ // Required changes were made to language formats. reset files.
150+ Path path = getDataFolder ().toPath ().resolve ("messages" );
151+ for (String language : LANGUAGES ) {
152+ var file = path .resolve ("messages_%s.properties" .formatted (language ));
153+ Files .copy (file , path .resolve ("messages_%s_old.properties" .formatted (language )), StandardCopyOption .REPLACE_EXISTING );
154+ Files .deleteIfExists (file );
155+ }
156+ base .version (2 );
157+ configuration .save ();
158+ }
159+
144160 var yamlStorage = new YamlStorage (configuration );
145161 storageRegistry = new StorageRegistryImpl (yamlStorage , configuration );
146162 storageRegistry .register (StorageRegistry .YAML , yamlStorage );
@@ -149,26 +165,26 @@ public void onPluginLoad() throws Throwable {
149165 @ Override
150166 public void onPluginEnable () {
151167 var localizer = Localizer .builder (this , configuration .general ().language ())
152- .setIncludedLocales ("de_DE" , "en_US" , "zh_TW" )
153- .build ();
168+ .setIncludedLocales (LANGUAGES )
169+ .build ();
154170 MessageSender .builder (this )
155- .prefix ("<gold>[SB]" )
156- .messageColor (NamedTextColor .AQUA )
157- .addTag (tags -> tags
158- .tag ("heading" , Tag .styling (NamedTextColor .GOLD ))
159- .tag ("name" , Tag .styling (NamedTextColor .AQUA ))
160- .tag ("value" , Tag .styling (NamedTextColor .DARK_GREEN ))
161- .tag ("change" , Tag .styling (NamedTextColor .YELLOW ))
162- .tag ("remove" , Tag .styling (NamedTextColor .RED ))
163- .tag ("add" , Tag .styling (NamedTextColor .GREEN ))
164- .tag ("warn" , Tag .styling (NamedTextColor .RED ))
165- .tag ("neutral" , Tag .styling (NamedTextColor .AQUA ))
166- .tag ("confirm" , Tag .styling (NamedTextColor .GREEN ))
167- .tag ("delete" , Tag .styling (NamedTextColor .RED ))
168- .tag ("inactive" , Tag .styling (NamedTextColor .GRAY ))
169- )
170- .localizer (localizer )
171- .register ();
171+ .prefix ("<gold>[SB]" )
172+ .messageColor (NamedTextColor .AQUA )
173+ .addTag (tags -> tags
174+ .tag ("heading" , Tag .styling (NamedTextColor .GOLD ))
175+ .tag ("name" , Tag .styling (NamedTextColor .DARK_AQUA ))
176+ .tag ("value" , Tag .styling (NamedTextColor .DARK_GREEN ))
177+ .tag ("change" , Tag .styling (NamedTextColor .YELLOW ))
178+ .tag ("remove" , Tag .styling (NamedTextColor .RED ))
179+ .tag ("add" , Tag .styling (NamedTextColor .GREEN ))
180+ .tag ("warn" , Tag .styling (NamedTextColor .RED ))
181+ .tag ("neutral" , Tag .styling (NamedTextColor .AQUA ))
182+ .tag ("confirm" , Tag .styling (NamedTextColor .GREEN ))
183+ .tag ("delete" , Tag .styling (NamedTextColor .RED ))
184+ .tag ("inactive" , Tag .styling (NamedTextColor .GRAY ))
185+ )
186+ .localizer (localizer )
187+ .register ();
172188
173189 schematics .register (SchematicCache .STORAGE , new SchematicBrushCache (this , configuration ));
174190
@@ -217,12 +233,12 @@ public void onPluginEnable() {
217233 public Module platformModule () {
218234 if (!getServer ().getName ().toLowerCase (Locale .ROOT ).contains ("spigot" )) {
219235 return JacksonPaper .builder ()
220- .colorAsHex ()
221- .build ();
236+ .colorAsHex ()
237+ .build ();
222238 }
223239 return JacksonBukkit .builder ()
224- .colorAsHex ()
225- .build ();
240+ .colorAsHex ()
241+ .build ();
226242 }
227243
228244 /**
@@ -255,14 +271,14 @@ public SimpleModule schematicBrushModule() {
255271 @ Override
256272 public ObjectMapper configureMapper (MapperBuilder <?, ?> builder ) {
257273 builder .addModule (platformModule ())
258- .typeFactory (TypeFactory .defaultInstance ().withClassLoader (getClassLoader ()))
259- .addModule (schematicBrushModule ())
260- .configure (SerializationFeature .FAIL_ON_EMPTY_BEANS , false )
261- .configure (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES , false )
262- .enable (MapperFeature .ACCEPT_CASE_INSENSITIVE_ENUMS );
274+ .typeFactory (TypeFactory .defaultInstance ().withClassLoader (getClassLoader ()))
275+ .addModule (schematicBrushModule ())
276+ .configure (SerializationFeature .FAIL_ON_EMPTY_BEANS , false )
277+ .configure (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES , false )
278+ .enable (MapperFeature .ACCEPT_CASE_INSENSITIVE_ENUMS );
263279 if (builder instanceof YAMLMapper .Builder b ) {
264280 b .disable (YAMLGenerator .Feature .USE_NATIVE_TYPE_ID )
265- .disable (YAMLGenerator .Feature .WRITE_DOC_START_MARKER );
281+ .disable (YAMLGenerator .Feature .WRITE_DOC_START_MARKER );
266282 }
267283 return builder
268284 .build ()
@@ -274,11 +290,11 @@ public ObjectMapper configureMapper(MapperBuilder<?, ?> builder) {
274290 public void onPostStart () throws Throwable {
275291 if (configuration .general ().isCheckUpdates () && UserData .get (this ).isPremium ()) {
276292 Updater .lyna (LynaUpdateData .builder (this , 1 )
277- .updateUrl ("https://discord.gg/zRW9Vpu" )
278- .notifyPermission (Permissions .Admin .RELOAD )
279- .notifyUpdate (true )
280- .build ())
281- .start ();
293+ .updateUrl ("https://discord.gg/zRW9Vpu" )
294+ .notifyPermission (Permissions .Admin .RELOAD )
295+ .notifyUpdate (true )
296+ .build ())
297+ .start ();
282298 }
283299 }
284300
@@ -327,11 +343,11 @@ private void enableMetrics() {
327343
328344 metrics .addCustomChart (new AdvancedPie ("installed_add_ons" ,
329345 () -> Arrays .stream (getServer ().getPluginManager ().getPlugins ())
330- .filter (plugin -> {
331- var descr = plugin .getDescription ();
332- return descr .getSoftDepend ().contains ("SchematicBrushReborn" ) || descr .getDepend ()
333- .contains ("SchematicBrushReborn" );
334- }).collect (Collectors .toMap (e -> e .getDescription ().getName (), e -> 1 ))));
346+ .filter (plugin -> {
347+ var descr = plugin .getDescription ();
348+ return descr .getSoftDepend ().contains ("SchematicBrushReborn" ) || descr .getDepend ()
349+ .contains ("SchematicBrushReborn" );
350+ }).collect (Collectors .toMap (e -> e .getDescription ().getName (), e -> 1 ))));
335351
336352 metrics .addCustomChart (new SimplePie ("used_storage_type" ,
337353 () -> configuration .general ().storageType ().name ()));
0 commit comments