9
0
mirror of https://github.com/WiIIiam278/HuskSync.git synced 2025-12-25 17:49:20 +00:00

Fix inventory and ender chest commands

This commit is contained in:
William
2022-07-11 12:32:51 +01:00
parent e5e848126a
commit bc9d31abc8
7 changed files with 44 additions and 27 deletions

View File

@@ -65,17 +65,18 @@ public class EnderChestCommand extends CommandBase implements TabCompletable {
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.getDefault())
.format(userDataSnapshot.versionTimestamp()))
.ifPresent(player::sendMessage);
final ItemData enderChestDataOnClose = plugin.getDataEditor().openItemEditorMenu(player, menu).join();
if (!menu.canEdit) {
return;
}
final UserData updatedUserData = new UserData(data.getStatusData(), data.getInventoryData(),
enderChestDataOnClose, data.getPotionEffectsData(), data.getAdvancementData(),
data.getStatisticsData(), data.getLocationData(),
data.getPersistentDataContainerData(),
plugin.getMinecraftVersion().toString());
plugin.getDatabase().setUserData(dataOwner, updatedUserData, DataSaveCause.ENDERCHEST_COMMAND).join();
plugin.getRedisManager().sendUserDataUpdate(dataOwner, updatedUserData).join();
plugin.getDataEditor().openItemEditorMenu(player, menu).thenAccept(enderChestDataOnClose -> {
if (!menu.canEdit) {
return;
}
final UserData updatedUserData = new UserData(data.getStatusData(), data.getInventoryData(),
enderChestDataOnClose, data.getPotionEffectsData(), data.getAdvancementData(),
data.getStatisticsData(), data.getLocationData(),
data.getPersistentDataContainerData(),
plugin.getMinecraftVersion().toString());
plugin.getDatabase().setUserData(dataOwner, updatedUserData, DataSaveCause.ENDERCHEST_COMMAND).join();
plugin.getRedisManager().sendUserDataUpdate(dataOwner, updatedUserData).join();
});
});
}

View File

@@ -65,17 +65,18 @@ public class InventoryCommand extends CommandBase implements TabCompletable {
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.getDefault())
.format(userDataSnapshot.versionTimestamp()))
.ifPresent(player::sendMessage);
final ItemData inventoryDataOnClose = plugin.getDataEditor().openItemEditorMenu(player, menu).join();
if (!menu.canEdit) {
return;
}
final UserData updatedUserData = new UserData(data.getStatusData(), inventoryDataOnClose,
data.getEnderChestData(), data.getPotionEffectsData(), data.getAdvancementData(),
data.getStatisticsData(), data.getLocationData(),
data.getPersistentDataContainerData(),
plugin.getMinecraftVersion().toString());
plugin.getDatabase().setUserData(dataOwner, updatedUserData, DataSaveCause.INVENTORY_COMMAND).join();
plugin.getRedisManager().sendUserDataUpdate(dataOwner, updatedUserData).join();
plugin.getDataEditor().openItemEditorMenu(player, menu).thenAccept(inventoryDataOnClose -> {
if (!menu.canEdit) {
return;
}
final UserData updatedUserData = new UserData(data.getStatusData(), inventoryDataOnClose,
data.getEnderChestData(), data.getPotionEffectsData(), data.getAdvancementData(),
data.getStatisticsData(), data.getLocationData(),
data.getPersistentDataContainerData(),
plugin.getMinecraftVersion().toString());
plugin.getDatabase().setUserData(dataOwner, updatedUserData, DataSaveCause.INVENTORY_COMMAND).join();
plugin.getRedisManager().sendUserDataUpdate(dataOwner, updatedUserData).join();
});
});
}

View File

@@ -42,6 +42,7 @@ public class DataEditor {
*/
public CompletableFuture<ItemData> openItemEditorMenu(@NotNull OnlineUser user,
@NotNull ItemEditorMenu itemEditorMenu) {
//user.closeOpenInventories();
this.openInventoryMenus.put(user.uuid, itemEditorMenu);
return itemEditorMenu.showInventory(user);
}
@@ -54,6 +55,7 @@ public class DataEditor {
*/
public void closeInventoryMenu(@NotNull OnlineUser user, @NotNull ItemData itemData) {
if (this.openInventoryMenus.containsKey(user.uuid)) {
System.out.println("Closing inventory menu for " + user.uuid);
this.openInventoryMenus.get(user.uuid).closeInventory(itemData);
}
this.openInventoryMenus.remove(user.uuid);

View File

@@ -258,6 +258,11 @@ public abstract class OnlineUser extends User {
*/
public abstract void showMenu(@NotNull ItemEditorMenu menu);
/**
* Close inventories the player currently has open
*/
public abstract void closeOpenInventories();
/**
* Get the player's current {@link UserData}
*