Skip to content
Merged
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
@@ -1,8 +1,10 @@
package org.mvplugins.multiverse.inventories.listeners;

import com.dumptruckman.minecraft.util.Logging;
import org.mvplugins.multiverse.external.jetbrains.annotations.Nullable;
import org.mvplugins.multiverse.inventories.MultiverseInventories;
import org.mvplugins.multiverse.inventories.ShareHandlingUpdater;
import org.mvplugins.multiverse.inventories.config.InventoriesConfig;
import org.mvplugins.multiverse.inventories.profile.PersistingProfile;
import org.mvplugins.multiverse.inventories.event.ShareHandlingEvent;
import org.mvplugins.multiverse.inventories.profile.PlayerProfile;
Expand All @@ -26,6 +28,7 @@ public abstract class ShareHandler {

protected final MultiverseInventories inventories;
protected final Player player;
protected final @Nullable InventoriesConfig inventoriesConfig;
protected final WorldGroupManager worldGroupManager;
protected final ProfileContainerStore worldProfileContainerStore;
final AffectedProfiles affectedProfiles;
Expand All @@ -34,6 +37,7 @@ public abstract class ShareHandler {
this.inventories = inventories;
this.player = player;
this.affectedProfiles = new AffectedProfiles();
this.inventoriesConfig = inventories.getServiceLocator().getService(InventoriesConfig.class);
this.worldGroupManager = inventories.getServiceLocator().getService(WorldGroupManager.class);
this.worldProfileContainerStore = inventories.getServiceLocator()
.getService(ProfileContainerStoreProvider.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ private boolean isPlayerBypassingChange(WorldGroup worldGroup) {
}

private boolean isFromWorldNotInToWorldGroup(WorldGroup worldGroup) {
if (inventoriesConfig.isDefaultingUngroupedWorlds()
&& !worldGroupManager.hasConfiguredGroup(fromWorld)
&& worldGroup.equals(worldGroupManager.getDefaultGroup())) {
return false;
}
return !worldGroup.containsWorld(fromWorld);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.dumptruckman.minecraft.util.Logging;
import org.jvnet.hk2.annotations.Contract;
import org.mvplugins.multiverse.core.world.LoadedMultiverseWorld;
import org.mvplugins.multiverse.core.world.WorldManager;
import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull;
import org.mvplugins.multiverse.inventories.MultiverseInventories;
Expand All @@ -20,6 +21,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* Abstract implementation of GroupManager with no persistence of groups.
Expand Down Expand Up @@ -86,8 +88,9 @@ public List<WorldGroup> getGroupsForWorld(String worldName) {
* {@inheritDoc}
*/
@Override
public boolean hasGroup(String worldName) {
return !getGroupsForWorld(worldName).isEmpty();
public boolean hasConfiguredGroup(String worldName) {
return groupNamesMap.values().stream()
.anyMatch(worldGroup -> worldGroup.getWorlds().contains(worldName));
}

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

protected void persistGroup(final WorldGroup worldGroup) {
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -134,24 +134,24 @@ public void createDefaultGroup() {
if (getGroup(DEFAULT_GROUP_NAME) != null) {
return;
}
World defaultWorld = Bukkit.getWorlds().get(0);
World defaultWorld = worldManager.getDefaultWorld()
.flatMap(LoadedMultiverseWorld::getBukkitWorld)
.fold(() -> Bukkit.getWorlds().get(0), world -> world);
World defaultNether = Bukkit.getWorld(defaultWorld.getName() + "_nether");
World defaultEnd = Bukkit.getWorld(defaultWorld.getName() + "_the_end");
WorldGroup worldGroup = new WorldGroup(this, profileContainerStoreProvider, DEFAULT_GROUP_NAME);
worldGroup.getShares().mergeShares(Sharables.allOf());
worldGroup.addWorld(defaultWorld);
StringBuilder worlds = new StringBuilder().append(defaultWorld.getName());
if (defaultNether != null) {
worldGroup.addWorld(defaultNether);
worlds.append(", ").append(defaultNether.getName());
}
if (defaultEnd != null) {
worldGroup.addWorld(defaultEnd);
worlds.append(", ").append(defaultEnd.getName());
}
updateGroup(worldGroup);
inventoriesConfig.save();
Logging.info("Created a default group for you containing all of your default worlds: " + worlds.toString());
Logging.info("Created a default group for you containing all of your default worlds: "
+ String.join(", ", worldGroup.getWorlds()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.jvnet.hk2.annotations.Contract;
import org.mvplugins.multiverse.external.vavr.control.Try;

import java.io.IOException;
import java.util.List;

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

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