From 1e9a27ccead1504a9db2c680a3caec283fdb6ea7 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Sun, 1 Oct 2023 11:45:31 +0100 Subject: [PATCH] fix: load flags after we is initliased - fixes #4073 - it could be possible to add a callback in the WE initilised event listener, but that overcomplicates it a bit and this is fine tbh --- .../com/plotsquared/core/plot/PlotArea.java | 85 +++++++++++-------- Core/src/main/resources/lang/messages_en.json | 2 + 2 files changed, 53 insertions(+), 34 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java b/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java index 73c34cdda..91121af6a 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java +++ b/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java @@ -51,6 +51,8 @@ import com.plotsquared.core.util.MathMan; import com.plotsquared.core.util.PlotExpression; import com.plotsquared.core.util.RegionUtil; import com.plotsquared.core.util.StringMan; +import com.plotsquared.core.util.task.TaskManager; +import com.plotsquared.core.util.task.TaskTime; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; @@ -391,47 +393,62 @@ public abstract class PlotArea implements ComponentLike { } } - List flags = config.getStringList("flags.default"); - if (flags.isEmpty()) { - flags = config.getStringList("flags"); - if (flags.isEmpty()) { - flags = new ArrayList<>(); - ConfigurationSection section = config.getConfigurationSection("flags"); - Set keys = section.getKeys(false); - for (String key : keys) { - if (!"default".equals(key)) { - flags.add(key + ';' + section.get(key)); - } - } - } - } - parseFlags(this.getFlagContainer(), flags); - ConsolePlayer.getConsole().sendMessage( - TranslatableCaption.of("flags.area_flags"), - TagResolver.resolver("flags", Tag.inserting(Component.text(flags.toString()))) - ); - this.spawnEggs = config.getBoolean("event.spawn.egg"); this.spawnCustom = config.getBoolean("event.spawn.custom"); this.spawnBreeding = config.getBoolean("event.spawn.breeding"); - List roadflags = config.getStringList("road.flags"); - if (roadflags.isEmpty()) { - roadflags = new ArrayList<>(); - ConfigurationSection section = config.getConfigurationSection("road.flags"); - Set keys = section.getKeys(false); - for (String key : keys) { - if (!"default".equals(key)) { - roadflags.add(key + ';' + section.get(key)); + Runnable loadFlags = () -> { + ConsolePlayer.getConsole().sendMessage( + TranslatableCaption.of("flags.loading_area_flags"), + TagResolver.resolver("area", Tag.inserting(Component.text(this.id == null ? this.worldName : this.id))) + ); + List flags = config.getStringList("flags.default"); + if (flags.isEmpty()) { + flags = config.getStringList("flags"); + if (flags.isEmpty()) { + flags = new ArrayList<>(); + ConfigurationSection section = config.getConfigurationSection("flags"); + Set keys = section.getKeys(false); + for (String key : keys) { + if (!"default".equals(key)) { + flags.add(key + ';' + section.get(key)); + } + } } } + parseFlags(this.getFlagContainer(), flags); + ConsolePlayer.getConsole().sendMessage( + TranslatableCaption.of("flags.area_flags"), + TagResolver.resolver("flags", Tag.inserting(Component.text(flags.toString()))) + ); + + List roadflags = config.getStringList("road.flags"); + if (roadflags.isEmpty()) { + roadflags = new ArrayList<>(); + ConfigurationSection section = config.getConfigurationSection("road.flags"); + Set keys = section.getKeys(false); + for (String key : keys) { + if (!"default".equals(key)) { + roadflags.add(key + ';' + section.get(key)); + } + } + } + this.roadFlags = roadflags.size() > 0; + parseFlags(this.getRoadFlagContainer(), roadflags); + ConsolePlayer.getConsole().sendMessage( + TranslatableCaption.of("flags.road_flags"), + TagResolver.resolver("flags", Tag.inserting(Component.text(roadflags.toString()))) + ); + }; + if (PlotSquared.get().isWeInitialised()) { + loadFlags.run(); + } else { + ConsolePlayer.getConsole().sendMessage( + TranslatableCaption.of("flags.delaying_loading_area_flags"), + TagResolver.resolver("area", Tag.inserting(Component.text(this.id == null ? this.worldName : this.id))) + ); + TaskManager.runTaskLater(loadFlags, TaskTime.ticks(1)); } - this.roadFlags = roadflags.size() > 0; - parseFlags(this.getRoadFlagContainer(), roadflags); - ConsolePlayer.getConsole().sendMessage( - TranslatableCaption.of("flags.road_flags"), - TagResolver.resolver("flags", Tag.inserting(Component.text(roadflags.toString()))) - ); loadConfiguration(config); } diff --git a/Core/src/main/resources/lang/messages_en.json b/Core/src/main/resources/lang/messages_en.json index 0fde34600..546cd3337 100644 --- a/Core/src/main/resources/lang/messages_en.json +++ b/Core/src/main/resources/lang/messages_en.json @@ -631,6 +631,8 @@ "flags.flag_error_double": "Flag value must be a decimal number.", "flags.flag_error_music": "Flag value must be a valid music disc ID.", "flags.flag_error_title": "Flag value must be in the format \"A title\" \"The subtitle\".", + "flags.delaying_loading_area_flags": "Delaying loading flags for area `` as WorldEdit is not initialised yet.", + "flags.loading_area_flags": "Loading flags for area: ", "flags.area_flags": "Area flags: ", "flags.road_flags": "Road flags: ", "commands.description.add": "Allow a user to build in a plot while the plot owner is online.",