1 Commits
Author SHA1 Message Date
TomTom abd52fb9ed fix: fix some issues, bump axapi version 2023-12-25 10:03:01 +01:00
4 changed files with 47 additions and 54 deletions

No files matched your search

+2 -2
View File
@@ -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'
@@ -90,7 +90,9 @@ public class SmithingTable_V1_16 implements SmithingTable, InventoryHolder {
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 @@ public class SmithingTable_V1_16 implements SmithingTable, InventoryHolder {
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<Recipe> recipeIterator = Bukkit.getServer().recipeIterator();
while (recipeIterator.hasNext()) {
inventory.setItem(outputSlot, new ItemStack(Material.AIR));
@@ -109,6 +109,9 @@ public class SmithingTable_V1_20 implements SmithingTable, InventoryHolder {
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 @@ public class SmithingTable_V1_20 implements SmithingTable, InventoryHolder {
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<Recipe> recipeIterator = Bukkit.getServer().recipeIterator();
while (recipeIterator.hasNext()) {
inventory.setItem(outputSlot, new ItemStack(Material.AIR));
Recipe recipe = recipeIterator.next();
if (recipe instanceof SmithingTrimRecipe trimRecipe) {
@@ -4,43 +4,15 @@ import com.artillexstudios.axapi.scheduler.Scheduler;
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;