feat(ignis): add earned Dagger crafting and safe blinking
This commit is contained in:
1 parent
183b6660b2
commit
17b61d7b43
29 files changed
+1402
-62
No files matched your search
@@ -0,0 +1,18 @@
|
||||
package games.dmg.spigotignis;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.function.LongSupplier;
|
||||
|
||||
/** Server-thread, per-player activation gate, independent of item copies and teleport outcome. */
|
||||
public final class DaggerCooldown {
|
||||
private final LongSupplier clock;
|
||||
private final java.util.Map<UUID, Long> started = new java.util.HashMap<>();
|
||||
public DaggerCooldown(LongSupplier clock) { this.clock = clock; }
|
||||
public boolean attempt(UUID player) {
|
||||
long now = clock.getAsLong();
|
||||
started.entrySet().removeIf(entry -> now - entry.getValue() >= 2_000_000_000L);
|
||||
if (started.containsKey(player)) return false;
|
||||
started.put(player, now);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package games.dmg.spigotignis;
|
||||
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.CraftItemEvent;
|
||||
import org.bukkit.event.block.CrafterCraftEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class DaggerCrafting implements Listener, Runnable {
|
||||
public static final NamespacedKey RECIPE = new NamespacedKey("spigotignis", "dagger");
|
||||
private static final TradableRewards REWARDS = new TradableRewards(Track.DAGGER);
|
||||
private final JavaPlugin plugin;
|
||||
private final StateService states;
|
||||
private final DaggerItems items;
|
||||
private final EchoGameplay dispatch;
|
||||
private final java.util.function.Function<org.bukkit.inventory.ItemStack, org.bukkit.inventory.ShapedRecipe> recipeFactory;
|
||||
public DaggerCrafting(JavaPlugin plugin, StateService states, DaggerItems items, EchoGameplay dispatch) {
|
||||
this(plugin, states, items, dispatch, result -> new org.bukkit.inventory.ShapedRecipe(RECIPE, result));
|
||||
}
|
||||
DaggerCrafting(JavaPlugin plugin, StateService states, DaggerItems items, EchoGameplay dispatch,
|
||||
java.util.function.Function<org.bukkit.inventory.ItemStack, org.bukkit.inventory.ShapedRecipe> recipeFactory) {
|
||||
this.plugin = plugin; this.states = states; this.items = items; this.dispatch = dispatch;
|
||||
this.recipeFactory = recipeFactory;
|
||||
}
|
||||
private boolean registered;
|
||||
private final java.util.Set<java.util.UUID> preparing = new java.util.HashSet<>();
|
||||
private final java.util.Set<ItemToken> delivering = new java.util.HashSet<>();
|
||||
private final java.util.Set<ItemToken> offered = new java.util.HashSet<>();
|
||||
@Override public void run() {
|
||||
if (!registered) {
|
||||
var recipe = recipeFactory.apply(items.prototype());
|
||||
configureRecipe(recipe);
|
||||
registered = plugin.getServer().addRecipe(recipe);
|
||||
if (!registered) return;
|
||||
}
|
||||
for (var player : plugin.getServer().getOnlinePlayers()) {
|
||||
var state = states.snapshot().players().getOrDefault(player.getUniqueId(), PlayerState.empty());
|
||||
if (!state.track(Track.DAGGER).unlocked()) {
|
||||
if (player.hasDiscoveredRecipe(RECIPE)) player.undiscoverRecipe(RECIPE);
|
||||
continue;
|
||||
}
|
||||
ensureReceipt(player);
|
||||
if (!player.hasDiscoveredRecipe(RECIPE)) player.discoverRecipe(RECIPE);
|
||||
for (var entry : state.pendingRewards().entrySet()) {
|
||||
if (entry.getValue() != Track.DAGGER) continue;
|
||||
var token = new ItemToken(player.getUniqueId(), entry.getKey(), state.track(Track.DAGGER).generation());
|
||||
if (delivering.contains(token)) continue;
|
||||
if (!offered.contains(token) && !items.offer(player, token)) continue;
|
||||
offered.add(token);
|
||||
delivering.add(token);
|
||||
states.update(current -> REWARDS.acknowledge(current, token))
|
||||
.whenComplete((ignored, error) -> dispatch.onServer(() -> {
|
||||
delivering.remove(token);
|
||||
if (error == null) offered.remove(token);
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
private void ensureReceipt(org.bukkit.entity.Player player) {
|
||||
var owner = player.getUniqueId();
|
||||
var snapshot = states.snapshot();
|
||||
var state = snapshot.players().getOrDefault(owner, PlayerState.empty()).track(Track.DAGGER);
|
||||
if (!state.unlocked() || REWARDS.craftingToken(snapshot, owner).isPresent() || !preparing.add(owner)) return;
|
||||
var receipt = java.util.UUID.randomUUID();
|
||||
long generation = state.generation();
|
||||
states.update(current -> {
|
||||
var now = current.players().getOrDefault(owner, PlayerState.empty()).track(Track.DAGGER);
|
||||
return now.unlocked() && now.generation() == generation ? REWARDS.issue(current, owner, receipt, false) : current;
|
||||
}).whenComplete((ignored, error) -> dispatch.onServer(() -> {
|
||||
preparing.remove(owner);
|
||||
var online = plugin.getServer().getPlayer(owner);
|
||||
if (error != null || online == null) return;
|
||||
var view = online.getOpenInventory();
|
||||
if (view.getTopInventory() instanceof org.bukkit.inventory.CraftingInventory inventory && matches(inventory.getRecipe())) {
|
||||
inventory.setResult(items.prototype());
|
||||
plugin.getServer().getPluginManager().callEvent(new org.bukkit.event.inventory.PrepareItemCraftEvent(inventory, view, false));
|
||||
online.updateInventory();
|
||||
}
|
||||
}));
|
||||
}
|
||||
public void close() { if (registered) plugin.getServer().removeRecipe(RECIPE); }
|
||||
@org.bukkit.event.EventHandler(priority = org.bukkit.event.EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onCraft(CraftItemEvent event) {
|
||||
if (!matches(event.getRecipe())) return;
|
||||
var identity = items.identify(event.getInventory().getResult());
|
||||
if (!(event.getWhoClicked() instanceof org.bukkit.entity.Player player) || identity.isEmpty()
|
||||
|| !identity.orElseThrow().issuer().equals(player.getUniqueId())
|
||||
|| !REWARDS.valid(states.snapshot(), player.getUniqueId(), identity.orElseThrow())) {
|
||||
event.setCancelled(true);
|
||||
event.getInventory().setResult(null);
|
||||
}
|
||||
}
|
||||
@org.bukkit.event.EventHandler(priority = org.bukkit.event.EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onCrafter(CrafterCraftEvent event) {
|
||||
if (matches(event.getRecipe())) event.setCancelled(true);
|
||||
}
|
||||
@org.bukkit.event.EventHandler(priority = org.bukkit.event.EventPriority.HIGHEST)
|
||||
public void onPrepare(org.bukkit.event.inventory.PrepareItemCraftEvent event) {
|
||||
if (!matches(event.getInventory().getRecipe()) || event.getInventory().getResult() == null) return;
|
||||
if (!(event.getView().getPlayer() instanceof org.bukkit.entity.Player player)) {
|
||||
event.getInventory().setResult(null);
|
||||
return;
|
||||
}
|
||||
var token = REWARDS.craftingToken(states.snapshot(), player.getUniqueId());
|
||||
event.getInventory().setResult(token.map(items::create).orElse(null));
|
||||
if (token.isEmpty()) ensureReceipt(player);
|
||||
}
|
||||
|
||||
static void configureRecipe(org.bukkit.inventory.ShapedRecipe recipe) {
|
||||
recipe.shape("HCH", "NKN", "HEH");
|
||||
recipe.setIngredient('H', org.bukkit.Material.HEART_OF_THE_SEA);
|
||||
recipe.setIngredient('C', org.bukkit.Material.HEAVY_CORE);
|
||||
recipe.setIngredient('N', org.bukkit.Material.NETHER_STAR);
|
||||
recipe.setIngredient('K', org.bukkit.Material.OMINOUS_TRIAL_KEY);
|
||||
recipe.setIngredient('E', org.bukkit.Material.DRAGON_EGG);
|
||||
}
|
||||
|
||||
private static boolean matches(org.bukkit.inventory.Recipe recipe) {
|
||||
return recipe instanceof org.bukkit.Keyed keyed && keyed.getKey().equals(RECIPE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package games.dmg.spigotignis;
|
||||
|
||||
import java.util.Optional;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public final class DaggerItems {
|
||||
private final java.util.function.Supplier<ItemStack> factory;
|
||||
public DaggerItems() { this(() -> new ItemStack(org.bukkit.Material.OMINOUS_TRIAL_KEY)); }
|
||||
DaggerItems(java.util.function.Supplier<ItemStack> factory) { this.factory = factory; }
|
||||
public ItemStack prototype() {
|
||||
var item = factory.get();
|
||||
var meta = item.getItemMeta();
|
||||
meta.displayName(net.kyori.adventure.text.Component.text("The Dagger", net.kyori.adventure.text.format.NamedTextColor.DARK_PURPLE));
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
public ItemStack create(ItemToken token) {
|
||||
var item = prototype();
|
||||
var meta = item.getItemMeta();
|
||||
meta.getPersistentDataContainer().set(IDENTITY, org.bukkit.persistence.PersistentDataType.STRING,
|
||||
EchoIdentity.encode(new EchoToken(token.issuer(), token.receipt(), token.generation())));
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
private static final org.bukkit.NamespacedKey IDENTITY = new org.bukkit.NamespacedKey("spigotignis", "dagger_identity");
|
||||
public boolean offer(org.bukkit.entity.Player player, ItemToken token) {
|
||||
for (var item : player.getInventory().getContents()) {
|
||||
if (identify(item).filter(token::equals).isPresent()) return true;
|
||||
}
|
||||
if (identify(player.getItemOnCursor()).filter(token::equals).isPresent()) return true;
|
||||
if (player.getInventory().firstEmpty() < 0) return false;
|
||||
return player.getInventory().addItem(create(token)).isEmpty();
|
||||
}
|
||||
|
||||
public Optional<ItemToken> identify(ItemStack item) {
|
||||
if (item == null || item.getType() != org.bukkit.Material.OMINOUS_TRIAL_KEY || !item.hasItemMeta()) return Optional.empty();
|
||||
return EchoIdentity.decode(item.getItemMeta().getPersistentDataContainer().get(IDENTITY, org.bukkit.persistence.PersistentDataType.STRING))
|
||||
.map(token -> new ItemToken(token.owner(), token.receipt(), token.generation()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package games.dmg.spigotignis;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.BoundingBox;
|
||||
|
||||
/** Server-thread collision policy; never loads chunks or performs a teleport. */
|
||||
public final class DaggerSafety {
|
||||
private static final long MAX_CELLS = 32768;
|
||||
private DaggerSafety() { }
|
||||
public static boolean safe(Player player, Location destination) {
|
||||
var world = player.getWorld();
|
||||
if (destination == null || destination.getWorld() != world
|
||||
|| !Double.isFinite(destination.getX()) || !Double.isFinite(destination.getY()) || !Double.isFinite(destination.getZ())) return false;
|
||||
var motion = destination.toVector().subtract(player.getLocation().toVector());
|
||||
var body = player.getBoundingBox().clone();
|
||||
var end = body.clone().shift(motion);
|
||||
if (end.getMinY() < world.getMinHeight() || end.getMaxY() > world.getMaxHeight()) return false;
|
||||
var border = world.getWorldBorder();
|
||||
for (double x : new double[]{end.getMinX(), end.getMaxX()}) {
|
||||
for (double z : new double[]{end.getMinZ(), end.getMaxZ()}) {
|
||||
if (!border.isInside(new Location(world, x, end.getMinY(), z))) return false;
|
||||
}
|
||||
}
|
||||
var swept = body.clone().union(end);
|
||||
if (swept.getMinX() <= Integer.MIN_VALUE + 2 || swept.getMaxX() >= Integer.MAX_VALUE - 2
|
||||
|| swept.getMinZ() <= Integer.MIN_VALUE + 2 || swept.getMaxZ() >= Integer.MAX_VALUE - 2) return false;
|
||||
// A one-cell halo includes shapes protruding beyond their owning block.
|
||||
int minX = (int) Math.floor(swept.getMinX()) - 1, maxX = (int) Math.floor(swept.getMaxX()) + 1;
|
||||
int minZ = (int) Math.floor(swept.getMinZ()) - 1, maxZ = (int) Math.floor(swept.getMaxZ()) + 1;
|
||||
int minY = Math.max(world.getMinHeight(), (int) Math.floor(swept.getMinY()) - 1);
|
||||
int maxY = Math.min(world.getMaxHeight() - 1, (int) Math.floor(swept.getMaxY()) + 1);
|
||||
long nx = (long) maxX - minX + 1, ny = (long) maxY - minY + 1, nz = (long) maxZ - minZ + 1;
|
||||
if (nx <= 0 || ny <= 0 || nz <= 0 || nx > MAX_CELLS || ny > MAX_CELLS || nz > MAX_CELLS || nx * ny * nz > MAX_CELLS) return false;
|
||||
for (int x = minX >> 4; x <= maxX >> 4; x++) {
|
||||
for (int z = minZ >> 4; z <= maxZ >> 4; z++) {
|
||||
if (!world.isChunkLoaded(x, z)) return false;
|
||||
}
|
||||
}
|
||||
var supportedBody = end.clone().shift(0, -.05, 0);
|
||||
for (int x = minX; x <= maxX; x++) {
|
||||
for (int y = minY; y <= maxY; y++) {
|
||||
for (int z = minZ; z <= maxZ; z++) {
|
||||
var block = world.getBlockAt(x, y, z);
|
||||
var cell = new BoundingBox(x, y, z, x + 1, y + 1, z + 1);
|
||||
if ((block.isLiquid() || dangerous(block.getType()))
|
||||
&& (DaggerSweep.hits(body, motion, cell) || supportedBody.overlaps(cell))) return false;
|
||||
for (var local : block.getCollisionShape().getBoundingBoxes()) {
|
||||
if (DaggerSweep.hits(body, motion, local.clone().shift(x, y, z))) return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return player.wouldCollideUsing(supportedBody);
|
||||
}
|
||||
|
||||
private static boolean dangerous(Material material) {
|
||||
return switch (material) {
|
||||
case LAVA, FIRE, SOUL_FIRE, CACTUS, MAGMA_BLOCK, SWEET_BERRY_BUSH, WITHER_ROSE,
|
||||
POWDER_SNOW, POINTED_DRIPSTONE, CAMPFIRE, SOUL_CAMPFIRE -> true;
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package games.dmg.spigotignis;
|
||||
|
||||
import org.bukkit.util.BoundingBox;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
/** Continuous body sweep, avoiding thin-wall gaps introduced by point sampling. */
|
||||
public final class DaggerSweep {
|
||||
private DaggerSweep() { }
|
||||
public static boolean hits(BoundingBox body, Vector motion, BoundingBox obstacle) {
|
||||
Vector center = body.getCenter();
|
||||
// Shrink by a numerical tolerance so resting on a floor is not penetration.
|
||||
double hx = Math.max(0, body.getWidthX() / 2 - 1e-7);
|
||||
double hy = Math.max(0, body.getHeight() / 2 - 1e-7);
|
||||
double hz = Math.max(0, body.getWidthZ() / 2 - 1e-7);
|
||||
double[] start = {center.getX(), center.getY(), center.getZ()};
|
||||
double[] delta = {motion.getX(), motion.getY(), motion.getZ()};
|
||||
double[] min = {obstacle.getMinX() - hx, obstacle.getMinY() - hy, obstacle.getMinZ() - hz};
|
||||
double[] max = {obstacle.getMaxX() + hx, obstacle.getMaxY() + hy, obstacle.getMaxZ() + hz};
|
||||
double enter = 0, exit = 1;
|
||||
for (int axis = 0; axis < 3; axis++) {
|
||||
if (delta[axis] == 0) {
|
||||
if (start[axis] < min[axis] || start[axis] > max[axis]) return false;
|
||||
} else {
|
||||
double a = (min[axis] - start[axis]) / delta[axis];
|
||||
double b = (max[axis] - start[axis]) / delta[axis];
|
||||
enter = Math.max(enter, Math.min(a, b));
|
||||
exit = Math.min(exit, Math.max(a, b));
|
||||
if (enter > exit) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package games.dmg.spigotignis;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
/** Geometry only; visibility and world safety are supplied by the server-thread adapter. */
|
||||
public final class DaggerTargeting {
|
||||
private DaggerTargeting() { }
|
||||
public record Target(UUID id, Vector eye, boolean visible) { }
|
||||
|
||||
public static Vector forward(Vector feet, Vector direction) {
|
||||
return feet.clone().add(direction.clone().normalize().multiply(3));
|
||||
}
|
||||
public static Vector behind(Vector feet, float yaw) {
|
||||
double radians = Math.toRadians(yaw);
|
||||
return feet.clone().add(new Vector(Math.sin(radians) * 1.5, 0, -Math.cos(radians) * 1.5));
|
||||
}
|
||||
|
||||
public static Optional<Target> select(Vector eye, Vector direction, Collection<Target> candidates) {
|
||||
if (!Double.isFinite(direction.lengthSquared()) || direction.lengthSquared() <= 0) return Optional.empty();
|
||||
Vector facing = direction.clone().normalize();
|
||||
Target best = null;
|
||||
double bestAlignment = -1;
|
||||
for (Target target : candidates) {
|
||||
Vector offset = target.eye().clone().subtract(eye);
|
||||
double distanceSquared = offset.lengthSquared();
|
||||
if (!target.visible() || distanceSquared <= 0 || distanceSquared > 64) continue;
|
||||
double alignment = offset.dot(facing) / Math.sqrt(distanceSquared);
|
||||
if (alignment < Math.cos(Math.toRadians(15))) continue;
|
||||
if (alignment > bestAlignment || (alignment == bestAlignment && best != null && target.id().compareTo(best.id()) < 0)) {
|
||||
best = target;
|
||||
bestAlignment = alignment;
|
||||
}
|
||||
}
|
||||
return Optional.ofNullable(best);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package games.dmg.spigotignis;
|
||||
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Supplier;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
|
||||
public final class DaggerUse implements Listener {
|
||||
private static final TradableRewards REWARDS = new TradableRewards(Track.DAGGER);
|
||||
private final Supplier<IgnisState> states;
|
||||
private final DaggerItems items;
|
||||
private final DaggerCooldown cooldown;
|
||||
private final BiPredicate<Player, Location> safety;
|
||||
public DaggerUse(Supplier<IgnisState> states, DaggerItems items, DaggerCooldown cooldown, BiPredicate<Player, Location> safety) {
|
||||
this.states = states; this.items = items; this.cooldown = cooldown; this.safety = safety;
|
||||
}
|
||||
|
||||
// Air interactions can have block use denied by vanilla while item use remains allowed.
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onUse(PlayerInteractEvent event) {
|
||||
if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
if (event.useItemInHand() == Event.Result.DENY
|
||||
|| event.getAction() == Action.RIGHT_CLICK_BLOCK && event.useInteractedBlock() == Event.Result.DENY) return;
|
||||
var identity = items.identify(event.getItem());
|
||||
if (identity.isEmpty()) return;
|
||||
// A Dagger must never be consumed as a vanilla vault key, including revoked copies.
|
||||
event.setUseItemInHand(Event.Result.DENY);
|
||||
event.setUseInteractedBlock(Event.Result.DENY);
|
||||
Player player = event.getPlayer();
|
||||
if (!player.isOnline() || player.isDead() || player.getGameMode() == org.bukkit.GameMode.SPECTATOR
|
||||
|| !REWARDS.valid(states.get(), player.getUniqueId(), identity.orElseThrow())
|
||||
|| !cooldown.attempt(player.getUniqueId())) return;
|
||||
var feet = player.getLocation();
|
||||
var eye = player.getEyeLocation();
|
||||
var candidates = new java.util.ArrayList<DaggerTargeting.Target>();
|
||||
var positions = new java.util.HashMap<java.util.UUID, Location>();
|
||||
for (var other : player.getWorld().getPlayers()) {
|
||||
if (other.getUniqueId().equals(player.getUniqueId()) || !other.isOnline() || other.isDead()
|
||||
|| other.isInvisible() || other.getGameMode() == org.bukkit.GameMode.SPECTATOR
|
||||
|| !player.canSee(other)) continue;
|
||||
var otherEye = other.getEyeLocation();
|
||||
if (otherEye.distanceSquared(eye) > 64 || !loadedLine(eye, otherEye)) continue;
|
||||
candidates.add(new DaggerTargeting.Target(other.getUniqueId(), otherEye.toVector(), player.hasLineOfSight(other)));
|
||||
positions.put(other.getUniqueId(), other.getLocation());
|
||||
}
|
||||
var selected = DaggerTargeting.select(eye.toVector(), eye.getDirection(), candidates);
|
||||
var point = selected.map(target -> {
|
||||
var position = positions.get(target.id());
|
||||
return DaggerTargeting.behind(position.toVector(), position.getYaw());
|
||||
}).orElseGet(() -> DaggerTargeting.forward(feet.toVector(), eye.getDirection()));
|
||||
var destination = new Location(player.getWorld(), point.getX(), point.getY(), point.getZ(), feet.getYaw(), feet.getPitch());
|
||||
if (safety.test(player, destination)) player.teleport(destination, TeleportCause.PLUGIN);
|
||||
}
|
||||
|
||||
private static boolean loadedLine(Location from, Location to) {
|
||||
for (int x = Math.min(from.getBlockX(), to.getBlockX()) >> 4; x <= Math.max(from.getBlockX(), to.getBlockX()) >> 4; x++) {
|
||||
for (int z = Math.min(from.getBlockZ(), to.getBlockZ()) >> 4; z <= Math.max(from.getBlockZ(), to.getBlockZ()) >> 4; z++) {
|
||||
if (!from.getWorld().isChunkLoaded(x, z)) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ public final class IgnisCommands implements CommandExecutor, TabCompleter {
|
||||
private final StateService states;
|
||||
private final EchoGameplay gameplay;
|
||||
private final InvisibilityProgress maskTracker;
|
||||
private final PearlProgress pearlTracker;
|
||||
private final Map<CommandSender, Confirmation> confirmations = new HashMap<>();
|
||||
|
||||
public IgnisCommands(JavaPlugin plugin, StateService states, EchoGameplay gameplay) {
|
||||
@@ -26,10 +27,16 @@ public final class IgnisCommands implements CommandExecutor, TabCompleter {
|
||||
}
|
||||
|
||||
public IgnisCommands(JavaPlugin plugin, StateService states, EchoGameplay gameplay, InvisibilityProgress maskTracker) {
|
||||
this(plugin, states, gameplay, maskTracker, null);
|
||||
}
|
||||
|
||||
public IgnisCommands(JavaPlugin plugin, StateService states, EchoGameplay gameplay,
|
||||
InvisibilityProgress maskTracker, PearlProgress pearlTracker) {
|
||||
this.plugin = plugin;
|
||||
this.states = states;
|
||||
this.gameplay = gameplay;
|
||||
this.maskTracker = maskTracker;
|
||||
this.pearlTracker = pearlTracker;
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
@@ -76,12 +83,14 @@ public final class IgnisCommands implements CommandExecutor, TabCompleter {
|
||||
long value = Long.parseLong(args[4]);
|
||||
boolean add = args[1].equalsIgnoreCase("add");
|
||||
CompletableFuture<IgnisState> checkpoint = track == Track.MASK && maskTracker != null
|
||||
? maskTracker.checkpoint(id) : CompletableFuture.completedFuture(states.snapshot());
|
||||
? maskTracker.checkpoint(id) : track == Track.DAGGER && pearlTracker != null
|
||||
? pearlTracker.checkpoint(id) : CompletableFuture.completedFuture(states.snapshot());
|
||||
mutation(sender, "progress " + id + " " + track + " " + args[1] + " " + value,
|
||||
checkpoint.thenCompose(ignored -> states.update(state -> ProgressAdministration.progress(state, id, track, value, add))));
|
||||
} else if (args.length == 3 && args[0].equalsIgnoreCase("give") && args[2].equalsIgnoreCase("mask")) {
|
||||
} else if (args.length == 3 && args[0].equalsIgnoreCase("give") && Set.of("mask", "dagger").contains(args[2].toLowerCase(Locale.ROOT))) {
|
||||
UUID id = resolve(args[1]), receipt = UUID.randomUUID();
|
||||
mutation(sender, "grant Mask " + id, states.update(state -> MaskRewards.issue(state, id, receipt, true)));
|
||||
var rewards = new TradableRewards(Track.valueOf(args[2].toUpperCase(Locale.ROOT)));
|
||||
mutation(sender, "grant " + args[2] + " " + id, states.update(state -> rewards.issue(state, id, receipt, true)));
|
||||
} else if (args.length == 3 && (args[0].equalsIgnoreCase("give") && args[2].equalsIgnoreCase("echo")
|
||||
|| args[0].equalsIgnoreCase("complete") && args[2].equalsIgnoreCase("void"))) {
|
||||
UUID id = resolve(args[1]), receipt = UUID.randomUUID();
|
||||
@@ -106,7 +115,7 @@ public final class IgnisCommands implements CommandExecutor, TabCompleter {
|
||||
} else throw new IllegalArgumentException("Use reset <player|UUID> <track|all> [confirm].");
|
||||
} else sender.sendMessage("Ignis admin: inspect <player|UUID>; limits [set <mask-ms|pearls|darkness-ms> <value>]; "
|
||||
+ "progress <set|add> <player|UUID> <mask|dagger|heart> <value>; complete <player|UUID> void; "
|
||||
+ "give <player|UUID> <echo|mask>; reset <player|UUID> <track|all> [confirm].");
|
||||
+ "give <player|UUID> <echo|mask|dagger>; reset <player|UUID> <track|all> [confirm].");
|
||||
} catch (IllegalArgumentException | ArithmeticException exception) {
|
||||
sender.sendMessage("Invalid Ignis command: " + exception.getMessage());
|
||||
}
|
||||
@@ -165,7 +174,7 @@ public final class IgnisCommands implements CommandExecutor, TabCompleter {
|
||||
if (args.length == 2) options = List.of("set", "add");
|
||||
else if (args.length == 4) options = List.of("mask", "dagger", "heart");
|
||||
else if (args.length == 5) options = List.of("0", "1");
|
||||
} else if (args.length == 3 && sub.equals("give")) options = List.of("echo", "mask");
|
||||
} else if (args.length == 3 && sub.equals("give")) options = List.of("echo", "mask", "dagger");
|
||||
else if (args.length == 3 && sub.equals("complete")) options = List.of("void");
|
||||
else if (sub.equals("reset")) {
|
||||
if (args.length == 3) options = List.of("void", "mask", "dagger", "heart", "all");
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package games.dmg.spigotignis;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
/** Receipt identity; the item's PDC key and reward service supply the track. */
|
||||
public record ItemToken(UUID issuer, UUID receipt, long generation) {
|
||||
public ItemToken {
|
||||
Objects.requireNonNull(issuer);
|
||||
Objects.requireNonNull(receipt);
|
||||
if (generation < 0) throw new IllegalArgumentException("Invalid item generation.");
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ public final class MaskCrafting implements Listener, Runnable {
|
||||
private final EchoGameplay dispatch;
|
||||
private final Set<UUID> preparing = new HashSet<>();
|
||||
private final Set<MaskToken> delivering = new HashSet<>();
|
||||
private final Set<MaskToken> offered = new HashSet<>();
|
||||
private boolean registered;
|
||||
private final java.util.function.Function<org.bukkit.inventory.ItemStack, ShapedRecipe> recipeFactory;
|
||||
|
||||
@@ -90,10 +91,15 @@ public final class MaskCrafting implements Listener, Runnable {
|
||||
for (var entry : state.pendingRewards().entrySet()) {
|
||||
if (entry.getValue() != Track.MASK) continue;
|
||||
var token = new MaskToken(player.getUniqueId(), entry.getKey(), state.track(Track.MASK).generation());
|
||||
if (delivering.contains(token) || !items.offer(player, token)) continue;
|
||||
if (delivering.contains(token)) continue;
|
||||
if (!offered.contains(token) && !items.offer(player, token)) continue;
|
||||
offered.add(token);
|
||||
delivering.add(token);
|
||||
states.update(current -> MaskRewards.acknowledge(current, token))
|
||||
.whenComplete((ignored, error) -> dispatch.onServer(() -> delivering.remove(token)));
|
||||
.whenComplete((ignored, error) -> dispatch.onServer(() -> {
|
||||
delivering.remove(token);
|
||||
if (error == null) offered.remove(token);
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,58 +1,26 @@
|
||||
package games.dmg.spigotignis;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
/** Crafting receipts are durable before vanilla may offer a result or consume ingredients. */
|
||||
/** Compatibility facade preserving existing Mask tokens and persisted identities. */
|
||||
public final class MaskRewards {
|
||||
private static final TradableRewards REWARDS = new TradableRewards(Track.MASK);
|
||||
private MaskRewards() { }
|
||||
|
||||
public static IgnisState issue(IgnisState state, UUID issuer, UUID receipt, boolean adminGrant) {
|
||||
PlayerState player = state.players().getOrDefault(issuer, PlayerState.empty());
|
||||
TrackState previous = player.track(Track.MASK);
|
||||
if (!adminGrant && !previous.unlocked()) throw new IllegalArgumentException("Mask crafting is not unlocked.");
|
||||
if (player.issuedRewards().containsKey(receipt)) {
|
||||
if (player.issuedRewards().get(receipt) != Track.MASK) throw new IllegalArgumentException("Receipt is already used.");
|
||||
return state;
|
||||
}
|
||||
var tracks = new HashMap<>(player.tracks());
|
||||
tracks.put(Track.MASK, new TrackState(previous.progress(), true, previous.activated(), previous.generation()));
|
||||
var issued = new HashMap<>(player.issuedRewards());
|
||||
issued.put(receipt, Track.MASK);
|
||||
var pending = new HashMap<>(player.pendingRewards());
|
||||
if (adminGrant) pending.put(receipt, Track.MASK);
|
||||
return replace(state, issuer, new PlayerState(tracks, pending, issued));
|
||||
return REWARDS.issue(state, issuer, receipt, adminGrant);
|
||||
}
|
||||
|
||||
public static boolean valid(IgnisState state, UUID holder, MaskToken token) {
|
||||
PlayerState origin = state.players().getOrDefault(token.issuer(), PlayerState.empty());
|
||||
return state.players().getOrDefault(holder, PlayerState.empty()).track(Track.MASK).unlocked()
|
||||
&& origin.track(Track.MASK).unlocked()
|
||||
&& origin.track(Track.MASK).generation() == token.generation()
|
||||
&& origin.issuedRewards().get(token.receipt()) == Track.MASK;
|
||||
return REWARDS.valid(state, holder, convert(token));
|
||||
}
|
||||
|
||||
public static Optional<MaskToken> craftingToken(IgnisState state, UUID issuer) {
|
||||
PlayerState player = state.players().getOrDefault(issuer, PlayerState.empty());
|
||||
if (!player.track(Track.MASK).unlocked()) return Optional.empty();
|
||||
return player.issuedRewards().entrySet().stream().filter(entry -> entry.getValue() == Track.MASK)
|
||||
.filter(entry -> !player.pendingRewards().containsKey(entry.getKey()))
|
||||
.map(java.util.Map.Entry::getKey).sorted().findFirst()
|
||||
.map(id -> new MaskToken(issuer, id, player.track(Track.MASK).generation()));
|
||||
return REWARDS.craftingToken(state, issuer).map(token -> new MaskToken(token.issuer(), token.receipt(), token.generation()));
|
||||
}
|
||||
|
||||
public static IgnisState acknowledge(IgnisState state, MaskToken token) {
|
||||
if (!valid(state, token.issuer(), token)) return state;
|
||||
PlayerState player = state.players().get(token.issuer());
|
||||
var pending = new HashMap<>(player.pendingRewards());
|
||||
pending.remove(token.receipt());
|
||||
return replace(state, token.issuer(), new PlayerState(player.tracks(), pending, player.issuedRewards()));
|
||||
return REWARDS.acknowledge(state, convert(token));
|
||||
}
|
||||
|
||||
private static IgnisState replace(IgnisState state, UUID issuer, PlayerState player) {
|
||||
var players = new HashMap<>(state.players());
|
||||
players.put(issuer, player);
|
||||
return new IgnisState(state.limits(), players);
|
||||
private static ItemToken convert(MaskToken token) {
|
||||
return new ItemToken(token.issuer(), token.receipt(), token.generation());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package games.dmg.spigotignis;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
import com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerStatisticIncrementEvent;
|
||||
|
||||
/** Correlates a launch with the post-consumption vanilla USE_ITEM notification. */
|
||||
public final class PearlLaunchListener implements Listener {
|
||||
private record Probe(PlayerLaunchProjectileEvent event, int before) { }
|
||||
private final java.util.Map<UUID, java.util.Deque<Probe>> pending = new java.util.HashMap<>();
|
||||
private final Consumer<Runnable> nextTick;
|
||||
private final Consumer<UUID> credit;
|
||||
public PearlLaunchListener(Consumer<Runnable> nextTick, Consumer<UUID> credit) {
|
||||
this.nextTick = nextTick;
|
||||
this.credit = credit;
|
||||
}
|
||||
|
||||
@org.bukkit.event.EventHandler(priority = org.bukkit.event.EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onLaunch(PlayerLaunchProjectileEvent event) {
|
||||
if (event.isCancelled() || !(event.getProjectile() instanceof org.bukkit.entity.EnderPearl)
|
||||
|| event.getItemStack().getType() != org.bukkit.Material.ENDER_PEARL) return;
|
||||
UUID player = event.getPlayer().getUniqueId();
|
||||
var probe = new Probe(event, event.getItemStack().getAmount());
|
||||
pending.computeIfAbsent(player, ignored -> new java.util.ArrayDeque<>()).addFirst(probe);
|
||||
nextTick.accept(() -> {
|
||||
var probes = pending.get(player);
|
||||
if (probes != null) {
|
||||
probes.remove(probe);
|
||||
if (probes.isEmpty()) pending.remove(player);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@org.bukkit.event.EventHandler(priority = org.bukkit.event.EventPriority.MONITOR)
|
||||
public void onUse(PlayerStatisticIncrementEvent event) {
|
||||
if (event.getStatistic() != org.bukkit.Statistic.USE_ITEM || event.getMaterial() != org.bukkit.Material.ENDER_PEARL) return;
|
||||
UUID player = event.getPlayer().getUniqueId();
|
||||
var probes = pending.get(player);
|
||||
if (probes == null) return;
|
||||
var iterator = probes.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Probe probe = iterator.next();
|
||||
if (probe.event().isCancelled() || !probe.event().shouldConsume()
|
||||
|| probe.event().getItemStack().getAmount() >= probe.before()) continue;
|
||||
iterator.remove();
|
||||
if (probes.isEmpty()) pending.remove(player);
|
||||
credit.accept(player);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package games.dmg.spigotignis;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/** Buffers observed consumed throws until acknowledged by the persistence worker. */
|
||||
public final class PearlProgress {
|
||||
private final StateService states;
|
||||
public PearlProgress(StateService states) { this.states = states; }
|
||||
private static final class Buffer {
|
||||
final long generation;
|
||||
long count;
|
||||
CompletableFuture<IgnisState> saving;
|
||||
Buffer(long generation) { this.generation = generation; }
|
||||
}
|
||||
private final java.util.Map<UUID, Buffer> pending = new java.util.HashMap<>();
|
||||
private Buffer buffer(UUID player) {
|
||||
long generation = generation(states.snapshot(), player);
|
||||
return pending.compute(player, (ignored, old) -> old == null || old.generation != generation ? new Buffer(generation) : old);
|
||||
}
|
||||
private static long generation(IgnisState state, UUID player) {
|
||||
return state.players().getOrDefault(player, PlayerState.empty()).track(Track.DAGGER).generation();
|
||||
}
|
||||
public synchronized void record(UUID player) {
|
||||
Buffer buffer = buffer(player);
|
||||
buffer.count = Math.addExact(buffer.count, 1);
|
||||
}
|
||||
public synchronized CompletableFuture<Void> checkpointAll() {
|
||||
return CompletableFuture.allOf(new java.util.ArrayList<>(pending.keySet()).stream()
|
||||
.map(this::checkpoint).toArray(CompletableFuture<?>[]::new));
|
||||
}
|
||||
|
||||
public synchronized CompletableFuture<IgnisState> checkpoint(UUID player) {
|
||||
Buffer buffer = buffer(player);
|
||||
if (buffer.saving != null) return buffer.saving.thenCompose(ignored -> checkpoint(player));
|
||||
long count = buffer.count;
|
||||
buffer.count = 0;
|
||||
if (count == 0) {
|
||||
pending.remove(player, buffer);
|
||||
return CompletableFuture.completedFuture(states.snapshot());
|
||||
}
|
||||
var acknowledgement = new CompletableFuture<IgnisState>();
|
||||
buffer.saving = acknowledgement;
|
||||
states.update(state -> generation(state, player) == buffer.generation
|
||||
? ProgressAdministration.progress(state, player, Track.DAGGER, count, true) : state)
|
||||
.whenComplete((state, error) -> {
|
||||
synchronized (this) {
|
||||
if (error != null) buffer.count = Math.addExact(buffer.count, count);
|
||||
buffer.saving = null;
|
||||
}
|
||||
if (error != null) acknowledgement.completeExceptionally(error);
|
||||
else acknowledgement.complete(state);
|
||||
});
|
||||
return acknowledgement;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,9 @@ public final class SpigotIgnisPlugin extends JavaPlugin {
|
||||
private MaskCrafting maskCrafting;
|
||||
private MaskEffects maskEffects;
|
||||
private MaskEquipmentListener maskEquipment;
|
||||
private PearlProgress pearlProgress;
|
||||
private DaggerCrafting daggerCrafting;
|
||||
private final java.util.concurrent.atomic.AtomicBoolean pearlSaveWarning = new java.util.concurrent.atomic.AtomicBoolean();
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
@@ -41,13 +44,27 @@ public final class SpigotIgnisPlugin extends JavaPlugin {
|
||||
getServer().getScheduler().runTaskTimer(this, new MaskSkinLoader(this, maskItems, gameplay), 1L, 6000L);
|
||||
getServer().getScheduler().runTaskTimer(this, maskCrafting, 1L, 20L);
|
||||
getServer().getScheduler().runTaskTimer(this, maskEffects, 1L, 1L);
|
||||
var commands = new IgnisCommands(this, service, gameplay, maskTracker);
|
||||
pearlProgress = new PearlProgress(service);
|
||||
var pearlListener = new PearlLaunchListener(action -> getServer().getScheduler().runTask(this, action), id -> {
|
||||
pearlProgress.record(id);
|
||||
pearlProgress.checkpoint(id).whenComplete((saved, failure) -> reportPearlSave(failure));
|
||||
});
|
||||
getServer().getPluginManager().registerEvents(pearlListener, this);
|
||||
getServer().getScheduler().runTaskTimer(this,
|
||||
() -> pearlProgress.checkpointAll().whenComplete((saved, failure) -> reportPearlSave(failure)), 20L, 20L);
|
||||
var daggerItems = new DaggerItems();
|
||||
daggerCrafting = new DaggerCrafting(this, service, daggerItems, gameplay);
|
||||
getServer().getPluginManager().registerEvents(daggerCrafting, this);
|
||||
getServer().getPluginManager().registerEvents(new DaggerUse(service::snapshot, daggerItems,
|
||||
new DaggerCooldown(System::nanoTime), DaggerSafety::safe), this);
|
||||
getServer().getScheduler().runTaskTimer(this, daggerCrafting, 1L, 20L);
|
||||
var commands = new IgnisCommands(this, service, gameplay, maskTracker, pearlProgress);
|
||||
for (String name : java.util.List.of("ignis", "ignisadmin")) {
|
||||
var command = java.util.Objects.requireNonNull(getCommand(name), "Missing command " + name);
|
||||
command.setExecutor(commands);
|
||||
command.setTabCompleter(commands);
|
||||
}
|
||||
getLogger().info("Ignis Echo and Mask enabled. Dagger and Heart remain in development.");
|
||||
getLogger().info("Ignis Echo, Mask and Dagger enabled. Heart remains in development.");
|
||||
});
|
||||
} catch (org.bukkit.plugin.IllegalPluginAccessException ignored) {
|
||||
service.close();
|
||||
@@ -58,10 +75,25 @@ public final class SpigotIgnisPlugin extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
if (maskEffects != null) maskEffects.close();
|
||||
if (maskEquipment != null) com.comphenix.protocol.ProtocolLibrary.getProtocolManager().removePacketListener(maskEquipment);
|
||||
if (maskCrafting != null) maskCrafting.close();
|
||||
if (maskProgress != null) maskProgress.stop();
|
||||
if (initialization != null) initialization.thenAccept(StateService::close);
|
||||
try {
|
||||
if (maskEffects != null) maskEffects.close();
|
||||
if (maskEquipment != null) com.comphenix.protocol.ProtocolLibrary.getProtocolManager().removePacketListener(maskEquipment);
|
||||
if (maskCrafting != null) maskCrafting.close();
|
||||
if (daggerCrafting != null) daggerCrafting.close();
|
||||
if (maskProgress != null) maskProgress.stop();
|
||||
} finally {
|
||||
var drain = pearlProgress == null ? CompletableFuture.<Void>completedFuture(null) : pearlProgress.checkpointAll();
|
||||
drain.whenComplete((saved, failure) -> {
|
||||
reportPearlSave(failure);
|
||||
if (initialization != null) initialization.thenAccept(StateService::close);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void reportPearlSave(Throwable failure) {
|
||||
if (failure == null) pearlSaveWarning.set(false);
|
||||
else if (pearlSaveWarning.compareAndSet(false, true)) {
|
||||
getLogger().warning("Pearl progress save failed; unacknowledged credit remains in memory for retry while enabled.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package games.dmg.spigotignis;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
/** Track-specific durable issuance and personal-use validation for tradable rewards. */
|
||||
public final class TradableRewards {
|
||||
private final Track track;
|
||||
public TradableRewards(Track track) {
|
||||
if (track == null || track == Track.VOID) throw new IllegalArgumentException("Echo uses bound activation rewards.");
|
||||
this.track = track;
|
||||
}
|
||||
|
||||
public IgnisState issue(IgnisState state, UUID issuer, UUID receipt, boolean adminGrant) {
|
||||
PlayerState player = state.players().getOrDefault(issuer, PlayerState.empty());
|
||||
TrackState previous = player.track(track);
|
||||
if (!adminGrant && !previous.unlocked()) throw new IllegalArgumentException("Crafting is not unlocked.");
|
||||
if (player.issuedRewards().containsKey(receipt)) {
|
||||
if (player.issuedRewards().get(receipt) != track) throw new IllegalArgumentException("Receipt is already used.");
|
||||
return state;
|
||||
}
|
||||
var tracks = new HashMap<>(player.tracks());
|
||||
tracks.put(track, new TrackState(previous.progress(), true, previous.activated(), previous.generation()));
|
||||
var issued = new HashMap<>(player.issuedRewards());
|
||||
issued.put(receipt, track);
|
||||
var pending = new HashMap<>(player.pendingRewards());
|
||||
if (adminGrant) pending.put(receipt, track);
|
||||
return replace(state, issuer, new PlayerState(tracks, pending, issued));
|
||||
}
|
||||
|
||||
public boolean valid(IgnisState state, UUID holder, ItemToken token) {
|
||||
PlayerState origin = state.players().getOrDefault(token.issuer(), PlayerState.empty());
|
||||
return state.players().getOrDefault(holder, PlayerState.empty()).track(track).unlocked()
|
||||
&& origin.track(track).unlocked()
|
||||
&& origin.track(track).generation() == token.generation()
|
||||
&& origin.issuedRewards().get(token.receipt()) == track;
|
||||
}
|
||||
|
||||
public Optional<ItemToken> craftingToken(IgnisState state, UUID issuer) {
|
||||
PlayerState player = state.players().getOrDefault(issuer, PlayerState.empty());
|
||||
if (!player.track(track).unlocked()) return Optional.empty();
|
||||
return player.issuedRewards().entrySet().stream().filter(entry -> entry.getValue() == track)
|
||||
.filter(entry -> !player.pendingRewards().containsKey(entry.getKey()))
|
||||
.map(java.util.Map.Entry::getKey).sorted().findFirst()
|
||||
.map(id -> new ItemToken(issuer, id, player.track(track).generation()));
|
||||
}
|
||||
|
||||
public IgnisState acknowledge(IgnisState state, ItemToken token) {
|
||||
if (!valid(state, token.issuer(), token)) return state;
|
||||
PlayerState player = state.players().get(token.issuer());
|
||||
var pending = new HashMap<>(player.pendingRewards());
|
||||
pending.remove(token.receipt());
|
||||
return replace(state, token.issuer(), new PlayerState(player.tracks(), pending, player.issuedRewards()));
|
||||
}
|
||||
|
||||
private static IgnisState replace(IgnisState state, UUID issuer, PlayerState player) {
|
||||
var players = new HashMap<>(state.players());
|
||||
players.put(issuer, player);
|
||||
return new IgnisState(state.limits(), players);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ name: SpigotIgnis
|
||||
version: '${version}'
|
||||
main: games.dmg.spigotignis.SpigotIgnisPlugin
|
||||
api-version: '1.21'
|
||||
description: Earnable shadow progression with Echo of the Abyss and The Mask.
|
||||
description: Earnable shadow progression with Echo of the Abyss, The Mask, and The Dagger.
|
||||
depend: [ProtocolLib]
|
||||
commands:
|
||||
ignis:
|
||||
|
||||
Reference in new issue
Block a user