2 Commits
5 changed files with 64 additions and 29 deletions

No files matched your search

+2 -2
View File
@@ -4,7 +4,7 @@ plugins {
}
group = 'com.artillexstudios.axsmithing'
version = '1.3'
version = '1.5'
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'
@@ -10,6 +10,7 @@ import com.artillexstudios.axsmithing.utils.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
@@ -90,7 +91,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,14 +203,20 @@ 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) {
Iterator<Recipe> recipeIterator = Bukkit.getServer().recipeIterator();
while (recipeIterator.hasNext()) {
@@ -236,6 +245,12 @@ public class SmithingTable_V1_16 implements SmithingTable, InventoryHolder {
return false;
}
ItemStack it;
if ((it = inventory.getItem(outputSlot)) != null && it.getType() == item.getType()) {
return false;
}
item.setItemMeta(baseItemMeta);
inventory.setItem(outputSlot, item);
return true;
@@ -108,7 +108,9 @@ public class SmithingTable_V1_20 implements SmithingTable, InventoryHolder {
if (!(event.getInventory().getHolder() instanceof SmithingTable_V1_20)) return;
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,33 +250,38 @@ 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) {
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) {
if (finalBase == null || finalAddition == null || finalTemplate == null) return false;
boolean test1 = trimRecipe.getTemplate().test(finalTemplate);
boolean test2 = trimRecipe.getBase().test(finalBase);
boolean test3 = trimRecipe.getAddition().test(finalAddition);
@@ -289,6 +296,11 @@ public class SmithingTable_V1_20 implements SmithingTable, InventoryHolder {
clone.setItemMeta(armorMeta);
}
ItemStack it;
if ((it = inventory.getItem(outputSlot)) != null && it.getType() == clone.getType()) {
return false;
}
inventory.setItem(outputSlot, clone);
return true;
} else {
@@ -319,6 +331,12 @@ public class SmithingTable_V1_20 implements SmithingTable, InventoryHolder {
if (item == null) {
return false;
}
ItemStack it;
if ((it = inventory.getItem(outputSlot)) != null && it.getType() == item.getType()) {
return false;
}
item.setItemMeta(baseItemMeta);
inventory.setItem(outputSlot, item);
return true;
@@ -4,7 +4,6 @@ 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;
@@ -23,6 +22,7 @@ public class InteractListener implements Listener {
if (event.getClickedBlock() == null) return;
if (event.getClickedBlock().getType() != Material.SMITHING_TABLE) return;
if (event.getAction().equals(Action.LEFT_CLICK_BLOCK)) return;
if (!AxSmithingPlugin.getConfiguration().getBoolean("listen-to-interact-event")) 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")) {
+3 -1
View File
@@ -43,9 +43,11 @@ menu:
- 14
material: air
listen-to-interact-event: true
messages:
prefix: "&#AA3428&lAxSmithing &7» "
no-permission: "&cYou do not have permission to do this!"
reload: "&aPlugin reloaded in %time%ms!"
config-version: 1
config-version: 2