Skip to content

Commit abd52fb

Browse files
committed
fix: fix some issues, bump axapi version
1 parent 366e7cd commit abd52fb

File tree

4 files changed

+47
-54
lines changed

4 files changed

+47
-54
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
group = 'com.artillexstudios.axsmithing'
7-
version = '1.3'
7+
version = '1.4'
88

99
repositories {
1010
mavenCentral()
@@ -28,7 +28,7 @@ repositories {
2828

2929
dependencies {
3030
implementation 'net.byteflux:libby-bukkit:1.2.0'
31-
implementation 'com.artillexstudios.axapi:axapi:1.3.9'
31+
implementation 'com.artillexstudios.axapi:axapi:1.4.10'
3232
implementation 'org.bstats:bstats-bukkit:3.0.2'
3333
compileOnly 'com.google.code.gson:gson:2.10.1'
3434
compileOnly 'org.spigotmc:spigot-api:1.20.1-R0.1-SNAPSHOT'

src/main/java/com/artillexstudios/axsmithing/gui/impl/SmithingTable_V1_16.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ public void handleClick(InventoryClickEvent event) {
9090
if (!(event.getInventory().getHolder() instanceof SmithingTable_V1_16)) return;
9191

9292
if ((event.getSlot() == upgradeSlot || event.getSlot() == itemSlot) && event.getInventory().getItem(outputSlot) != null) {
93-
event.getInventory().setItem(outputSlot, null);
93+
if (checkRecipes(event.getInventory(), event.getInventory().getItem(itemSlot), event.getInventory().getItem(upgradeSlot))) {
94+
event.getInventory().setItem(outputSlot, null);
95+
}
9496
}
9597

9698
if (event.getClickedInventory() == event.getView().getTopInventory()) {
@@ -200,15 +202,24 @@ private void updateGui(Inventory inv) {
200202
ItemStack finalAddition = addition;
201203
ItemStack finalBase = base;
202204

203-
boolean successful = checkRecipe(inv, finalBase, finalAddition);
204-
205-
if (!successful) {
206-
checkRecipe(inv, finalAddition, finalBase);
207-
}
205+
checkRecipes(inv, finalBase, finalAddition);
208206
}, 1L);
209207
}
210208

209+
private boolean checkRecipes(Inventory inv, ItemStack finalBase, ItemStack finalAddition) {
210+
boolean successful = checkRecipe(inv, finalBase, finalAddition);
211+
212+
if (!successful) {
213+
checkRecipe(inv, finalAddition, finalBase);
214+
}
215+
216+
return successful;
217+
}
218+
211219
private boolean checkRecipe(Inventory inventory, ItemStack finalBase, ItemStack finalAddition) {
220+
if (inventory.getItem(outputSlot) != null && !inventory.getItem(outputSlot).getType().isAir()) {
221+
return false;
222+
}
212223
Iterator<Recipe> recipeIterator = Bukkit.getServer().recipeIterator();
213224
while (recipeIterator.hasNext()) {
214225
inventory.setItem(outputSlot, new ItemStack(Material.AIR));

src/main/java/com/artillexstudios/axsmithing/gui/impl/SmithingTable_V1_20.java

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ public void handleClick(InventoryClickEvent event) {
109109

110110
if ((event.getSlot() == upgradeSlot || event.getSlot() == itemSlot || event.getSlot() == templateSlot) && event.getInventory().getItem(outputSlot) != null) {
111111
event.getInventory().setItem(outputSlot, null);
112+
if (checkRecipes(event.getInventory(), event.getInventory().getItem(templateSlot), event.getInventory().getItem(itemSlot), event.getInventory().getItem(upgradeSlot))) {
113+
event.getInventory().setItem(outputSlot, null);
114+
}
112115
}
113116

114117
if (event.getClickedInventory() == event.getView().getTopInventory()) {
@@ -248,30 +251,37 @@ private void updateGui(Inventory inv) {
248251
ItemStack finalBase = base;
249252

250253
// Very very very ugly solution, but I guess, it works!
251-
boolean successful = checkRecipe(inv, finalBase, finalAddition, finalTemplate);
252-
if (!successful) {
253-
successful = checkRecipe(inv, finalBase, finalTemplate, finalAddition);
254-
}
255-
if (!successful) {
256-
successful = checkRecipe(inv, finalTemplate, finalBase, finalAddition);
257-
}
258-
if (!successful) {
259-
successful = checkRecipe(inv, finalTemplate, finalAddition, finalBase);
260-
}
261-
if (!successful) {
262-
successful = checkRecipe(inv, finalAddition, finalBase, finalTemplate);
263-
}
264-
if (!successful) {
265-
checkRecipe(inv, finalAddition, finalTemplate, finalBase);
266-
}
267-
254+
checkRecipes(inv, finalTemplate, finalBase, finalAddition);
268255
}, 1L);
269256
}
270257

258+
private boolean checkRecipes(Inventory inv, ItemStack finalTemplate, ItemStack finalBase, ItemStack finalAddition) {
259+
boolean successful = checkRecipe(inv, finalBase, finalAddition, finalTemplate);
260+
if (!successful) {
261+
successful = checkRecipe(inv, finalBase, finalTemplate, finalAddition);
262+
}
263+
if (!successful) {
264+
successful = checkRecipe(inv, finalTemplate, finalBase, finalAddition);
265+
}
266+
if (!successful) {
267+
successful = checkRecipe(inv, finalTemplate, finalAddition, finalBase);
268+
}
269+
if (!successful) {
270+
successful = checkRecipe(inv, finalAddition, finalBase, finalTemplate);
271+
}
272+
if (!successful) {
273+
checkRecipe(inv, finalAddition, finalTemplate, finalBase);
274+
}
275+
276+
return successful;
277+
}
278+
271279
private boolean checkRecipe(Inventory inventory, ItemStack finalTemplate, ItemStack finalBase, ItemStack finalAddition) {
280+
if (inventory.getItem(outputSlot) != null && !inventory.getItem(outputSlot).getType().isAir()) {
281+
return false;
282+
}
272283
Iterator<Recipe> recipeIterator = Bukkit.getServer().recipeIterator();
273284
while (recipeIterator.hasNext()) {
274-
inventory.setItem(outputSlot, new ItemStack(Material.AIR));
275285
Recipe recipe = recipeIterator.next();
276286

277287
if (recipe instanceof SmithingTrimRecipe trimRecipe) {

src/main/java/com/artillexstudios/axsmithing/listener/InteractListener.java

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,15 @@
44
import com.artillexstudios.axapi.utils.Version;
55
import com.artillexstudios.axsmithing.AxSmithingPlugin;
66
import com.viaversion.viaversion.api.Via;
7-
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
8-
import org.bukkit.Material;
97
import org.bukkit.entity.Player;
10-
import org.bukkit.event.Event;
118
import org.bukkit.event.EventHandler;
129
import org.bukkit.event.Listener;
13-
import org.bukkit.event.block.Action;
1410
import org.bukkit.event.inventory.InventoryOpenEvent;
1511
import org.bukkit.event.inventory.InventoryType;
16-
import org.bukkit.event.player.PlayerInteractEvent;
1712
import org.jetbrains.annotations.NotNull;
1813

1914
public class InteractListener implements Listener {
2015

21-
@EventHandler
22-
public void onPlayerInteractEvent(@NotNull final PlayerInteractEvent event) {
23-
if (event.getClickedBlock() == null) return;
24-
if (event.getClickedBlock().getType() != Material.SMITHING_TABLE) return;
25-
if (event.getAction().equals(Action.LEFT_CLICK_BLOCK)) return;
26-
27-
if (AxSmithingPlugin.is1_20()) {
28-
if (Via.getAPI().getPlayerVersion(event.getPlayer()) >= Version.v1_20_1.protocolId && !AxSmithingPlugin.getConfiguration().getBoolean("menu.1_20.force-for-1_20-clients")) {
29-
return;
30-
}
31-
} else {
32-
if (Via.getAPI().getPlayerVersion(event.getPlayer()) != Version.v1_20_1.protocolId && Via.getAPI().getPlayerVersion(event.getPlayer()) != Version.v1_20_2.protocolId) {
33-
return;
34-
}
35-
}
36-
37-
event.setCancelled(true);
38-
event.setUseInteractedBlock(Event.Result.DENY);
39-
event.setUseItemInHand(Event.Result.DENY);
40-
event.getPlayer().closeInventory();
41-
AxSmithingPlugin.getSmithingTableImpl().open(event.getPlayer());
42-
}
43-
4416
@EventHandler
4517
public void onInventoryOpenEvent(@NotNull final InventoryOpenEvent event) {
4618
if (event.getInventory().getType() != InventoryType.SMITHING) return;

0 commit comments

Comments
 (0)