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
Expand Up @@ -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);

Expand Down
13 changes: 3 additions & 10 deletions plugin/src/main/java/com/lishid/openinv/util/InventoryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,7 +39,7 @@ public class InventoryManager implements Listener {

private final Map<UUID, ISpecialPlayerInventory> inventories = new ConcurrentHashMap<>();
private final Map<UUID, ISpecialEnderChest> enderChests = new ConcurrentHashMap<>();
private final Set<UUID> expectedCloses = new HashSet<>();
private final Set<UUID> expectedCloses = ConcurrentHashMap.newKeySet();
private final @NotNull OpenInv plugin;
private final @NotNull Config config;
private final @NotNull InternalAccessor accessor;
Expand All @@ -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;
Expand Down Expand Up @@ -217,8 +211,7 @@ private <T extends ISpecialInventory> 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);
}
}
}
Expand Down Expand Up @@ -269,7 +262,7 @@ private void save(@NotNull ISpecialInventory inventory) {
private <T extends ISpecialInventory> @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;
}
Expand Down