|
|
@ -4,6 +4,7 @@ import net.william278.husksync.BukkitHuskSync;
|
|
|
|
import net.william278.husksync.data.BukkitSerializer;
|
|
|
|
import net.william278.husksync.data.BukkitSerializer;
|
|
|
|
import net.william278.husksync.data.DataSerializationException;
|
|
|
|
import net.william278.husksync.data.DataSerializationException;
|
|
|
|
import net.william278.husksync.data.ItemData;
|
|
|
|
import net.william278.husksync.data.ItemData;
|
|
|
|
|
|
|
|
import net.william278.husksync.editor.ItemEditorMenuType;
|
|
|
|
import net.william278.husksync.player.BukkitPlayer;
|
|
|
|
import net.william278.husksync.player.BukkitPlayer;
|
|
|
|
import net.william278.husksync.player.OnlineUser;
|
|
|
|
import net.william278.husksync.player.OnlineUser;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
@ -24,6 +25,7 @@ import org.bukkit.event.world.WorldSaveEvent;
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
@ -46,25 +48,29 @@ public class BukkitEventListener extends EventListener implements Listener {
|
|
|
|
|
|
|
|
|
|
|
|
@EventHandler(ignoreCancelled = true)
|
|
|
|
@EventHandler(ignoreCancelled = true)
|
|
|
|
public void onWorldSave(@NotNull WorldSaveEvent event) {
|
|
|
|
public void onWorldSave(@NotNull WorldSaveEvent event) {
|
|
|
|
super.handleWorldSave(event.getWorld().getPlayers().stream().map(BukkitPlayer::adapt)
|
|
|
|
CompletableFuture.runAsync(() -> super.handleAsyncWorldSave(event.getWorld().getPlayers().stream()
|
|
|
|
.collect(Collectors.toList()));
|
|
|
|
.map(BukkitPlayer::adapt).collect(Collectors.toList())));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@EventHandler(ignoreCancelled = true)
|
|
|
|
@EventHandler(ignoreCancelled = true)
|
|
|
|
public void onInventoryClose(@NotNull InventoryCloseEvent event) {
|
|
|
|
public void onInventoryClose(@NotNull InventoryCloseEvent event) {
|
|
|
|
|
|
|
|
CompletableFuture.runAsync(() -> {
|
|
|
|
if (event.getPlayer() instanceof Player player) {
|
|
|
|
if (event.getPlayer() instanceof Player player) {
|
|
|
|
final OnlineUser user = BukkitPlayer.adapt(player);
|
|
|
|
final OnlineUser user = BukkitPlayer.adapt(player);
|
|
|
|
if (plugin.getDataEditor().isEditingInventoryData(user)) {
|
|
|
|
plugin.getDataEditor().getEditingInventoryData(user).ifPresent(menu -> {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
BukkitSerializer.serializeItemStackArray(Arrays.copyOf(event.getInventory().getContents(),
|
|
|
|
BukkitSerializer.serializeItemStackArray(Arrays.copyOf(event.getInventory().getContents(),
|
|
|
|
event.getPlayer().getInventory().getSize())).thenAccept(
|
|
|
|
menu.itemEditorMenuType == ItemEditorMenuType.INVENTORY_VIEWER
|
|
|
|
|
|
|
|
? player.getInventory().getSize()
|
|
|
|
|
|
|
|
: player.getEnderChest().getSize())).thenAccept(
|
|
|
|
serializedInventory -> super.handleMenuClose(user, new ItemData(serializedInventory)));
|
|
|
|
serializedInventory -> super.handleMenuClose(user, new ItemData(serializedInventory)));
|
|
|
|
} catch (DataSerializationException e) {
|
|
|
|
} catch (DataSerializationException e) {
|
|
|
|
plugin.getLoggingAdapter().log(Level.SEVERE,
|
|
|
|
plugin.getLoggingAdapter().log(Level.SEVERE,
|
|
|
|
"Failed to serialize inventory data during menu close", e);
|
|
|
|
"Failed to serialize inventory data during menu close", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|