Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow handling of non MV worlds for shares #524

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ public List<WorldGroup> getGroupsForWorld(String worldName) {
worldName = worldName.toLowerCase();
List<WorldGroup> worldGroups = new ArrayList<>();
for (WorldGroup worldGroup : getGroupNames().values()) {
if (worldGroup.containsWorld(worldName)) {
if (worldGroup.containsWorld(worldName, false)) {
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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.List;

public final class WorldGroup {

Expand Down Expand Up @@ -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<WorldGroup> groups = plugin.getGroupManager().getGroupsForWorld(worldName);

byDefault = !groups.isEmpty();
}

return direct || byDefault;


return this.getWorlds().contains(worldName.toLowerCase());
}

Expand Down