Skip to content

Commit 99a7609

Browse files
committed
Fix Multiverse Inventories compatibility
1 parent 32e77c3 commit 99a7609

File tree

3 files changed

+92
-77
lines changed

3 files changed

+92
-77
lines changed

build.gradle.kts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,21 @@ repositories {
3737

3838
dependencies {
3939
testImplementation("junit:junit:4.13.1")
40-
paperweight.paperDevBundle("1.21.9-R0.1-SNAPSHOT")
40+
paperweight.paperDevBundle("1.21.10-R0.1-SNAPSHOT")
4141
compileOnly("com.bergerkiller.bukkit:MyWorlds:1.12-v2") {
4242
exclude(group="org.spigotmc") // Don't let Spigot API overwrite Paper
4343
}
4444
compileOnly("com.griefcraft:LWC:4.3.2")
45-
compileOnly("com.onarandombox.multiversecore:Multiverse-Core:4.1.0")
46-
compileOnly("com.onarandombox.multiverseinventories:Multiverse-Inventories:3.0.0")
45+
compileOnly("org.mvplugins.multiverse.core:multiverse-core:5.0.2")
46+
compileOnly("org.mvplugins.multiverse.inventories:multiverse-inventories:5.0.2")
4747
compileOnly("me.drayshak.worldinventories:WorldInventories:1.7.0")
4848
compileOnly("nl.rutgerkok:blocklocker:1.9.2")
4949
compileOnly("org.yi.acru.bukkit:Lockette:1.7.12")
5050
compileOnly("uk.co.tggl.pluckerpluck.multiinv:MultiInv:3.3.0")
5151
}
5252

5353
group = "nl.rutgerkok.betterenderchest"
54-
version = "2.7.2"
54+
version = "2.7.3-SNAPSHOT"
5555
description = "BetterEnderChest"
5656
java.sourceCompatibility = JavaVersion.VERSION_21
5757

src/main/java/nl/rutgerkok/betterenderchest/importers/MultiverseInventoriesImporter.java

Lines changed: 87 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
package nl.rutgerkok.betterenderchest.importers;
22

3-
import java.io.IOException;
43
import java.util.HashSet;
54
import java.util.List;
65
import java.util.Set;
6+
import java.util.concurrent.ExecutionException;
77

8+
import com.google.common.util.concurrent.Futures;
9+
import com.google.common.util.concurrent.ListenableFuture;
10+
import com.google.common.util.concurrent.SettableFuture;
11+
import nl.rutgerkok.betterenderchest.exception.ChestNotFoundException;
812
import org.bukkit.Bukkit;
913
import org.bukkit.OfflinePlayer;
1014
import org.bukkit.inventory.Inventory;
1115
import org.bukkit.inventory.ItemStack;
1216

13-
import com.onarandombox.multiverseinventories.MultiverseInventories;
14-
import com.onarandombox.multiverseinventories.WorldGroup;
15-
import com.onarandombox.multiverseinventories.profile.GlobalProfile;
16-
import com.onarandombox.multiverseinventories.profile.PlayerProfile;
17-
import com.onarandombox.multiverseinventories.profile.ProfileType;
18-
import com.onarandombox.multiverseinventories.profile.ProfileTypes;
19-
import com.onarandombox.multiverseinventories.share.Sharables;
17+
import org.mvplugins.multiverse.inventories.MultiverseInventoriesApi;
18+
import org.mvplugins.multiverse.inventories.profile.data.PlayerProfile;
19+
import org.mvplugins.multiverse.inventories.profile.key.GlobalProfileKey;
20+
import org.mvplugins.multiverse.inventories.profile.key.ProfileType;
21+
import org.mvplugins.multiverse.inventories.profile.key.ProfileTypes;
22+
import org.mvplugins.multiverse.inventories.share.Sharables;
2023

2124
import nl.rutgerkok.betterenderchest.BetterEnderChest;
2225
import nl.rutgerkok.betterenderchest.chestowner.ChestOwner;
26+
import org.mvplugins.multiverse.inventories.profile.group.WorldGroup;
2327

2428

2529
public class MultiverseInventoriesImporter extends InventoryImporter {
@@ -35,96 +39,107 @@ public Priority getPriority() {
3539
}
3640

3741
@Override
38-
public Inventory importInventory(ChestOwner chestOwner, nl.rutgerkok.betterenderchest.WorldGroup worldGroup,
39-
BetterEnderChest plugin) throws IOException {
42+
public ListenableFuture<Inventory> importInventoryAsync(final ChestOwner chestOwner, nl.rutgerkok.betterenderchest.WorldGroup worldGroup, BetterEnderChest plugin) {
4043
String groupName = worldGroup.getGroupName();
4144

4245
OfflinePlayer offlinePlayer = chestOwner.getOfflinePlayer();
4346
if (offlinePlayer == null || chestOwner.isSpecialChest()) {
4447
// Public chests and default chests cannot be imported.
45-
return null;
48+
return Futures.immediateFailedFuture(new ChestNotFoundException(chestOwner, worldGroup));
4649
}
4750

4851
// Get the plugin
49-
MultiverseInventories multiverseInventories = (MultiverseInventories) Bukkit.getServer().getPluginManager().getPlugin("Multiverse-Inventories");
52+
MultiverseInventoriesApi multiverseInventories = MultiverseInventoriesApi.get();
5053

5154
// Make groupName case-correct
52-
WorldGroup group = null;
53-
List<WorldGroup> multiverseInventoriesGroups = multiverseInventories.getGroupManager().getGroups();
54-
for (WorldGroup aGroup : multiverseInventoriesGroups) {
55-
if (aGroup.getName().equalsIgnoreCase(groupName)) {
56-
group = aGroup;
57-
break;
58-
}
59-
}
55+
List<WorldGroup> multiverseInventoriesGroups = multiverseInventories.getWorldGroupManager().getGroups();
56+
57+
WorldGroup group = multiverseInventoriesGroups.stream()
58+
.filter(aGroup -> aGroup.getName().equalsIgnoreCase(groupName))
59+
.findAny()
60+
.orElse(null);
6061

6162
// Check if a matching group has been found
6263
if (group == null) {
6364
plugin.warning("No matching Multiverse-Inventories group found for " + groupName + ". Cannot import " + chestOwner.getDisplayName() + ".");
64-
return null;
65+
return Futures.immediateFailedFuture(new ChestNotFoundException(chestOwner, worldGroup));
6566
}
6667

6768
// Get the global profile of the player
68-
GlobalProfile globalProfile = multiverseInventories.getData().getGlobalProfile(offlinePlayer.getName(),
69-
offlinePlayer.getUniqueId());
70-
if (globalProfile == null) {
71-
plugin.debug("It seems that there is no data for " + chestOwner.getDisplayName() + ", so nothing can be imported.");
72-
return null;
73-
}
74-
if (globalProfile.getLastWorld() == null) {
75-
plugin.debug("It seems that the world of " + chestOwner.getDisplayName() + " is null, so nothing can be imported.");
76-
return null;
77-
}
78-
79-
// If the player is in the current worldgroup, it should load from
80-
// vanilla (Multiverse-Inventories would return an outdated inventory).
81-
// If the player is in anthor worldgroup, it should load from
82-
// Multiverse-Inventories.
83-
if (group.containsWorld(globalProfile.getLastWorld())) {
84-
// Player is in the current group, load from vanilla
85-
return plugin.getInventoryImporters().getRegistration("vanilla").importInventory(chestOwner, worldGroup, plugin);
86-
} else {
87-
// Get the correct gamemode
88-
ProfileType profileType;
89-
if (multiverseInventories.getMVIConfig().isUsingGameModeProfiles()) {
90-
// BetterEnderChest doesn't support seperation of gamemodes, so
91-
// use the default gamemode of the server
92-
profileType = ProfileTypes.forGameMode(Bukkit.getDefaultGameMode());
93-
} else {
94-
// Multiverse-Inventories gamemode seperation disabled, use
95-
// SURVIVAL
96-
profileType = ProfileTypes.SURVIVAL;
69+
SettableFuture<Inventory> returnedInventory = SettableFuture.create();
70+
multiverseInventories.getProfileDataSource().getGlobalProfile(GlobalProfileKey.of(offlinePlayer)).thenAcceptAsync(globalProfile -> {
71+
if (globalProfile == null) {
72+
plugin.debug("It seems that there is no data for " + chestOwner.getDisplayName() + ", so nothing can be imported.");
73+
returnedInventory.setException(new ChestNotFoundException(chestOwner, worldGroup));
74+
return;
9775
}
98-
99-
// Get the data
100-
PlayerProfile playerData = multiverseInventories.getGroupManager().getGroup(groupName)
101-
.getGroupProfileContainer().getPlayerData(profileType, offlinePlayer);
102-
103-
// Return nothing if there is nothing
104-
if (playerData == null) {
105-
return null;
76+
if (globalProfile.getLastWorld() == null) {
77+
plugin.debug("It seems that the world of " + chestOwner.getDisplayName() + " is null, so nothing can be imported.");
78+
returnedInventory.setException(new ChestNotFoundException(chestOwner, worldGroup));
79+
return;
10680
}
10781

108-
// Get the item stacks
109-
ItemStack[] stacks = playerData.get(Sharables.ENDER_CHEST);
110-
111-
// Return nothing if there is nothing
112-
if (stacks == null || stacks.length == 0) {
113-
return null;
82+
// If the player is in the current worldgroup, it should load from
83+
// vanilla (Multiverse-Inventories would return an outdated inventory).
84+
// If the player is in anothor worldgroup, it should load from
85+
// Multiverse-Inventories.
86+
if (group.containsWorld(globalProfile.getLastWorld())) {
87+
// Player is in the current group, load from vanilla
88+
returnedInventory.setFuture(plugin.getInventoryImporters().getRegistration("vanilla").importInventoryAsync(chestOwner, worldGroup, plugin));
89+
} else {
90+
// Get the correct gamemode
91+
ProfileType profileType;
92+
if (multiverseInventories.getInventoriesConfig().getEnableGamemodeShareHandling()) {
93+
// BetterEnderChest doesn't support seperation of gamemodes, so
94+
// use the default gamemode of the server
95+
profileType = ProfileTypes.forGameMode(Bukkit.getDefaultGameMode());
96+
} else {
97+
// Multiverse-Inventories gamemode seperation disabled, use the default
98+
profileType = ProfileTypes.getDefault();
99+
}
100+
101+
// Get the data (we can halt this thread, we're on a worker thread anyway)
102+
try {
103+
PlayerProfile playerData = multiverseInventories.getWorldGroupManager().getGroup(groupName)
104+
.getGroupProfileContainer().getPlayerData(profileType, offlinePlayer).get();
105+
106+
// Return nothing if there is nothing
107+
if (playerData == null) {
108+
returnedInventory.setException(new ChestNotFoundException(chestOwner, worldGroup));
109+
return;
110+
}
111+
112+
// Get the item stacks
113+
ItemStack[] stacks = playerData.get(Sharables.ENDER_CHEST);
114+
115+
// Return nothing if there is nothing
116+
if (stacks == null || stacks.length == 0) {
117+
returnedInventory.setException(new ChestNotFoundException(chestOwner, worldGroup));
118+
return;
119+
}
120+
121+
// Add everything from Multiverse-Inventories to betterInventory
122+
Inventory betterInventory = plugin.getEmptyInventoryProvider().loadEmptyInventory(chestOwner, worldGroup);
123+
betterInventory.setContents(stacks);
124+
returnedInventory.set(betterInventory);
125+
} catch (InterruptedException e) {
126+
returnedInventory.setException(e);
127+
} catch (ExecutionException e) {
128+
returnedInventory.setException(e.getCause());
129+
}
114130
}
115-
116-
// Add everything from Multiverse-Inventories to betterInventory
117-
Inventory betterInventory = plugin.getEmptyInventoryProvider().loadEmptyInventory(chestOwner, worldGroup);
118-
betterInventory.setContents(stacks);
119-
return betterInventory;
120-
}
131+
}, plugin.getExecutors().workerThreadExecutor()).exceptionally(e -> {
132+
returnedInventory.setException(e);
133+
return null;
134+
});
135+
return returnedInventory;
121136
}
122137

123138
@Override
124139
public Iterable<nl.rutgerkok.betterenderchest.WorldGroup> importWorldGroups(BetterEnderChest plugin) {
125140
Set<nl.rutgerkok.betterenderchest.WorldGroup> becGroups = new HashSet<>();
126-
MultiverseInventories multiverseInventories = (MultiverseInventories) Bukkit.getServer().getPluginManager().getPlugin("Multiverse-Inventories");
127-
for (WorldGroup miGroup : multiverseInventories.getGroupManager().getGroups()) {
141+
MultiverseInventoriesApi multiverseInventories = MultiverseInventoriesApi.get();
142+
for (WorldGroup miGroup : multiverseInventories.getWorldGroupManager().getGroups()) {
128143
// Convert each group config
129144
nl.rutgerkok.betterenderchest.WorldGroup worldGroup = new nl.rutgerkok.betterenderchest.WorldGroup(
130145
miGroup.getName());

src/main/resources/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: BetterEnderChest
22
main: nl.rutgerkok.betterenderchest.BetterEnderChestPlugin
33
description: 'Secure and configurable Ender Chests'
4-
version: "2.7.2"
4+
version: "2.7.3"
55
author: 'Rutger Kok'
66
api-version: '1.21.9'
77
softdepend:

0 commit comments

Comments
 (0)