4 Commits
Author SHA1 Message Date
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
10 changed files with 232 additions and 79 deletions

No files matched your search

+1 -1
View File
@@ -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
View File
@@ -4,7 +4,7 @@ plugins {
}
group = 'com.artillexstudios.axsmithing'
version = '1.2'
version = '1.3'
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.3.9'
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
@@ -159,7 +186,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()) {
@@ -178,7 +205,7 @@ public class SmithingTable_V1_16 implements SmithingTable, InventoryHolder {
if (!successful) {
checkRecipe(inv, finalAddition, finalBase);
}
}, 0L);
}, 1L);
}
private boolean checkRecipe(Inventory inventory, ItemStack finalBase, ItemStack finalAddition) {
@@ -188,17 +215,27 @@ 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;
}
item.setItemMeta(baseItemMeta);
inventory.setItem(outputSlot, item);
return true;
@@ -210,4 +247,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
@@ -188,7 +223,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);
@@ -230,7 +265,7 @@ public class SmithingTable_V1_20 implements SmithingTable, InventoryHolder {
checkRecipe(inv, finalAddition, finalTemplate, finalBase);
}
}, 0L);
}, 1L);
}
private boolean checkRecipe(Inventory inventory, ItemStack finalTemplate, ItemStack finalBase, ItemStack finalAddition) {
@@ -262,18 +297,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 +331,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,9 +1,10 @@
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;
@@ -24,11 +25,11 @@ public class InteractListener implements Listener {
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")) {
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;
}
}
@@ -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()) >= 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;
+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"
}
}
]
+1
View File
@@ -2,6 +2,7 @@ name: "AxSmithing"
main: "com.artillexstudios.axsmithing.AxSmithingPlugin"
version: "$version"
api-version: "1.16"
folia-supported: true
depend:
- ViaVersion