Match beacon range and accept ordinary stamped payments
Some checks failed
Planet DuneChest Build / dunechest (push) Successful in 53s
DuneRealms Plugin CI / plugins (push) Has been cancelled

This commit is contained in:
unimatrixgit 2026-11-30 19:34:14 +01:00
commit 5a53ff0c56
3 changed files with 34 additions and 3 deletions

View file

@ -1,9 +1,18 @@
package com.example.dunechest;
import java.util.List;
import java.util.Set;
/** Pure vanilla-beacon rules (no Bukkit types): effect availability per pyramid level, range and duration. */
public final class BeaconRules {
private static final Set<String> COMMODITY_METADATA = Set.of(
"dunerealms:quality", "dunerealms:equipment_mark", "dunerealms:item_class",
"dunerealms:metadata_policy", "dunerealms:metadata_lore_header", "dunerealms:origin_world");
static boolean ordinaryPaymentMetadata(Set<String> keys) {
return COMMODITY_METADATA.containsAll(keys);
}
private BeaconRules() {}
public static final List<String> LEVEL1 = List.of("SPEED", "HASTE"), LEVEL2 = List.of("RESISTANCE", "JUMP_BOOST"), LEVEL3 = List.of("STRENGTH");

View file

@ -23,6 +23,7 @@ import org.bukkit.potion.PotionEffectType;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.util.BoundingBox;
import org.bukkit.util.Transformation;
import org.joml.AxisAngle4f;
import org.joml.Vector3f;
@ -482,9 +483,11 @@ public final class StorageModule implements Listener, CommandExecutor {
int range = BeaconRules.range(level), dur = BeaconRules.durationTicks(level);
var primary = effect(p.primary); if (primary == null) return;
int amp = BeaconRules.primaryAmplifier(level, p.primary, p.secondary); boolean regen = BeaconRules.regeneration(level, p.primary, p.secondary);
double cx = b.getX() + 0.5, cz = b.getZ() + 0.5;
BoundingBox area = new BoundingBox(b.getX() - range, b.getY() - range, b.getZ() - range,
b.getX() + 1 + range, b.getY() + 1 + range + b.getWorld().getMaxHeight() - b.getWorld().getMinHeight(),
b.getZ() + 1 + range);
for (Player pl : b.getWorld().getPlayers()) {
Location l = pl.getLocation(); if (Math.abs(l.getX() - cx) > range + 0.5 || Math.abs(l.getZ() - cz) > range + 0.5) continue;
if (pl.getGameMode() == GameMode.SPECTATOR || !area.overlaps(pl.getBoundingBox())) continue;
pl.addPotionEffect(new PotionEffect(primary, dur, amp, true, true, true));
if (regen) pl.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, dur, 0, true, true, true));
}
@ -525,6 +528,15 @@ public final class StorageModule implements Listener, CommandExecutor {
actions.put(slot, () -> beaconConfirm(pl, key, primary, null));
com.example.dunegui.NativeMenus.inventory(plugin, pl, "Dune Beacon", model, actions);
}
private static boolean beaconPayment(ItemStack item) {
if (item == null || item.isEmpty() || !PAYMENT.contains(item.getType())) return false;
ItemMeta meta = item.getItemMeta();
return !meta.hasDisplayName() && !meta.hasItemName() && !meta.hasItemModel()
&& !meta.hasCustomModelData() && !meta.hasEnchants()
&& BeaconRules.ordinaryPaymentMetadata(meta.getPersistentDataContainer().getKeys().stream()
.map(NamespacedKey::toString).collect(java.util.stream.Collectors.toSet()));
}
private void beaconConfirm(Player pl, String key, String primary, String secondary) {
var p = data.blocks.get(key); if (p == null || p.kind != StorageData.Kind.BEACON) return;
int level = beaconLevel(locate(key, p).getBlock());
@ -535,7 +547,7 @@ public final class StorageModule implements Listener, CommandExecutor {
int paymentSlot = 0;
while (paymentSlot < slots.length) {
ItemStack item = slots[paymentSlot];
if (item != null && PAYMENT.contains(item.getType()) && !item.hasItemMeta()) break;
if (beaconPayment(item)) break;
paymentSlot++;
}
if (paymentSlot == slots.length) { say(pl, payText() + "."); return; }

View file

@ -2,9 +2,19 @@ package com.example.dunechest;
import static org.junit.jupiter.api.Assertions.*;
import java.util.List;
import java.util.Set;
import org.junit.jupiter.api.Test;
class BeaconRulesTest {
@Test void acceptsOrdinaryJarvisMetadataAndRejectsCustomIdentities() {
assertTrue(BeaconRules.ordinaryPaymentMetadata(Set.of()));
assertTrue(BeaconRules.ordinaryPaymentMetadata(Set.of("dunerealms:quality",
"dunerealms:equipment_mark", "dunerealms:item_class", "dunerealms:metadata_policy",
"dunerealms:metadata_lore_header", "dunerealms:origin_world")));
assertFalse(BeaconRules.ordinaryPaymentMetadata(Set.of("dunerealms:quality", "executableitems:ei-id")));
assertFalse(BeaconRules.ordinaryPaymentMetadata(Set.of("dunerealms:item")));
}
@Test void primariesGrowWithLevel() {
assertEquals(List.of(), BeaconRules.primaries(0));
assertEquals(List.of("SPEED", "HASTE"), BeaconRules.primaries(1));