From abd52fb9ed7bf51c2629921292fb30064b8e60fb Mon Sep 17 00:00:00 2001 From: TomTom <93038247+AverageGithub@users.noreply.github.com> Date: Mon, 25 Dec 2023 10:03:01 +0100 Subject: [PATCH] fix: fix some issues, bump axapi version --- build.gradle | 4 +- .../gui/impl/SmithingTable_V1_16.java | 23 +++++++--- .../gui/impl/SmithingTable_V1_20.java | 46 +++++++++++-------- .../axsmithing/listener/InteractListener.java | 28 ----------- 4 files changed, 47 insertions(+), 54 deletions(-) diff --git a/build.gradle b/build.gradle index ca009aa..bf5bd6c 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group = 'com.artillexstudios.axsmithing' -version = '1.3' +version = '1.4' repositories { mavenCentral() @@ -28,7 +28,7 @@ repositories { dependencies { implementation 'net.byteflux:libby-bukkit:1.2.0' - implementation 'com.artillexstudios.axapi:axapi:1.3.9' + implementation 'com.artillexstudios.axapi:axapi:1.4.10' implementation 'org.bstats:bstats-bukkit:3.0.2' compileOnly 'com.google.code.gson:gson:2.10.1' compileOnly 'org.spigotmc:spigot-api:1.20.1-R0.1-SNAPSHOT' diff --git a/src/main/java/com/artillexstudios/axsmithing/gui/impl/SmithingTable_V1_16.java b/src/main/java/com/artillexstudios/axsmithing/gui/impl/SmithingTable_V1_16.java index 73886a3..8f7b654 100644 --- a/src/main/java/com/artillexstudios/axsmithing/gui/impl/SmithingTable_V1_16.java +++ b/src/main/java/com/artillexstudios/axsmithing/gui/impl/SmithingTable_V1_16.java @@ -90,7 +90,9 @@ public void handleClick(InventoryClickEvent event) { if (!(event.getInventory().getHolder() instanceof SmithingTable_V1_16)) return; if ((event.getSlot() == upgradeSlot || event.getSlot() == itemSlot) && event.getInventory().getItem(outputSlot) != null) { - event.getInventory().setItem(outputSlot, null); + if (checkRecipes(event.getInventory(), event.getInventory().getItem(itemSlot), event.getInventory().getItem(upgradeSlot))) { + event.getInventory().setItem(outputSlot, null); + } } if (event.getClickedInventory() == event.getView().getTopInventory()) { @@ -200,15 +202,24 @@ private void updateGui(Inventory inv) { ItemStack finalAddition = addition; ItemStack finalBase = base; - boolean successful = checkRecipe(inv, finalBase, finalAddition); - - if (!successful) { - checkRecipe(inv, finalAddition, finalBase); - } + checkRecipes(inv, finalBase, finalAddition); }, 1L); } + private boolean checkRecipes(Inventory inv, ItemStack finalBase, ItemStack finalAddition) { + boolean successful = checkRecipe(inv, finalBase, finalAddition); + + if (!successful) { + checkRecipe(inv, finalAddition, finalBase); + } + + return successful; + } + private boolean checkRecipe(Inventory inventory, ItemStack finalBase, ItemStack finalAddition) { + if (inventory.getItem(outputSlot) != null && !inventory.getItem(outputSlot).getType().isAir()) { + return false; + } Iterator recipeIterator = Bukkit.getServer().recipeIterator(); while (recipeIterator.hasNext()) { inventory.setItem(outputSlot, new ItemStack(Material.AIR)); diff --git a/src/main/java/com/artillexstudios/axsmithing/gui/impl/SmithingTable_V1_20.java b/src/main/java/com/artillexstudios/axsmithing/gui/impl/SmithingTable_V1_20.java index 64876b1..eb65203 100644 --- a/src/main/java/com/artillexstudios/axsmithing/gui/impl/SmithingTable_V1_20.java +++ b/src/main/java/com/artillexstudios/axsmithing/gui/impl/SmithingTable_V1_20.java @@ -109,6 +109,9 @@ public void handleClick(InventoryClickEvent event) { if ((event.getSlot() == upgradeSlot || event.getSlot() == itemSlot || event.getSlot() == templateSlot) && event.getInventory().getItem(outputSlot) != null) { event.getInventory().setItem(outputSlot, null); + if (checkRecipes(event.getInventory(), event.getInventory().getItem(templateSlot), event.getInventory().getItem(itemSlot), event.getInventory().getItem(upgradeSlot))) { + event.getInventory().setItem(outputSlot, null); + } } if (event.getClickedInventory() == event.getView().getTopInventory()) { @@ -248,30 +251,37 @@ private void updateGui(Inventory inv) { ItemStack finalBase = base; // Very very very ugly solution, but I guess, it works! - boolean successful = checkRecipe(inv, finalBase, finalAddition, finalTemplate); - if (!successful) { - successful = checkRecipe(inv, finalBase, finalTemplate, finalAddition); - } - if (!successful) { - successful = checkRecipe(inv, finalTemplate, finalBase, finalAddition); - } - if (!successful) { - successful = checkRecipe(inv, finalTemplate, finalAddition, finalBase); - } - if (!successful) { - successful = checkRecipe(inv, finalAddition, finalBase, finalTemplate); - } - if (!successful) { - checkRecipe(inv, finalAddition, finalTemplate, finalBase); - } - + checkRecipes(inv, finalTemplate, finalBase, finalAddition); }, 1L); } + private boolean checkRecipes(Inventory inv, ItemStack finalTemplate, ItemStack finalBase, ItemStack finalAddition) { + boolean successful = checkRecipe(inv, finalBase, finalAddition, finalTemplate); + if (!successful) { + successful = checkRecipe(inv, finalBase, finalTemplate, finalAddition); + } + if (!successful) { + successful = checkRecipe(inv, finalTemplate, finalBase, finalAddition); + } + if (!successful) { + successful = checkRecipe(inv, finalTemplate, finalAddition, finalBase); + } + if (!successful) { + successful = checkRecipe(inv, finalAddition, finalBase, finalTemplate); + } + if (!successful) { + checkRecipe(inv, finalAddition, finalTemplate, finalBase); + } + + return successful; + } + private boolean checkRecipe(Inventory inventory, ItemStack finalTemplate, ItemStack finalBase, ItemStack finalAddition) { + if (inventory.getItem(outputSlot) != null && !inventory.getItem(outputSlot).getType().isAir()) { + return false; + } Iterator recipeIterator = Bukkit.getServer().recipeIterator(); while (recipeIterator.hasNext()) { - inventory.setItem(outputSlot, new ItemStack(Material.AIR)); Recipe recipe = recipeIterator.next(); if (recipe instanceof SmithingTrimRecipe trimRecipe) { diff --git a/src/main/java/com/artillexstudios/axsmithing/listener/InteractListener.java b/src/main/java/com/artillexstudios/axsmithing/listener/InteractListener.java index 9034dfc..11f29bb 100644 --- a/src/main/java/com/artillexstudios/axsmithing/listener/InteractListener.java +++ b/src/main/java/com/artillexstudios/axsmithing/listener/InteractListener.java @@ -4,43 +4,15 @@ import com.artillexstudios.axapi.utils.Version; import com.artillexstudios.axsmithing.AxSmithingPlugin; import com.viaversion.viaversion.api.Via; -import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; -import org.bukkit.Material; import org.bukkit.entity.Player; -import org.bukkit.event.Event; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.block.Action; import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.event.inventory.InventoryType; -import org.bukkit.event.player.PlayerInteractEvent; import org.jetbrains.annotations.NotNull; public class InteractListener implements Listener { - @EventHandler - public void onPlayerInteractEvent(@NotNull final PlayerInteractEvent event) { - if (event.getClickedBlock() == null) return; - if (event.getClickedBlock().getType() != Material.SMITHING_TABLE) return; - if (event.getAction().equals(Action.LEFT_CLICK_BLOCK)) return; - - if (AxSmithingPlugin.is1_20()) { - if (Via.getAPI().getPlayerVersion(event.getPlayer()) >= Version.v1_20_1.protocolId && !AxSmithingPlugin.getConfiguration().getBoolean("menu.1_20.force-for-1_20-clients")) { - return; - } - } else { - if (Via.getAPI().getPlayerVersion(event.getPlayer()) != Version.v1_20_1.protocolId && Via.getAPI().getPlayerVersion(event.getPlayer()) != Version.v1_20_2.protocolId) { - return; - } - } - - event.setCancelled(true); - event.setUseInteractedBlock(Event.Result.DENY); - event.setUseItemInHand(Event.Result.DENY); - event.getPlayer().closeInventory(); - AxSmithingPlugin.getSmithingTableImpl().open(event.getPlayer()); - } - @EventHandler public void onInventoryOpenEvent(@NotNull final InventoryOpenEvent event) { if (event.getInventory().getType() != InventoryType.SMITHING) return;