diff --git a/DuneChest/build.gradle.kts b/DuneChest/build.gradle.kts index 9d7e141c..e4f86494 100644 --- a/DuneChest/build.gradle.kts +++ b/DuneChest/build.gradle.kts @@ -1,6 +1,6 @@ plugins { java } group = "com.example" -version = "1.0.8" +version = "1.0.9" repositories { mavenCentral() maven("https://repo.papermc.io/repository/maven-public/") diff --git a/DuneChest/src/main/java/com/example/dunechest/StorageModule.java b/DuneChest/src/main/java/com/example/dunechest/StorageModule.java index 5358c670..45a6f8fb 100644 --- a/DuneChest/src/main/java/com/example/dunechest/StorageModule.java +++ b/DuneChest/src/main/java/com/example/dunechest/StorageModule.java @@ -1,5 +1,6 @@ package com.example.dunechest; +import java.lang.reflect.Method; import java.util.*; import java.util.function.Predicate; import net.kyori.adventure.text.Component; @@ -38,6 +39,8 @@ public final class StorageModule implements Listener, CommandExecutor { private final List tasks = new ArrayList<>(); private final Map> displays = new HashMap<>(); private final Map signatures = new HashMap<>(); private int counter; + private Plugin itemGrader; + private Method markCreatedItem; private final Map recipeSessions = new HashMap<>(); private record RecipeSession(InventoryView view, Menu menu) {} @@ -64,6 +67,14 @@ public final class StorageModule implements Listener, CommandExecutor { public StorageModule(JavaPlugin plugin) { this.plugin = plugin; this.data = new StorageData(plugin); this.items = new StorageItems(plugin); } public void start() { + itemGrader = Bukkit.getPluginManager().getPlugin("JarvisTranslator"); + if (itemGrader != null && itemGrader.isEnabled()) { + try { + markCreatedItem = itemGrader.getClass().getMethod("markCreatedItem", ItemStack.class); + } catch (NoSuchMethodException unavailable) { + plugin.getLogger().warning("JARVIS item grading API is unavailable."); + } + } data.load(); items.registerRecipes(); Bukkit.getPluginManager().registerEvents(this, plugin); tasks.add(Bukkit.getScheduler().runTaskTimer(plugin, this::tick, 40L, 2L)); @@ -71,7 +82,20 @@ public final class StorageModule implements Listener, CommandExecutor { public void stop() { tasks.forEach(BukkitTask::cancel); displays.values().forEach(l -> l.forEach(this::kill)); displays.clear(); data.save(); } /** For the JARVIS Exchange: build a custom item by id (ender_chest, speed_hopper with tier, auto_crafter). */ - public ItemStack issue(String id, int tier) { return items.create(id, tier); } + public ItemStack issue(String id, int tier) { + ItemStack item = items.create(id, tier); + gradeCreated(item); + return item; + } + + private void gradeCreated(ItemStack item) { + if (markCreatedItem == null || !itemGrader.isEnabled()) return; + try { + markCreatedItem.invoke(itemGrader, item); + } catch (ReflectiveOperationException failure) { + throw new IllegalStateException("JARVIS could not grade the DuneChest output", failure); + } + } // ---------- helpers ---------- private static boolean isDye(Material m) { return m.name().endsWith("_DYE") && dyeIndex(m) >= 0; } @@ -443,6 +467,7 @@ public final class StorageModule implements Listener, CommandExecutor { if (!(r instanceof Keyed expected) || !(actual instanceof Keyed matched) || !expected.getKey().equals(matched.getKey())) return; ItemStack result = actual.getResult().clone(); + gradeCreated(result); Inventory probe = Bukkit.createInventory(null, Math.min(54, Math.max(9, (dst.getSize() + 8) / 9 * 9))); for (int i = 0; i < dst.getSize() && i < probe.getSize(); i++) probe.setItem(i, dst.getItem(i)); if (!probe.addItem(result.clone()).isEmpty()) return; @@ -657,6 +682,7 @@ public final class StorageModule implements Listener, CommandExecutor { case "hopper2" -> items.create(StorageItems.HOPPER, 2); case "hopper3" -> items.create(StorageItems.HOPPER, 3); case "crafter" -> items.create(StorageItems.CRAFTER, 1); case "wrench" -> items.create(StorageItems.WRENCH, 1); case "beacon" -> items.create(StorageItems.BEACON, 1); default -> null; }; if (item == null) { s.sendMessage("Unknown item."); return true; } int n = 1; try { if (a.length > 3) n = Math.max(1, Math.min(64, Integer.parseInt(a[3]))); } catch (NumberFormatException ignored) { } + gradeCreated(item); item.setAmount(n); t.getInventory().addItem(item).values().forEach(r -> t.getWorld().dropItemNaturally(t.getLocation(), r)); s.sendMessage("Gave " + n + " " + a[2] + " to " + t.getName()); return true; } } diff --git a/DuneChest/src/main/resources/plugin.yml b/DuneChest/src/main/resources/plugin.yml index 9e492eff..edec4ce1 100644 --- a/DuneChest/src/main/resources/plugin.yml +++ b/DuneChest/src/main/resources/plugin.yml @@ -1,8 +1,8 @@ name: DuneChest -version: 1.0.8 +version: 1.0.9 main: com.example.dunechest.DuneChest api-version: '1.21.8' -softdepend: [floodgate, DuneMenus, DuneEss] +softdepend: [floodgate, DuneMenus, DuneEss, JarvisTranslator] prefix: DuneChest description: DuneChest - colour-linked Ender Chests, Speed Hoppers and Auto Crafters commands: