Move InventoryView handling to separate modules

This commit is contained in:
Heliosares
2024-07-18 19:31:14 -04:00
parent 841a085f74
commit 95c9b22eb2
4 changed files with 20 additions and 1 deletions

View File

@@ -1,4 +1,10 @@
package dev.heliosares.auxprotect.utils;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory;
public class InventoryUtil_1_20 {
public static Inventory getTopInventory(HumanEntity player) {
return player.getOpenInventory().getTopInventory();
}
}

View File

@@ -1,4 +1,10 @@
package dev.heliosares.auxprotect.utils;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory;
public class InventoryUtil_1_21 {
public static Inventory getTopInventory(HumanEntity player) {
return player.getOpenInventory().getTopInventory();
}
}

View File

@@ -51,6 +51,7 @@
<artifactSet>
<includes>
<include>org.json:json</include>
<include>dev.heliosares:*</include>
</includes>
</artifactSet>
<minimizeJar>true</minimizeJar>

View File

@@ -7,6 +7,8 @@ import dev.heliosares.auxprotect.database.EntryAction;
import dev.heliosares.auxprotect.database.SingleItemEntry;
import dev.heliosares.auxprotect.spigot.AuxProtectSpigot;
import dev.heliosares.auxprotect.utils.InvSerialization;
import dev.heliosares.auxprotect.utils.InventoryUtil_1_20;
import dev.heliosares.auxprotect.utils.InventoryUtil_1_21;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
@@ -86,7 +88,11 @@ public class InventoryListener implements Listener {
InventoryType type;
type = e.getWhoClicked().getOpenInventory().getTopInventory().getType();
if (plugin.getCompatabilityVersion() < 21) {
type = InventoryUtil_1_20.getTopInventory(e.getWhoClicked()).getType();
} else {
type = InventoryUtil_1_21.getTopInventory(e.getWhoClicked()).getType();
}
if (e.getSlotType() != InventoryType.SlotType.RESULT) return;