From 14b0994725788f57f48bb3717e8b7f17e5c5c0a4 Mon Sep 17 00:00:00 2001 From: Ryan Voots Date: Sat, 22 Apr 2023 13:08:58 -0400 Subject: [PATCH 1/2] Fix handling of default ungrouped world option to handle sharing between un-imported worlds properly --- .../AbstractWorldGroupManager.java | 2 +- .../multiverseinventories/WorldGroup.java | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/onarandombox/multiverseinventories/AbstractWorldGroupManager.java b/src/main/java/com/onarandombox/multiverseinventories/AbstractWorldGroupManager.java index 59ee14f5..660e0bde 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/AbstractWorldGroupManager.java +++ b/src/main/java/com/onarandombox/multiverseinventories/AbstractWorldGroupManager.java @@ -54,7 +54,7 @@ public List getGroupsForWorld(String worldName) { worldName = worldName.toLowerCase(); List worldGroups = new ArrayList<>(); for (WorldGroup worldGroup : getGroupNames().values()) { - if (worldGroup.containsWorld(worldName)) { + if (worldGroup.containsWorld(worldName, false)) { worldGroups.add(worldGroup); } } diff --git a/src/main/java/com/onarandombox/multiverseinventories/WorldGroup.java b/src/main/java/com/onarandombox/multiverseinventories/WorldGroup.java index ef42ac42..060a4164 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/WorldGroup.java +++ b/src/main/java/com/onarandombox/multiverseinventories/WorldGroup.java @@ -10,6 +10,7 @@ import java.util.Collection; import java.util.HashSet; import java.util.Set; +import java.util.List; public final class WorldGroup { @@ -174,6 +175,29 @@ public Shares getShares() { * @return True if specified world is part of this group. */ public boolean containsWorld(String worldName) { + return this.containsWorld(worldName, true); + } + + + /** + * @param worldName Name of world to check for. + * @param checkDefaults Check if the world would be part of this group from the default ungrouped world config option. Needed to avoid a recursion when checking if the world is in any other group + * @return True if specified world is part of this group. + */ + public boolean containsWorld(String worldName, boolean checkDefaults) { + boolean direct = this.getWorlds().contains(worldName.toLowerCase()); + + boolean byDefault = false; + + if (checkDefaults && this.isDefault() && plugin.getMVIConfig().isDefaultingUngroupedWorlds()) { + List groups = plugin.getGroupManager().getGroupsForWorld(worldName); + + byDefault = !groups.isEmpty(); + } + + return direct || byDefault; + + return this.getWorlds().contains(worldName.toLowerCase()); } From 267df9834dfec78495456a1849d060d13112bf13 Mon Sep 17 00:00:00 2001 From: Ryan Voots Date: Sat, 22 Apr 2023 13:15:24 -0400 Subject: [PATCH 2/2] Create configuration variable to control allowing non-MV worlds to be handled. --- .../AbstractWorldGroupManager.java | 4 ++-- .../multiverseinventories/InventoriesConfig.java | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/onarandombox/multiverseinventories/AbstractWorldGroupManager.java b/src/main/java/com/onarandombox/multiverseinventories/AbstractWorldGroupManager.java index 660e0bde..443d4124 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/AbstractWorldGroupManager.java +++ b/src/main/java/com/onarandombox/multiverseinventories/AbstractWorldGroupManager.java @@ -58,9 +58,9 @@ public List getGroupsForWorld(String worldName) { worldGroups.add(worldGroup); } } - // Only use the default group for worlds managed by MV-Core + // Only use the default group for worlds managed by MV-Core, unless allowed by config if (worldGroups.isEmpty() && plugin.getMVIConfig().isDefaultingUngroupedWorlds() && - plugin.getCore().getMVWorldManager().isMVWorld(worldName)) { + (plugin.getCore().getMVWorldManager().isMVWorld(worldName) || plugin.getMVIConfig().allowNonMVWorlds())) { Logging.finer("Returning default group for world: " + worldName); worldGroups.add(getDefaultGroup()); } diff --git a/src/main/java/com/onarandombox/multiverseinventories/InventoriesConfig.java b/src/main/java/com/onarandombox/multiverseinventories/InventoriesConfig.java index 867e1a97..8221b41f 100644 --- a/src/main/java/com/onarandombox/multiverseinventories/InventoriesConfig.java +++ b/src/main/java/com/onarandombox/multiverseinventories/InventoriesConfig.java @@ -40,6 +40,11 @@ public enum Path { */ DEFAULT_UNGROUPED_WORLDS("settings.default_ungrouped_worlds", false, "# If set to true, any world not listed in a group will automatically use the settings for the default group!"), + /** + * Allow worlds not part of Multiverse to be considered ungrouped + */ + ALLOW_NONMV_WORLDS("settings.allow_nonmv_worlds", false, "# If set to true, any world that isn't imported into MV yet, can be treated as an ungrouped world. Requires default_ungrouped_worlds to function properly."), + /** * Whether or not to save/load player data on log out/in. */ @@ -277,6 +282,13 @@ public Shares getOptionalShares() { public boolean isDefaultingUngroupedWorlds() { return this.getBoolean(Path.DEFAULT_UNGROUPED_WORLDS); } + + /** + * @return true if we should handle non-MV worlds also. + */ + public boolean isAllowNonMVWorlds() { + return this.getBoolean(Path.ALLOW_NONMV_WORLDS); + } /** * @param useDefaultGroup Set this to true to use the default group for ungrouped worlds.