Skip to content

Commit

Permalink
More responsibility reduction
Browse files Browse the repository at this point in the history
  • Loading branch information
Jikoo committed Aug 7, 2024
1 parent e8ab490 commit e642616
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion plugin/src/main/java/com/lishid/openinv/OpenInv.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void onEnable() {
// Perform initial config load.
reloadConfig();

inventoryManager = new InventoryManager(this, accessor);
inventoryManager = new InventoryManager(this, config, accessor);
playerLoader = new PlayerLoader(this, config, inventoryManager, accessor, getLogger());

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
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;
import com.lishid.openinv.internal.ISpecialPlayerInventory;
import com.lishid.openinv.util.config.Config;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
Expand All @@ -19,6 +19,7 @@
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -43,11 +44,13 @@ 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 OpenInv plugin;
private final @NotNull Plugin plugin;
private final @NotNull Config config;
private final @NotNull InternalAccessor accessor;

public InventoryManager(@NotNull OpenInv plugin, @NotNull InternalAccessor accessor) {
public InventoryManager(@NotNull Plugin plugin, @NotNull Config config, @NotNull InternalAccessor accessor) {
this.plugin = plugin;
this.config = config;
this.accessor = accessor;
}

Expand All @@ -60,7 +63,7 @@ public void evictAll() {
viewer.closeInventory();
}
// If saving is prevented, return a null value for the player to save.
if (plugin.disableSaving() || OpenEvents.saveCancelled(inventory)) {
if (config.isSaveDisabled() || OpenEvents.saveCancelled(inventory)) {
return null;
}
if (inventory.getPlayer() instanceof Player player) {
Expand Down Expand Up @@ -194,7 +197,7 @@ private <T extends ISpecialInventory> void checkViewerAccess(@NotNull T inventor

Player owner = (Player) inventory.getPlayer();
Permissions connectedState = online ? Permissions.ACCESS_ONLINE : Permissions.ACCESS_OFFLINE;
boolean alwaysDenied = !online && plugin.disableOfflineAccess();
boolean alwaysDenied = !online && config.isOfflineDisabled();

// Copy viewers so we don't modify the list we're iterating over when closing inventories.
List<HumanEntity> viewers = new ArrayList<>(inventory.getBukkitInventory().getViewers());
Expand Down Expand Up @@ -248,7 +251,7 @@ private <T extends ISpecialInventory> boolean consumeLoaded(
}

private void save(@NotNull ISpecialInventory inventory) {
if (plugin.disableSaving()) {
if (config.isSaveDisabled()) {
return;
}

Expand Down

0 comments on commit e642616

Please sign in to comment.