24 Commits
Author SHA1 Message Date
AverageGithub 5d1161bb15 chore: bump version 2026-08-10 12:35:45 +02:00
AverageGithub bfbe454b71 fix: fix an exception on disable, fix the plugin not working with the new versioning 2026-08-10 12:33:49 +02:00
TomTom 97ed8ad6e2 fix: add support for new armor trims 2024-08-11 16:49:20 +02:00
TomTom cbcd7f5855 chore: bump version 2024-08-11 13:26:48 +02:00
TomTom cf4416d562 fix: fix version support to support new 1.20.x versions automatically 2024-08-11 13:26:34 +02:00
TomTom f214bf44b3 chore: bump axapi 2024-05-04 15:26:24 +02:00
TomTom e9d941e872 feat: 1.20.5/6 support 2024-05-01 15:07:39 +02:00
TomTom 532fda45f3 Merge pull request #9 from Pantera07/better/version
Better version handling
2024-05-01 15:02:44 +02:00
Pantera (Mad_Daniel) 2a4dd534a5 Better version handling 2024-04-28 15:32:39 +09:00
TomTom 39d0e36e72 fix: fix folia support 2024-04-06 20:06:09 +02:00
TomTom f5bdb77c0e fix: fix issue with templates v2 2024-02-17 15:17:19 +01:00
TomTom b06b4e7156 fix: fix issue with templates 2024-02-17 15:16:20 +01:00
TomTom 05c131cbff fix: fix issue with template/base 2024-02-17 14:49:46 +01:00
TomTom e3b71c2141 chore: bump version 2024-02-17 14:38:41 +01:00
TomTom 7c52af372f fix: fix issue, update axapi 2024-02-17 14:36:55 +01:00
TomTom 2b51eef478 fix: fix glitch, add config option for listening to interact event 2024-01-01 13:14:27 +01:00
TomTom abd52fb9ed fix: fix some issues, bump axapi version 2023-12-25 10:03:01 +01:00
TomTom 366e7cd32a fix: fix issues on older versions aswell 2023-12-04 19:57:27 +01:00
TomTom 8d2dfe0695 Merge remote-tracking branch 'origin/master' 2023-12-04 19:48:10 +01:00
TomTom b9b440c97b feat: folia support 2023-12-04 19:47:17 +01:00
TomTom d2ff1107de Fix oopsie 2023-11-04 11:50:06 +01:00
TomTom af074e465d Merge remote-tracking branch 'origin/master' 2023-10-29 10:46:56 +01:00
TomTom 5d7674f3b0 Fixed item disappearing when put into output slot 2023-10-29 10:46:21 +01:00
TomTom c987f543bc Add download instructions 2023-10-25 15:45:30 +02:00
18 changed files with 391 additions and 154 deletions

No files matched your search

