Skip to content

Commit

Permalink
fix: load flags after we is initialised (#4186)
Browse files Browse the repository at this point in the history
* 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

* Extract method
  • Loading branch information
dordsor21 authored Oct 7, 2023
1 parent f848162 commit a30cdb3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
32 changes: 25 additions & 7 deletions Core/src/main/java/com/plotsquared/core/plot/PlotArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
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;
Expand Down Expand Up @@ -391,6 +393,28 @@ public void loadDefaultConfiguration(ConfigurationSection config) {
}
}

this.spawnEggs = config.getBoolean("event.spawn.egg");
this.spawnCustom = config.getBoolean("event.spawn.custom");
this.spawnBreeding = config.getBoolean("event.spawn.breeding");

if (PlotSquared.get().isWeInitialised()) {
loadFlags(config);
} 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(config), TaskTime.ticks(1));
}

loadConfiguration(config);
}

private void loadFlags(ConfigurationSection config) {
ConsolePlayer.getConsole().sendMessage(
TranslatableCaption.of("flags.loading_area_flags"),
TagResolver.resolver("area", Tag.inserting(Component.text(this.id == null ? this.worldName : this.id)))
);
List<String> flags = config.getStringList("flags.default");
if (flags.isEmpty()) {
flags = config.getStringList("flags");
Expand All @@ -411,10 +435,6 @@ public void loadDefaultConfiguration(ConfigurationSection config) {
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<String> roadflags = config.getStringList("road.flags");
if (roadflags.isEmpty()) {
roadflags = new ArrayList<>();
Expand All @@ -426,14 +446,12 @@ public void loadDefaultConfiguration(ConfigurationSection config) {
}
}
}
this.roadFlags = roadflags.size() > 0;
this.roadFlags = !roadflags.isEmpty();
parseFlags(this.getRoadFlagContainer(), roadflags);
ConsolePlayer.getConsole().sendMessage(
TranslatableCaption.of("flags.road_flags"),
TagResolver.resolver("flags", Tag.inserting(Component.text(roadflags.toString())))
);

loadConfiguration(config);
}

public abstract void loadConfiguration(ConfigurationSection config);
Expand Down
2 changes: 2 additions & 0 deletions Core/src/main/resources/lang/messages_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,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 </red><grey>\"A title\" \"The subtitle\"</grey><red>.",
"flags.delaying_loading_area_flags": "<prefix><gray>Delaying loading flags for area `</gray><dark_aqua><area></dark_aqua><gray>` as WorldEdit is not initialised yet.</gray>",
"flags.loading_area_flags": "<prefix><gray>Loading flags for area: </gray><dark_aqua><area></dark_aqua>",
"flags.area_flags": "<prefix><gray>Area flags: </gray><dark_aqua><flags></dark_aqua>",
"flags.road_flags": "<prefix><gray>Road flags: </gray><dark_aqua><flags></dark_aqua>",
"commands.description.add": "<gray>Allow a user to build in a plot while the plot owner is online.</gray>",
Expand Down

0 comments on commit a30cdb3

Please sign in to comment.