From 33318adc2a046ce9f9e98d75182bb902a40590ce Mon Sep 17 00:00:00 2001 From: RootBeer Date: Sat, 16 May 2026 15:59:20 -0400 Subject: [PATCH] Cover remaining (incorrectly scheduled) calls --- .../openinv/command/PlayerLookupCommand.java | 32 ++++++++++--------- .../lishid/openinv/util/InventoryManager.java | 13 ++------ 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/plugin/src/main/java/com/lishid/openinv/command/PlayerLookupCommand.java b/plugin/src/main/java/com/lishid/openinv/command/PlayerLookupCommand.java index 9081ad1f..8602db89 100644 --- a/plugin/src/main/java/com/lishid/openinv/command/PlayerLookupCommand.java +++ b/plugin/src/main/java/com/lishid/openinv/command/PlayerLookupCommand.java @@ -70,23 +70,25 @@ public void run() { return; } - new WrappedRunnable() { - @Override - public void run() { - // Ensure sender still exists. - if ((sender instanceof Player player) && !player.isValid()) { - return; - } - - // Perform access checks and load target if necessary. - PlayerAccess onlineTarget = access(sender, target, accessInv); - - if (onlineTarget != null) { - handle(sender, onlineTarget, accessInv, args); - } + Runnable sync = () -> { + // Ensure sender still exists. + if ((sender instanceof Player player) && !player.isValid()) { + return; } - }.runTask(PlayerLookupCommand.this.plugin); + // Perform access checks and load target if necessary. + PlayerAccess onlineTarget = access(sender, target, accessInv); + + if (onlineTarget != null) { + handle(sender, onlineTarget, accessInv, args); + } + }; + + if (sender instanceof Player senderPlayer) { + PlayerLookupCommand.this.plugin.getScheduler().runTaskAtEntity(senderPlayer, sync); + } else { + PlayerLookupCommand.this.plugin.getScheduler().runTask(sync); + } } }.runTaskAsynchronously(this.plugin); diff --git a/plugin/src/main/java/com/lishid/openinv/util/InventoryManager.java b/plugin/src/main/java/com/lishid/openinv/util/InventoryManager.java index d6460197..40076679 100644 --- a/plugin/src/main/java/com/lishid/openinv/util/InventoryManager.java +++ b/plugin/src/main/java/com/lishid/openinv/util/InventoryManager.java @@ -22,7 +22,6 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; @@ -40,7 +39,7 @@ public class InventoryManager implements Listener { private final Map inventories = new ConcurrentHashMap<>(); private final Map enderChests = new ConcurrentHashMap<>(); - private final Set expectedCloses = new HashSet<>(); + private final Set expectedCloses = ConcurrentHashMap.newKeySet(); private final @NotNull OpenInv plugin; private final @NotNull Config config; private final @NotNull InternalAccessor accessor; @@ -54,11 +53,6 @@ public InventoryManager(@NotNull OpenInv plugin, @NotNull Config config, @NotNul public void evictAll() { Stream.concat(inventories.values().stream(), enderChests.values().stream()) .map(inventory -> { - // Rather than iterate twice, evict all viewers during remapping. - for (HumanEntity viewer : List.copyOf(inventory.getBukkitInventory().getViewers())) { - expectedCloses.add(viewer.getUniqueId()); - viewer.closeInventory(); - } // If saving is prevented, return a null value for the player to save. if (config.isSaveDisabled() || OpenEvents.saveCancelled(inventory)) { return null; @@ -217,8 +211,7 @@ private void checkViewerAccess(@NotNull T inventor if (alwaysDenied || !connectedState.hasPermission(viewer) || (!Objects.equals(owner.getWorld(), viewer.getWorld()) && !Permissions.ACCESS_CROSSWORLD.hasPermission(viewer))) { - expectedCloses.add(viewer.getUniqueId()); - viewer.closeInventory(); + plugin.getScheduler().runTaskAtEntity(viewer, viewer::closeInventory); } } } @@ -269,7 +262,7 @@ private void save(@NotNull ISpecialInventory inventory) { private @Nullable T remove(@NotNull UUID key, @NotNull T inventory) { for (HumanEntity viewer : List.copyOf(inventory.getBukkitInventory().getViewers())) { expectedCloses.add(viewer.getUniqueId()); - viewer.closeInventory(); + plugin.getScheduler().runTaskAtEntity(viewer, viewer::closeInventory); } return null; }