+1 -1
View File
@@ -5,7 +5,7 @@
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="C:/Gradle/gradle-7.5.1" />
<option name="gradleJvm" value="17" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
+1 -1
View File
@@ -5,7 +5,7 @@
<option name="description" value="" />
</component>
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_16" default="true" project-jdk-name="temurin-16" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
+2
View File
@@ -19,6 +19,8 @@ Commands:
Permissions:
axsmithing.reload
To download: [Click here, and download the latest .jar!](https://github.com/ViaVersionAddons/AxSmithing/releases/)
Need help? Join our Discord!
![discord](https://discordapp.com/api/guilds/1130070418150133761/widget.png?style=banner2)
+16 -11
View File
@@ -1,10 +1,10 @@
plugins {
id 'java'
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'io.github.goooler.shadow' version '8.1.7'
}
group = 'com.artillexstudios.axsmithing'
version = '1.0'
version = '1.10'
repositories {
mavenCentral()
@@ -20,19 +20,19 @@ 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.190:all'
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'
compileOnly 'com.viaversion:viaversion-api:4.7.0'
compileOnly 'com.viaversion:viaversion-api:4.10.0'
}
compileJava {
@@ -40,13 +40,18 @@ compileJava {
options.encoding = "UTF-8"
}
processResources {
filesMatching("plugin.yml") {
expand(version: version)
}
}
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")
minimize()
relocate("com.artillexstudios.axapi", "com.artillexstudios.axsmithing.libs.axapi")
}
build {
dependsOn(shadowJar)
}
}
Binary file not shown.
+3 -2
View File
@@ -1,6 +1,7 @@
#Sat Aug 19 14:47:24 CEST 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Vendored
+22 -8
View File
@@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
@@ -80,13 +80,10 @@ do
esac
done
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
@@ -133,22 +130,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
@@ -193,6 +197,10 @@ if "$cygwin" || "$msys" ; then
done
fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
@@ -205,6 +213,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Vendored
+9 -6
View File
@@ -14,7 +14,7 @@
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@@ -25,7 +25,8 @@
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if %ERRORLEVEL% equ 0 goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
@@ -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.scheduler.Scheduler;
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,12 @@ public class AxSmithingPlugin extends JavaPlugin {
Bukkit.getPluginCommand("axsmithing").setTabCompleter(new AxSmithingTabComplete());
}
public String reload() {
long now = System.currentTimeMillis();
@Override
public void onDisable() {
Scheduler.get().cancelAll();
}
public void reload() {
try {
config.reload();
} catch (IOException e) {
@@ -77,14 +82,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 (!Bukkit.getBukkitVersion().startsWith("1.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,14 +1,16 @@
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;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
@@ -16,10 +18,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 +35,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 +45,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 +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()) {
@@ -116,6 +146,12 @@ public class SmithingTable_V1_16 implements SmithingTable, InventoryHolder {
public void handleDrag(InventoryDragEvent event) {
if (!(event.getInventory().getHolder() instanceof SmithingTable_V1_16)) return;
ItemStack outputItem = event.getInventory().getItem(outputSlot);
if (event.getRawSlots().contains(outputSlot) && (outputItem == null || outputItem.getType().isAir()) && !event.getOldCursor().getType().isAir()) {
event.setCancelled(true);
return;
}
if (event.getInventory().getItem(outputSlot) != null && event.getInventory().getItem(outputSlot).getType() != Material.AIR) {
event.getInventory().getItem(outputSlot).setAmount(0);
}
@@ -153,26 +189,32 @@ 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()) {
addition = new ItemStack(Material.AIR);
}
if (base == null || addition.getType().isAir()) {
if (base == null || base.getType().isAir()) {
base = new ItemStack(Material.AIR);
}
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) {
successful = checkRecipe(inv, finalAddition, finalBase);
}
return successful;
}
private boolean checkRecipe(Inventory inventory, ItemStack finalBase, ItemStack finalAddition) {
@@ -182,17 +224,33 @@ public class SmithingTable_V1_16 implements SmithingTable, InventoryHolder {
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;
}
ItemStack it;
if ((it = inventory.getItem(outputSlot)) != null && it.getType() == item.getType()) {
return false;
}
item.setItemMeta(baseItemMeta);
inventory.setItem(outputSlot, item);
return true;
@@ -204,4 +262,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,13 +1,16 @@
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.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
@@ -16,6 +19,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,9 +31,11 @@ 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;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
@@ -39,6 +46,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 +59,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
@@ -73,7 +111,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()) {
@@ -133,11 +173,11 @@ public class SmithingTable_V1_20 implements SmithingTable, InventoryHolder {
public void handleClose(InventoryCloseEvent event) {
if (!(event.getInventory().getHolder() instanceof SmithingTable_V1_20)) return;
if (event.getInventory().getItem(templateSlot) != null)
if (event.getInventory().getItem(templateSlot) != null && event.getInventory().getItem(templateSlot).getType() != Material.AIR)
event.getPlayer().getInventory().addItem(event.getInventory().getItem(templateSlot));
if (event.getInventory().getItem(itemSlot) != null)
if (event.getInventory().getItem(itemSlot) != null && event.getInventory().getItem(itemSlot).getType() != Material.AIR)
event.getPlayer().getInventory().addItem(event.getInventory().getItem(itemSlot));
if (event.getInventory().getItem(upgradeSlot) != null)
if (event.getInventory().getItem(upgradeSlot) != null && event.getInventory().getItem(upgradeSlot).getType() != Material.AIR)
event.getPlayer().getInventory().addItem(event.getInventory().getItem(upgradeSlot));
}
@@ -145,6 +185,12 @@ public class SmithingTable_V1_20 implements SmithingTable, InventoryHolder {
public void handleDrag(InventoryDragEvent event) {
if (!(event.getInventory().getHolder() instanceof SmithingTable_V1_20)) return;
ItemStack outputItem = event.getInventory().getItem(outputSlot);
if (event.getRawSlots().contains(outputSlot) && (outputItem == null || outputItem.getType().isAir()) && !event.getOldCursor().getType().isAir()) {
event.setCancelled(true);
return;
}
if (event.getInventory().getItem(outputSlot) != null) {
event.getInventory().getItem(outputSlot).setAmount(0);
}
@@ -182,7 +228,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);
@@ -190,15 +236,21 @@ public class SmithingTable_V1_20 implements SmithingTable, InventoryHolder {
addition = new ItemStack(Material.AIR);
}
if (base == null || addition.getType().isAir()) {
if (base == null || base.getType().isAir()) {
base = new ItemStack(Material.AIR);
}
if (template == null || addition.getType().isAir()) {
if (!needNetheriteTemplate) {
if (template == null || template.getType().isAir()) {
template = new ItemStack(Material.AIR);
}
if (!needNetheriteTemplate && !hasTemplate(addition, base, template)) {
if (template.getType().isAir()) {
template = new ItemStack(Material.NETHERITE_UPGRADE_SMITHING_TEMPLATE);
} else {
template = new ItemStack(Material.AIR);
} else if (base.getType().isAir()) {
base = new ItemStack(Material.NETHERITE_UPGRADE_SMITHING_TEMPLATE);
} else if (addition.getType().isAir()) {
addition = new ItemStack(Material.NETHERITE_UPGRADE_SMITHING_TEMPLATE);;
}
}
@@ -207,33 +259,52 @@ 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) {
successful = checkRecipe(inv, finalAddition, finalTemplate, finalBase);
}
return successful;
}
private boolean hasTemplate(ItemStack item1, ItemStack item2, ItemStack item3) {
if (isTemplate(item1)) {
return true;
} else if (isTemplate(item2)) {
return true;
} else {
return isTemplate(item3);
}
}
private boolean isTemplate(ItemStack item) {
return item.getType().name().contains("SMITHING_TEMPLATE");
}
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);
@@ -248,6 +319,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 {
@@ -256,18 +332,34 @@ 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;
}
ItemStack it;
if ((it = inventory.getItem(outputSlot)) != null && it.getType() == item.getType()) {
return false;
}
item.setItemMeta(baseItemMeta);
inventory.setItem(outputSlot, item);
return true;
@@ -280,6 +372,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;
@@ -299,24 +447,7 @@ public class SmithingTable_V1_20 implements SmithingTable, InventoryHolder {
default -> material = null;
}
switch (finalTemplate.getType()) {
case COAST_ARMOR_TRIM_SMITHING_TEMPLATE -> pattern = TrimPattern.COAST;
case DUNE_ARMOR_TRIM_SMITHING_TEMPLATE -> pattern = TrimPattern.DUNE;
case EYE_ARMOR_TRIM_SMITHING_TEMPLATE -> pattern = TrimPattern.EYE;
case SENTRY_ARMOR_TRIM_SMITHING_TEMPLATE -> pattern = TrimPattern.SENTRY;
case HOST_ARMOR_TRIM_SMITHING_TEMPLATE -> pattern = TrimPattern.HOST;
case SHAPER_ARMOR_TRIM_SMITHING_TEMPLATE -> pattern = TrimPattern.SHAPER;
case SILENCE_ARMOR_TRIM_SMITHING_TEMPLATE -> pattern = TrimPattern.SILENCE;
case RAISER_ARMOR_TRIM_SMITHING_TEMPLATE -> pattern = TrimPattern.RAISER;
case RIB_ARMOR_TRIM_SMITHING_TEMPLATE -> pattern = TrimPattern.RIB;
case SNOUT_ARMOR_TRIM_SMITHING_TEMPLATE -> pattern = TrimPattern.SNOUT;
case SPIRE_ARMOR_TRIM_SMITHING_TEMPLATE -> pattern = TrimPattern.SPIRE;
case TIDE_ARMOR_TRIM_SMITHING_TEMPLATE -> pattern = TrimPattern.TIDE;
case VEX_ARMOR_TRIM_SMITHING_TEMPLATE -> pattern = TrimPattern.VEX;
case WARD_ARMOR_TRIM_SMITHING_TEMPLATE -> pattern = TrimPattern.WARD;
case WAYFINDER_ARMOR_TRIM_SMITHING_TEMPLATE -> pattern = TrimPattern.WAYFINDER;
default -> pattern = null;
}
pattern = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft(finalTemplate.getType().name().replace("_ARMOR_TRIM_SMITHING_TEMPLATE", "").toLowerCase(Locale.ENGLISH)));
if (pattern == null || material == null) {
return null;
@@ -1,9 +1,9 @@
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;
@@ -22,13 +22,14 @@ 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()) >= ProtocolVersion.v1_20.getVersion() && !AxSmithingPlugin.getConfiguration().getBoolean("menu.1_20.force-for-1_20-clients")) {
if (Via.getAPI().getPlayerVersion(event.getPlayer()) >= 762 && !AxSmithingPlugin.getConfiguration().getBoolean("menu.1_20.force-for-1_20-clients")) {
return;
}
} else {
if (Via.getAPI().getPlayerVersion(event.getPlayer()) != ProtocolVersion.v1_20.getVersion()) {
if (!AxSmithingPlugin.getConfiguration().getBoolean("menu.1_16.force")) {
return;
}
}
@@ -45,16 +46,18 @@ public class InteractListener implements Listener {
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()) >= 762 && !AxSmithingPlugin.getConfiguration().getBoolean("menu.1_20.force-for-1_20-clients")) {
return;
}
} else {
if (Via.getAPI().getPlayerVersion(event.getPlayer()) != ProtocolVersion.v1_20.getVersion()) {
if (!AxSmithingPlugin.getConfiguration().getBoolean("menu.1_16.force")) {
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;
@@ -9,7 +9,7 @@ import org.jetbrains.annotations.NotNull;
public class StringUtils {
private static final LegacyComponentSerializer LEGACY_COMPONENT_SERIALIZER = LegacyComponentSerializer.builder().character('\u00a7').useUnusualXRepeatedCharacterHexFormat().hexColors().build();
private static final LegacyComponentSerializer LEGACY_FORMATTER = LegacyComponentSerializer.legacyAmpersand().toBuilder().useUnusualXRepeatedCharacterHexFormat().hexColors().build();
private static final LegacyComponentSerializer LEGACY_FORMATTER = LegacyComponentSerializer.builder().character('&').useUnusualXRepeatedCharacterHexFormat().hexColors().build();
private static final MiniMessage MINI_MESSAGE = MiniMessage.miniMessage();
@NotNull
+4 -1
View File
@@ -32,6 +32,7 @@ menu:
upgrade-slot: 12
output-slot: 14
dont-convert-with-modeldata: false
force: false
items:
'1':
slots:
@@ -43,9 +44,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: 3
+5 -32
View File
@@ -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 -1
View File
@@ -1,7 +1,8 @@
name: "AxSmithing"
main: "com.artillexstudios.axsmithing.AxSmithingPlugin"
version: "1.0"
version: "$version"
api-version: "1.16"
folia-supported: true
depend:
- ViaVersion