diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..71cb6b9 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,36 @@ +# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: build + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + cache: maven + - name: Build with Maven + run: mvn -B package --file pom.xml + + - name: Upload a Build Artifact + uses: actions/upload-artifact@v4.6.0 + with: + path: target/*.jar diff --git a/src/main/java/com/artillexstudios/axshulkers/listeners/impl/PlayerDropItemListener.java b/src/main/java/com/artillexstudios/axshulkers/listeners/impl/PlayerDropItemListener.java index 1c27441..d9f21f3 100644 --- a/src/main/java/com/artillexstudios/axshulkers/listeners/impl/PlayerDropItemListener.java +++ b/src/main/java/com/artillexstudios/axshulkers/listeners/impl/PlayerDropItemListener.java @@ -14,7 +14,7 @@ public class PlayerDropItemListener implements Listener { @EventHandler (ignoreCancelled = true) public void onDrop(@NotNull PlayerDropItemEvent event) { ItemStack it = event.getItemDrop().getItemStack(); - if (!ShulkerUtils.isShulker(it)) return; + if (!ShulkerUtils.isShulker(it) || ShulkerUtils.getShulkerUUID(it) == null) return; String name = ShulkerUtils.getShulkerName(it); Shulkerbox shulkerbox = Shulkerboxes.getShulker(it, name); diff --git a/src/main/java/com/artillexstudios/axshulkers/listeners/impl/PlayerInteractListener.java b/src/main/java/com/artillexstudios/axshulkers/listeners/impl/PlayerInteractListener.java index cba6afc..3ddadef 100644 --- a/src/main/java/com/artillexstudios/axshulkers/listeners/impl/PlayerInteractListener.java +++ b/src/main/java/com/artillexstudios/axshulkers/listeners/impl/PlayerInteractListener.java @@ -11,14 +11,6 @@ public class PlayerInteractListener implements Listener { - @EventHandler (ignoreCancelled = true) - public void onInteract(@NotNull PlayerInteractEvent event) { - if (event.getAction() == Action.PHYSICAL) return; - Shulkerbox shulkerbox; - if ((shulkerbox = ShulkerUtils.hasShulkerOpen(event.getPlayer())) == null) return; - shulkerbox.close(); - } - @EventHandler (ignoreCancelled = true) public void onInteractEntity(@NotNull PlayerInteractEntityEvent event) { Shulkerbox shulkerbox; diff --git a/src/main/java/com/artillexstudios/axshulkers/listeners/impl/ShulkerOpenListener.java b/src/main/java/com/artillexstudios/axshulkers/listeners/impl/ShulkerOpenListener.java index 707df0d..7c64864 100644 --- a/src/main/java/com/artillexstudios/axshulkers/listeners/impl/ShulkerOpenListener.java +++ b/src/main/java/com/artillexstudios/axshulkers/listeners/impl/ShulkerOpenListener.java @@ -36,10 +36,14 @@ public void onInteract(@NotNull PlayerInteractEvent event) { event.getPlayer().closeInventory(); } - if (event.getAction() != Action.RIGHT_CLICK_AIR) return; + if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK) return; final Player player = event.getPlayer(); - if (openShulker(player, player.getInventory().getItemInMainHand())) event.setCancelled(true); + + ItemStack potentialShulker = ShulkerUtils.getHeldShulker(player.getInventory()); + if (ShulkerUtils.isShulker(potentialShulker)) + if (openShulker(player, potentialShulker)) + event.setCancelled(true); } @EventHandler (priority = EventPriority.LOW) diff --git a/src/main/java/com/artillexstudios/axshulkers/utils/ShulkerUtils.java b/src/main/java/com/artillexstudios/axshulkers/utils/ShulkerUtils.java index 17484b9..7ad5cb0 100644 --- a/src/main/java/com/artillexstudios/axshulkers/utils/ShulkerUtils.java +++ b/src/main/java/com/artillexstudios/axshulkers/utils/ShulkerUtils.java @@ -10,6 +10,7 @@ import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.meta.BlockStateMeta; import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; @@ -69,6 +70,17 @@ public static boolean isShulker(@Nullable ItemStack it) { return shulkers.contains(it.getType()); } + //returns shulker in main hand, if not found returns shulker in off hand + @Nullable + public static ItemStack getHeldShulker(PlayerInventory playerInventory) { + if (isShulker(playerInventory.getItemInMainHand())) + return playerInventory.getItemInMainHand(); + else if (isShulker(playerInventory.getItemInOffHand())) + return playerInventory.getItemInOffHand(); + + return null; + } + public static boolean isAllowedInventoryType(@NotNull Inventory inventory) { return inventories.contains(inventory.getType()); } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index b335be7..d5efa41 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -6,7 +6,7 @@ prefix: "&#CC00FF&lAxShulkers &7ยป " -# EXPERIEMENTAL (this option was well tested, however it is still less safe than the default system) +# EXPERIMENTAL (this option was well tested, however it is still less safe than the default system) # this setting will remove the safety UUID from the shulkers after they are closed # it relies on java WeakReference-s to protect you from dupes # this also force disables 'enable-obfuscation' @@ -27,7 +27,7 @@ enable-obfuscation: false # note: this is not required for security, you can leave it on 0 to disable open-cooldown-milliseconds: 0 -# should the shulker open when it gets right clicked in the player's inventory? +# should the shulker open when it gets right-clicked in the player's inventory? opening-from-inventory: enabled: true # should this also be possible in the player's ender chest?