Skip to content

Commit

Permalink
Fix compilation issues and wrap up work
Browse files Browse the repository at this point in the history
  • Loading branch information
NahuLD committed Oct 21, 2024
1 parent 2af0410 commit 84d9128
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public abstract class OpenChestMenu<T extends Container & ISpecialInventory & In
protected final boolean viewOnly;
protected final boolean ownContainer;
protected final int topSize;
private CraftInventoryView<OpenChestMenu<T>> bukkitEntity;
private CraftInventoryView<OpenChestMenu<T>, Inventory> bukkitEntity;
// Syncher fields
private @Nullable ContainerSynchronizer synchronizer;
private final List<DataSlot> dataSlots = new ArrayList<>();
Expand Down Expand Up @@ -132,15 +132,15 @@ protected void preSlotSetup() {}


@Override
public final @NotNull CraftInventoryView<OpenChestMenu<T>> getBukkitView() {
public final @NotNull CraftInventoryView<OpenChestMenu<T>, Inventory> getBukkitView() {
if (bukkitEntity == null) {
bukkitEntity = createBukkitEntity();
}

return bukkitEntity;
}

protected @NotNull CraftInventoryView<OpenChestMenu<T>> createBukkitEntity() {
protected @NotNull CraftInventoryView<OpenChestMenu<T>, Inventory> createBukkitEntity() {
Inventory top;
if (viewOnly) {
top = new OpenDummyInventory(container);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected void preSlotSetup() {
}

@Override
protected @NotNull CraftInventoryView<OpenChestMenu<OpenInventory>> createBukkitEntity() {
protected @NotNull CraftInventoryView<OpenChestMenu<OpenInventory>, Inventory> createBukkitEntity() {
org.bukkit.inventory.Inventory bukkitInventory;
if (viewOnly) {
bukkitInventory = new OpenDummyInventory(container);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.lishid.openinv.listener;

import com.google.errorprone.annotations.Keep;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.internal.ISpecialEnderChest;
import com.lishid.openinv.internal.ISpecialInventory;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
Expand Down Expand Up @@ -33,10 +34,10 @@
*/
public class LegacyInventoryListener implements Listener {

private final @NotNull Plugin plugin;
private final @NotNull OpenInv plugin;
private final @NotNull Config config;

public LegacyInventoryListener(@NotNull Plugin plugin, @NotNull Config config) {
public LegacyInventoryListener(@NotNull OpenInv plugin, @NotNull Config config) {
this.plugin = plugin;
this.config = config;
}
Expand Down Expand Up @@ -67,7 +68,7 @@ private void onInventoryClick(@NotNull final InventoryClickEvent event) {
event.setCurrentItem(null);

// Complete add action in same tick after event completion.
this.plugin.getServer().getScheduler().runTask(this.plugin, () -> player.getInventory().addItem(clone));
this.plugin.getScheduler().runTaskAtEntity(player, () -> player.getInventory().addItem(clone));
}

@Keep
Expand Down Expand Up @@ -117,7 +118,7 @@ private void onInventoryDrag(@NotNull final InventoryDragEvent event) {
lost.setAmount(overlapLosses);

// Re-add the lost items in the same tick after the event has completed.
plugin.getServer().getScheduler().runTask(plugin, () -> {
this.plugin.getScheduler().runTaskAtEntity(event.getWhoClicked(), () -> {
InventoryView currentOpen = event.getWhoClicked().getOpenInventory();

if (!currentOpen.equals(view)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.github.jikoo.planarwrappers.util.version.BukkitVersions;
import com.github.jikoo.planarwrappers.util.version.Version;
import com.google.errorprone.annotations.Keep;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.event.OpenEvents;
import com.lishid.openinv.internal.ISpecialEnderChest;
import com.lishid.openinv.internal.ISpecialInventory;
Expand Down Expand Up @@ -44,11 +45,11 @@ 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 @NotNull Plugin plugin;
private final @NotNull OpenInv plugin;
private final @NotNull Config config;
private final @NotNull InternalAccessor accessor;

public InventoryManager(@NotNull Plugin plugin, @NotNull Config config, @NotNull InternalAccessor accessor) {
public InventoryManager(@NotNull OpenInv plugin, @NotNull Config config, @NotNull InternalAccessor accessor) {
this.plugin = plugin;
this.config = config;
this.accessor = accessor;
Expand Down Expand Up @@ -164,7 +165,7 @@ private void onInventoryClose(@NotNull InventoryCloseEvent event) {
}

// Schedule task to check in use status later this tick. Closing user is still in viewer list.
plugin.getServer().getScheduler().runTask(plugin, () -> {
this.plugin.getScheduler().runTaskAtEntity(inventory.getPlayer(), () -> {
if (loaded.isInUse()) {
return;
}
Expand Down
12 changes: 7 additions & 5 deletions plugin/src/main/java/com/lishid/openinv/util/PlayerLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.errorprone.annotations.Keep;
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.util.config.Config;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
Expand All @@ -18,6 +19,7 @@
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.logging.Level;
Expand All @@ -28,15 +30,15 @@
*/
public class PlayerLoader implements Listener {

private final @NotNull Plugin plugin;
private final @NotNull OpenInv plugin;
private final @NotNull Config config;
private final @NotNull InventoryManager inventoryManager;
private final @NotNull InternalAccessor internalAccessor;
private final @NotNull Logger logger;
private final @NotNull Cache<String, PlayerProfile> lookupCache;

public PlayerLoader(
@NotNull Plugin plugin,
@NotNull OpenInv plugin,
@NotNull Config config,
@NotNull InventoryManager inventoryManager,
@NotNull InternalAccessor internalAccessor,
Expand Down Expand Up @@ -78,8 +80,8 @@ public PlayerLoader(
return internalAccessor.getPlayerDataManager().loadPlayer(offline);
}

Future<Player> future = Bukkit.getScheduler().callSyncMethod(plugin,
() -> internalAccessor.getPlayerDataManager().loadPlayer(offline));
Future<Player> future = new CompletableFuture();
plugin.getScheduler().runTask(() -> internalAccessor.getPlayerDataManager().loadPlayer(offline));

try {
player = future.get();
Expand Down Expand Up @@ -195,7 +197,7 @@ private void updateMatches(@NotNull PlayerJoinEvent event) {
return;
}

plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, () -> {
plugin.getScheduler().runTaskLaterAsynchronously(() -> {
Iterator<Map.Entry<String, PlayerProfile>> iterator = lookupCache.asMap().entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, PlayerProfile> entry = iterator.next();
Expand Down

0 comments on commit 84d9128

Please sign in to comment.