Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
abd52fb9ed | ||
|
|
366e7cd32a | ||
|
|
8d2dfe0695 | ||
|
|
b9b440c97b | ||
|
|
d2ff1107de |
No files matched your search
@@ -19,7 +19,7 @@ Commands:
|
||||
Permissions:
|
||||
axsmithing.reload
|
||||
|
||||
To download: [Click here, and download the latest .jar!](https://github.com/ViaVersionAddons/AxSmithing/releases/tag/release)
|
||||
To download: [Click here, and download the latest .jar!](https://github.com/ViaVersionAddons/AxSmithing/releases/)
|
||||
|
||||
Need help? Join our Discord!
|
||||
|
||||
|
||||
+7
-7
@@ -4,7 +4,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = 'com.artillexstudios.axsmithing'
|
||||
version = '1.2'
|
||||
version = '1.4'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
@@ -20,15 +20,15 @@ repositories {
|
||||
maven {
|
||||
url = uri('https://repo.viaversion.com')
|
||||
}
|
||||
|
||||
maven {
|
||||
url = uri('https://repo.artillex-studios.com/releases')
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'net.byteflux:libby-bukkit:1.2.0'
|
||||
implementation 'dev.dejvokep:boosted-yaml:1.3'
|
||||
implementation 'net.kyori:adventure-text-minimessage:4.14.0'
|
||||
implementation 'net.kyori:adventure-text-serializer-legacy:4.14.0'
|
||||
implementation 'net.kyori:adventure-platform-bukkit:4.3.0'
|
||||
implementation 'net.kyori:adventure-api:4.14.0'
|
||||
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'
|
||||
@@ -48,8 +48,8 @@ processResources {
|
||||
|
||||
shadowJar {
|
||||
relocate("net.byteflux.libby", "com.artillexstudios.axsmithing.libs.libby")
|
||||
relocate("net.kyori", "com.artillexstudios.axsmithing.libs.kyori")
|
||||
relocate("org.bstats", "com.artillexstudios.axsmithing.libs.bstats")
|
||||
relocate("com.artillexstudios.axapi", "com.artillexstudios.axsmithing.libs.axapi")
|
||||
minimize()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
package com.artillexstudios.axsmithing;
|
||||
|
||||
import com.artillexstudios.axapi.AxPlugin;
|
||||
import com.artillexstudios.axapi.libs.boostedyaml.boostedyaml.YamlDocument;
|
||||
import com.artillexstudios.axapi.libs.boostedyaml.boostedyaml.dvs.versioning.BasicVersioning;
|
||||
import com.artillexstudios.axapi.libs.boostedyaml.boostedyaml.settings.dumper.DumperSettings;
|
||||
import com.artillexstudios.axapi.libs.boostedyaml.boostedyaml.settings.general.GeneralSettings;
|
||||
import com.artillexstudios.axapi.libs.boostedyaml.boostedyaml.settings.loader.LoaderSettings;
|
||||
import com.artillexstudios.axapi.libs.boostedyaml.boostedyaml.settings.updater.UpdaterSettings;
|
||||
import com.artillexstudios.axapi.utils.Version;
|
||||
import com.artillexstudios.axsmithing.command.AxSmithingCommand;
|
||||
import com.artillexstudios.axsmithing.command.AxSmithingTabComplete;
|
||||
import com.artillexstudios.axsmithing.gui.SmithingTable;
|
||||
@@ -7,21 +15,14 @@ import com.artillexstudios.axsmithing.gui.impl.SmithingTable_V1_16;
|
||||
import com.artillexstudios.axsmithing.gui.impl.SmithingTable_V1_20;
|
||||
import com.artillexstudios.axsmithing.listener.InteractListener;
|
||||
import com.artillexstudios.axsmithing.listener.InventoryListener;
|
||||
import dev.dejvokep.boostedyaml.YamlDocument;
|
||||
import dev.dejvokep.boostedyaml.dvs.versioning.BasicVersioning;
|
||||
import dev.dejvokep.boostedyaml.settings.dumper.DumperSettings;
|
||||
import dev.dejvokep.boostedyaml.settings.general.GeneralSettings;
|
||||
import dev.dejvokep.boostedyaml.settings.loader.LoaderSettings;
|
||||
import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class AxSmithingPlugin extends JavaPlugin {
|
||||
public class AxSmithingPlugin extends AxPlugin {
|
||||
private static YamlDocument config;
|
||||
private static SmithingTable smithingTableImpl;
|
||||
private static AxSmithingPlugin instance;
|
||||
@@ -52,7 +53,7 @@ public class AxSmithingPlugin extends JavaPlugin {
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
public void enable() {
|
||||
instance = this;
|
||||
new Metrics(this, 19575);
|
||||
try {
|
||||
@@ -68,8 +69,7 @@ public class AxSmithingPlugin extends JavaPlugin {
|
||||
Bukkit.getPluginCommand("axsmithing").setTabCompleter(new AxSmithingTabComplete());
|
||||
}
|
||||
|
||||
public String reload() {
|
||||
long now = System.currentTimeMillis();
|
||||
public void reload() {
|
||||
try {
|
||||
config.reload();
|
||||
} catch (IOException e) {
|
||||
@@ -77,14 +77,10 @@ public class AxSmithingPlugin extends JavaPlugin {
|
||||
}
|
||||
|
||||
initializeSmithingTableImpl();
|
||||
long took = System.currentTimeMillis() - now;
|
||||
return String.valueOf(took);
|
||||
}
|
||||
|
||||
private void initializeSmithingTableImpl() {
|
||||
String version = Bukkit.getVersion();
|
||||
|
||||
if (version.contains("20")) {
|
||||
if (Version.getServerVersion().isNewerThanOrEqualTo(Version.v1_20_1)) {
|
||||
v1_20 = true;
|
||||
smithingTableImpl = new SmithingTable_V1_20();
|
||||
} else {
|
||||
|
||||
@@ -16,7 +16,7 @@ public class AxSmithingCommand implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
String took = AxSmithingPlugin.getInstance().reload();
|
||||
String took = String.valueOf(AxSmithingPlugin.getInstance().reloadWithTime());
|
||||
sender.sendMessage(StringUtils.format(AxSmithingPlugin.getConfiguration().getString("messages.prefix") + AxSmithingPlugin.getConfiguration().getString("messages.reload").replace("%time%", took)));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package com.artillexstudios.axsmithing.gui.impl;
|
||||
|
||||
import com.artillexstudios.axapi.libs.boostedyaml.boostedyaml.YamlDocument;
|
||||
import com.artillexstudios.axapi.libs.boostedyaml.boostedyaml.block.implementation.Section;
|
||||
import com.artillexstudios.axapi.scheduler.Scheduler;
|
||||
import com.artillexstudios.axsmithing.AxSmithingPlugin;
|
||||
import com.artillexstudios.axsmithing.gui.SmithingTable;
|
||||
import com.artillexstudios.axsmithing.utils.ItemBuilder;
|
||||
import com.artillexstudios.axsmithing.utils.StringUtils;
|
||||
import dev.dejvokep.boostedyaml.YamlDocument;
|
||||
import dev.dejvokep.boostedyaml.block.implementation.Section;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -16,10 +17,12 @@ import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
import org.bukkit.inventory.RecipeChoice;
|
||||
import org.bukkit.inventory.SmithingRecipe;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -31,6 +34,9 @@ public class SmithingTable_V1_16 implements SmithingTable, InventoryHolder {
|
||||
private final int upgradeSlot;
|
||||
private final int itemSlot;
|
||||
private final boolean dontConvertWithModelData;
|
||||
private final Field baseField;
|
||||
private final Field additionField;
|
||||
private final Field resultField;
|
||||
|
||||
public SmithingTable_V1_16() {
|
||||
YamlDocument config = AxSmithingPlugin.getConfiguration();
|
||||
@@ -38,6 +44,27 @@ public class SmithingTable_V1_16 implements SmithingTable, InventoryHolder {
|
||||
upgradeSlot = config.getInt("menu.1_16.upgrade-slot");
|
||||
itemSlot = config.getInt("menu.1_16.item-slot");
|
||||
dontConvertWithModelData = config.getBoolean("menu.1_16.dont-convert-with-modeldata");
|
||||
|
||||
try {
|
||||
baseField = SmithingRecipe.class.getDeclaredField("base");
|
||||
baseField.setAccessible(true);
|
||||
} catch (NoSuchFieldException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try {
|
||||
additionField = SmithingRecipe.class.getDeclaredField("addition");
|
||||
additionField.setAccessible(true);
|
||||
} catch (NoSuchFieldException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try {
|
||||
resultField = SmithingRecipe.class.getDeclaredField("result");
|
||||
resultField.setAccessible(true);
|
||||
} catch (NoSuchFieldException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -63,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()) {
|
||||
@@ -159,7 +188,7 @@ public class SmithingTable_V1_16 implements SmithingTable, InventoryHolder {
|
||||
}
|
||||
|
||||
private void updateGui(Inventory inv) {
|
||||
Bukkit.getScheduler().runTaskLater(AxSmithingPlugin.getInstance(), t -> {
|
||||
Scheduler.get().runLater(t -> {
|
||||
ItemStack base = inv.getItem(itemSlot);
|
||||
ItemStack addition = inv.getItem(upgradeSlot);
|
||||
if (addition == null || addition.getType().isAir()) {
|
||||
@@ -173,32 +202,51 @@ public class SmithingTable_V1_16 implements SmithingTable, InventoryHolder {
|
||||
ItemStack finalAddition = addition;
|
||||
ItemStack finalBase = base;
|
||||
|
||||
boolean successful = checkRecipe(inv, finalBase, finalAddition);
|
||||
checkRecipes(inv, finalBase, finalAddition);
|
||||
}, 1L);
|
||||
}
|
||||
|
||||
if (!successful) {
|
||||
checkRecipe(inv, finalAddition, finalBase);
|
||||
}
|
||||
}, 0L);
|
||||
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));
|
||||
Recipe recipe = recipeIterator.next();
|
||||
|
||||
if (recipe instanceof SmithingRecipe smithingRecipe) {
|
||||
boolean test1 = smithingRecipe.getBase().test(finalBase);
|
||||
RecipeChoice base = getBase(smithingRecipe);
|
||||
RecipeChoice addition = getAddition(smithingRecipe);
|
||||
if (base == null || addition == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean test1 = base.test(finalBase);
|
||||
ItemMeta baseItemMeta = finalBase.getItemMeta();
|
||||
if (baseItemMeta == null) return false;
|
||||
boolean test2 = smithingRecipe.getAddition().test(finalAddition);
|
||||
boolean test2 = addition.test(finalAddition);
|
||||
|
||||
if (dontConvertWithModelData && baseItemMeta.hasCustomModelData()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (test1 && test2) {
|
||||
ItemStack item = smithingRecipe.getResult();
|
||||
ItemStack item = getResult(smithingRecipe);
|
||||
if (item == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
item.setItemMeta(baseItemMeta);
|
||||
inventory.setItem(outputSlot, item);
|
||||
return true;
|
||||
@@ -210,4 +258,46 @@ public class SmithingTable_V1_16 implements SmithingTable, InventoryHolder {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public RecipeChoice getBase(SmithingRecipe recipe) {
|
||||
RecipeChoice recipeChoice;
|
||||
try {
|
||||
recipeChoice = (RecipeChoice) baseField.get(recipe);
|
||||
if (recipeChoice == null) {
|
||||
return null;
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return recipeChoice.clone();
|
||||
}
|
||||
|
||||
public RecipeChoice getAddition(SmithingRecipe recipe) {
|
||||
RecipeChoice recipeChoice;
|
||||
try {
|
||||
recipeChoice = (RecipeChoice) additionField.get(recipe);
|
||||
if (recipeChoice == null) {
|
||||
return null;
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return recipeChoice.clone();
|
||||
}
|
||||
|
||||
public ItemStack getResult(SmithingRecipe recipe) {
|
||||
ItemStack result;
|
||||
try {
|
||||
result = (ItemStack) resultField.get(recipe);
|
||||
if (result == null) {
|
||||
return null;
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return result.clone();
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
package com.artillexstudios.axsmithing.gui.impl;
|
||||
|
||||
import com.artillexstudios.axapi.libs.boostedyaml.boostedyaml.YamlDocument;
|
||||
import com.artillexstudios.axapi.libs.boostedyaml.boostedyaml.block.implementation.Section;
|
||||
import com.artillexstudios.axapi.scheduler.Scheduler;
|
||||
import com.artillexstudios.axsmithing.AxSmithingPlugin;
|
||||
import com.artillexstudios.axsmithing.gui.SmithingTable;
|
||||
import com.artillexstudios.axsmithing.utils.ItemBuilder;
|
||||
import com.artillexstudios.axsmithing.utils.StringUtils;
|
||||
import dev.dejvokep.boostedyaml.YamlDocument;
|
||||
import dev.dejvokep.boostedyaml.block.implementation.Section;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -16,6 +17,8 @@ import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
import org.bukkit.inventory.RecipeChoice;
|
||||
import org.bukkit.inventory.SmithingRecipe;
|
||||
import org.bukkit.inventory.SmithingTransformRecipe;
|
||||
import org.bukkit.inventory.SmithingTrimRecipe;
|
||||
import org.bukkit.inventory.meta.ArmorMeta;
|
||||
@@ -26,6 +29,7 @@ import org.bukkit.inventory.meta.trim.TrimPattern;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -39,6 +43,10 @@ public class SmithingTable_V1_20 implements SmithingTable, InventoryHolder {
|
||||
private final int templateSlot;
|
||||
private final boolean needNetheriteTemplate;
|
||||
private final boolean dontConvertWithModelData;
|
||||
private final Field templateField;
|
||||
private final Field baseField;
|
||||
private final Field additionField;
|
||||
private final Field resultField;
|
||||
|
||||
public SmithingTable_V1_20() {
|
||||
YamlDocument config = AxSmithingPlugin.getConfiguration();
|
||||
@@ -48,6 +56,33 @@ public class SmithingTable_V1_20 implements SmithingTable, InventoryHolder {
|
||||
itemSlot = config.getInt("menu.1_20.item-slot");
|
||||
needNetheriteTemplate = config.getBoolean("menu.1_20.need-netherite-template");
|
||||
dontConvertWithModelData = config.getBoolean("menu.1_20.dont-convert-with-modeldata");
|
||||
try {
|
||||
templateField = SmithingTransformRecipe.class.getDeclaredField("template");
|
||||
templateField.setAccessible(true);
|
||||
} catch (NoSuchFieldException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try {
|
||||
baseField = SmithingRecipe.class.getDeclaredField("base");
|
||||
baseField.setAccessible(true);
|
||||
} catch (NoSuchFieldException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try {
|
||||
additionField = SmithingRecipe.class.getDeclaredField("addition");
|
||||
additionField.setAccessible(true);
|
||||
} catch (NoSuchFieldException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
try {
|
||||
resultField = SmithingRecipe.class.getDeclaredField("result");
|
||||
resultField.setAccessible(true);
|
||||
} catch (NoSuchFieldException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -74,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()) {
|
||||
@@ -188,7 +226,7 @@ public class SmithingTable_V1_20 implements SmithingTable, InventoryHolder {
|
||||
}
|
||||
|
||||
private void updateGui(Inventory inv) {
|
||||
Bukkit.getScheduler().runTaskLater(AxSmithingPlugin.getInstance(), t -> {
|
||||
Scheduler.get().runLater(t -> {
|
||||
ItemStack template = inv.getItem(templateSlot);
|
||||
ItemStack base = inv.getItem(itemSlot);
|
||||
ItemStack addition = inv.getItem(upgradeSlot);
|
||||
@@ -213,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);
|
||||
}
|
||||
|
||||
}, 0L);
|
||||
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) {
|
||||
@@ -262,18 +307,28 @@ public class SmithingTable_V1_20 implements SmithingTable, InventoryHolder {
|
||||
}
|
||||
|
||||
if (recipe instanceof SmithingTransformRecipe transformRecipe) {
|
||||
boolean test1 = transformRecipe.getTemplate().test(finalTemplate);
|
||||
boolean test2 = transformRecipe.getBase().test(finalBase);
|
||||
RecipeChoice template = getTemplate(transformRecipe);
|
||||
RecipeChoice base = getBase(transformRecipe);
|
||||
RecipeChoice addition = getAddition(transformRecipe);
|
||||
if (template == null || base == null || addition == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean test1 = template.test(finalTemplate);
|
||||
boolean test2 = base.test(finalBase);
|
||||
ItemMeta baseItemMeta = finalBase.getItemMeta();
|
||||
if (baseItemMeta == null) return false;
|
||||
boolean test3 = transformRecipe.getAddition().test(finalAddition);
|
||||
boolean test3 = addition.test(finalAddition);
|
||||
|
||||
if (dontConvertWithModelData && baseItemMeta.hasCustomModelData()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (test1 && test2 && test3) {
|
||||
ItemStack item = transformRecipe.getResult();
|
||||
ItemStack item = getResult(transformRecipe);
|
||||
if (item == null) {
|
||||
return false;
|
||||
}
|
||||
item.setItemMeta(baseItemMeta);
|
||||
inventory.setItem(outputSlot, item);
|
||||
return true;
|
||||
@@ -286,6 +341,62 @@ public class SmithingTable_V1_20 implements SmithingTable, InventoryHolder {
|
||||
return false;
|
||||
}
|
||||
|
||||
public RecipeChoice getTemplate(SmithingTransformRecipe recipe) {
|
||||
RecipeChoice recipeChoice;
|
||||
try {
|
||||
recipeChoice = (RecipeChoice) templateField.get(recipe);
|
||||
if (recipeChoice == null) {
|
||||
return null;
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return recipeChoice.clone();
|
||||
}
|
||||
|
||||
public RecipeChoice getBase(SmithingTransformRecipe recipe) {
|
||||
RecipeChoice recipeChoice;
|
||||
try {
|
||||
recipeChoice = (RecipeChoice) baseField.get(recipe);
|
||||
if (recipeChoice == null) {
|
||||
return null;
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return recipeChoice.clone();
|
||||
}
|
||||
|
||||
public RecipeChoice getAddition(SmithingTransformRecipe recipe) {
|
||||
RecipeChoice recipeChoice;
|
||||
try {
|
||||
recipeChoice = (RecipeChoice) additionField.get(recipe);
|
||||
if (recipeChoice == null) {
|
||||
return null;
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return recipeChoice.clone();
|
||||
}
|
||||
|
||||
public ItemStack getResult(SmithingTransformRecipe recipe) {
|
||||
ItemStack result;
|
||||
try {
|
||||
result = (ItemStack) resultField.get(recipe);
|
||||
if (result == null) {
|
||||
return null;
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return result.clone();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private ArmorTrim armorTrim(@NotNull ItemStack finalAddition, @NotNull ItemStack finalTemplate) {
|
||||
TrimMaterial material;
|
||||
|
||||
@@ -1,60 +1,35 @@
|
||||
package com.artillexstudios.axsmithing.listener;
|
||||
|
||||
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.Bukkit;
|
||||
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()) >= ProtocolVersion.v1_20.getVersion() && !AxSmithingPlugin.getConfiguration().getBoolean("menu.1_20.force-for-1_20-clients")) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (Via.getAPI().getPlayerVersion(event.getPlayer()) != ProtocolVersion.v1_20.getVersion()) {
|
||||
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;
|
||||
|
||||
if (AxSmithingPlugin.is1_20()) {
|
||||
if (Via.getAPI().getPlayerVersion(event.getPlayer()) >= ProtocolVersion.v1_20.getVersion() && !AxSmithingPlugin.getConfiguration().getBoolean("menu.1_20.force-for-1_20-clients")) {
|
||||
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()) != ProtocolVersion.v1_20.getVersion()) {
|
||||
if (Via.getAPI().getPlayerVersion(event.getPlayer()) != Version.v1_20_1.protocolId && Via.getAPI().getPlayerVersion(event.getPlayer()) != Version.v1_20_2.protocolId) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
event.getPlayer().closeInventory();
|
||||
Bukkit.getScheduler().runTaskLater(AxSmithingPlugin.getInstance(), () -> AxSmithingPlugin.getSmithingTableImpl().open((Player) event.getPlayer()),1L);
|
||||
Scheduler.get().runLater(t -> {
|
||||
AxSmithingPlugin.getSmithingTableImpl().open((Player) event.getPlayer());
|
||||
}, 1);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.artillexstudios.axsmithing.utils;
|
||||
|
||||
import dev.dejvokep.boostedyaml.block.implementation.Section;
|
||||
import com.artillexstudios.axapi.libs.boostedyaml.boostedyaml.block.implementation.Section;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
|
||||
@@ -1,39 +1,12 @@
|
||||
{
|
||||
"dependencies": [
|
||||
{
|
||||
"group": "net.kyori",
|
||||
"artifact": "adventure-text-minimessage",
|
||||
"version": "4.14.0",
|
||||
"group": "org.bstats",
|
||||
"artifact": "bstats-bukkit",
|
||||
"version": "3.0.2",
|
||||
"relocate": {
|
||||
"from": "net.kyori",
|
||||
"to": "com.artillexstudios.axsmithing.libs.adventure"
|
||||
}
|
||||
},
|
||||
{
|
||||
"group": "net.kyori",
|
||||
"artifact": "adventure-text-serializer-legacy",
|
||||
"version": "4.14.0",
|
||||
"relocate": {
|
||||
"from": "net.kyori",
|
||||
"to": "com.artillexstudios.axsmithing.libs.adventure"
|
||||
}
|
||||
},
|
||||
{
|
||||
"group": "net.kyori",
|
||||
"artifact": "adventure-platform-bukkit",
|
||||
"version": "4.3.0",
|
||||
"relocate": {
|
||||
"from": "net.kyori",
|
||||
"to": "com.artillexstudios.axsmithing.libs.adventure"
|
||||
}
|
||||
},
|
||||
{
|
||||
"group": "net.kyori",
|
||||
"artifact": "adventure-api",
|
||||
"version": "4.14.0",
|
||||
"relocate": {
|
||||
"from": "net.kyori",
|
||||
"to": "com.artillexstudios.axsmithing.libs.adventure"
|
||||
"from": "org.bstats",
|
||||
"to": "com.artillexstudios.axsmithing.libs.bstats"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
@@ -2,6 +2,7 @@ name: "AxSmithing"
|
||||
main: "com.artillexstudios.axsmithing.AxSmithingPlugin"
|
||||
version: "$version"
|
||||
api-version: "1.16"
|
||||
folia-supported: true
|
||||
depend:
|
||||
- ViaVersion
|
||||
|
||||
|
||||
Reference in new issue
Block a user