Skip to content

Commit 6e2e514

Browse files
authored
Merge pull request #568 from Multiverse/ben/mv5/fix-default-group
Fix profile being updated for ungrouped world even when default_ungro…
2 parents a791580 + 8fb6d0c commit 6e2e514

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

src/main/java/org/mvplugins/multiverse/inventories/listeners/ShareHandler.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package org.mvplugins.multiverse.inventories.listeners;
22

33
import com.dumptruckman.minecraft.util.Logging;
4+
import org.mvplugins.multiverse.external.jetbrains.annotations.Nullable;
45
import org.mvplugins.multiverse.inventories.MultiverseInventories;
56
import org.mvplugins.multiverse.inventories.ShareHandlingUpdater;
7+
import org.mvplugins.multiverse.inventories.config.InventoriesConfig;
68
import org.mvplugins.multiverse.inventories.profile.PersistingProfile;
79
import org.mvplugins.multiverse.inventories.event.ShareHandlingEvent;
810
import org.mvplugins.multiverse.inventories.profile.PlayerProfile;
@@ -26,6 +28,7 @@ public abstract class ShareHandler {
2628

2729
protected final MultiverseInventories inventories;
2830
protected final Player player;
31+
protected final @Nullable InventoriesConfig inventoriesConfig;
2932
protected final WorldGroupManager worldGroupManager;
3033
protected final ProfileContainerStore worldProfileContainerStore;
3134
final AffectedProfiles affectedProfiles;
@@ -34,6 +37,7 @@ public abstract class ShareHandler {
3437
this.inventories = inventories;
3538
this.player = player;
3639
this.affectedProfiles = new AffectedProfiles();
40+
this.inventoriesConfig = inventories.getServiceLocator().getService(InventoriesConfig.class);
3741
this.worldGroupManager = inventories.getServiceLocator().getService(WorldGroupManager.class);
3842
this.worldProfileContainerStore = inventories.getServiceLocator()
3943
.getService(ProfileContainerStoreProvider.class)

src/main/java/org/mvplugins/multiverse/inventories/listeners/WorldChangeShareHandler.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ private boolean isPlayerBypassingChange(WorldGroup worldGroup) {
144144
}
145145

146146
private boolean isFromWorldNotInToWorldGroup(WorldGroup worldGroup) {
147+
if (inventoriesConfig.isDefaultingUngroupedWorlds()
148+
&& !worldGroupManager.hasConfiguredGroup(fromWorld)
149+
&& worldGroup.equals(worldGroupManager.getDefaultGroup())) {
150+
return false;
151+
}
147152
return !worldGroup.containsWorld(fromWorld);
148153
}
149154

src/main/java/org/mvplugins/multiverse/inventories/profile/group/AbstractWorldGroupManager.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.dumptruckman.minecraft.util.Logging;
44
import org.jvnet.hk2.annotations.Contract;
5+
import org.mvplugins.multiverse.core.world.LoadedMultiverseWorld;
56
import org.mvplugins.multiverse.core.world.WorldManager;
67
import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull;
78
import org.mvplugins.multiverse.inventories.MultiverseInventories;
@@ -20,6 +21,7 @@
2021
import java.util.LinkedHashMap;
2122
import java.util.List;
2223
import java.util.Map;
24+
import java.util.stream.Collectors;
2325

2426
/**
2527
* Abstract implementation of GroupManager with no persistence of groups.
@@ -86,8 +88,9 @@ public List<WorldGroup> getGroupsForWorld(String worldName) {
8688
* {@inheritDoc}
8789
*/
8890
@Override
89-
public boolean hasGroup(String worldName) {
90-
return !getGroupsForWorld(worldName).isEmpty();
91+
public boolean hasConfiguredGroup(String worldName) {
92+
return groupNamesMap.values().stream()
93+
.anyMatch(worldGroup -> worldGroup.getWorlds().contains(worldName));
9194
}
9295

9396
/**
@@ -104,9 +107,6 @@ public void updateGroup(final WorldGroup worldGroup) {
104107
getGroupNames().put(worldGroup.getName().toLowerCase(), worldGroup);
105108
}
106109

107-
protected void persistGroup(final WorldGroup worldGroup) {
108-
}
109-
110110
/**
111111
* {@inheritDoc}
112112
*/
@@ -134,24 +134,24 @@ public void createDefaultGroup() {
134134
if (getGroup(DEFAULT_GROUP_NAME) != null) {
135135
return;
136136
}
137-
World defaultWorld = Bukkit.getWorlds().get(0);
137+
World defaultWorld = worldManager.getDefaultWorld()
138+
.flatMap(LoadedMultiverseWorld::getBukkitWorld)
139+
.fold(() -> Bukkit.getWorlds().get(0), world -> world);
138140
World defaultNether = Bukkit.getWorld(defaultWorld.getName() + "_nether");
139141
World defaultEnd = Bukkit.getWorld(defaultWorld.getName() + "_the_end");
140142
WorldGroup worldGroup = new WorldGroup(this, profileContainerStoreProvider, DEFAULT_GROUP_NAME);
141143
worldGroup.getShares().mergeShares(Sharables.allOf());
142144
worldGroup.addWorld(defaultWorld);
143-
StringBuilder worlds = new StringBuilder().append(defaultWorld.getName());
144145
if (defaultNether != null) {
145146
worldGroup.addWorld(defaultNether);
146-
worlds.append(", ").append(defaultNether.getName());
147147
}
148148
if (defaultEnd != null) {
149149
worldGroup.addWorld(defaultEnd);
150-
worlds.append(", ").append(defaultEnd.getName());
151150
}
152151
updateGroup(worldGroup);
153152
inventoriesConfig.save();
154-
Logging.info("Created a default group for you containing all of your default worlds: " + worlds.toString());
153+
Logging.info("Created a default group for you containing all of your default worlds: "
154+
+ String.join(", ", worldGroup.getWorlds()));
155155
}
156156

157157
/**

src/main/java/org/mvplugins/multiverse/inventories/profile/group/WorldGroupManager.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import org.jvnet.hk2.annotations.Contract;
55
import org.mvplugins.multiverse.external.vavr.control.Try;
66

7-
import java.io.IOException;
87
import java.util.List;
98

109
/**
@@ -51,7 +50,7 @@ public sealed interface WorldGroupManager permits AbstractWorldGroupManager {
5150
* @param worldName Name of the world to check.
5251
* @return true if this world has one or more groups.
5352
*/
54-
boolean hasGroup(String worldName);
53+
boolean hasConfiguredGroup(String worldName);
5554

5655
/**
5756
* <p>Adds or updates a world group in Multiverse-Inventories.</p>

0 commit comments

Comments
 (0)