Grade DuneChest outputs through JARVIS at creation
This commit is contained in:
parent
622f7ab6cd
commit
d7bcd912ac
3 changed files with 30 additions and 4 deletions
|
|
@ -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/")
|
||||
|
|
|
|||
|
|
@ -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<BukkitTask> tasks = new ArrayList<>();
|
||||
private final Map<String, List<UUID>> displays = new HashMap<>(); private final Map<String, String> signatures = new HashMap<>();
|
||||
private int counter;
|
||||
private Plugin itemGrader;
|
||||
private Method markCreatedItem;
|
||||
private final Map<UUID, RecipeSession> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff