Configure stillsuit sunlight wear and preserve installed Core behavior (374)

This commit is contained in:
Dev 2026-11-06 08:29:10 +01:00
commit 55ab317428
7 changed files with 158 additions and 6 deletions

View file

@ -1,5 +1,21 @@
Ticket374 / public590078 — implementation checkpoint 5November2026
# Stillsuit sunlight wear — ticket #590078 (native374)
Implemented candidate only: clear daytime open-sky Arrakis wears each tagged, damageable equipped stillsuit piece. Per-item persisted exposure counter; Common15 / Uncommon30 / Rare45 / Epic60 / Legendary90 seconds per normal1durability attempt. Missing/unknown quality usesCommon. Standard Paper damageItemStack(slot,1) preserves enchantment/event/break logic. Unbreakable equipment skipped. Full-suit protection re-evaluated after wear, so a breaking item can expose player. Water resets existing lethal heat timer; shade/night/weather/otherworld/creative/spectator/death continue to stop exposure. Removed cosmetic fire and its broad FIRE_TICK cancellation so ordinary fire damage is no longer suppressed by sun exposure.
Implementation and staged validation, 6 November 2026. This checkpoint is not a deployment claim.
Actual validation: Java21 Gradle8.14.3 compileJava and jar PASS against configuredPaper1.21.8. New SunWearTest2 tests PASS: five rarity intervals, null/unknown/case handling, actual private wear routine boundary using mocked equipment/PDC, normal slot damage invocation and no direct fire/health damage. Whole existing suite76tests51failures; not yet baseline-compared, do NOT claim pre-existing. No game deployment. Candidate /tmp/ticket374-build/DuneRealms-minecraft-only/build/libs/DuneRealms-Core.jar on webhost is build evidence only. Need exposure/water/normalcombat/breakage integration tests, installed backend version check and coordinated backup/deployment acceptance. Originalbrief saysconfigurableintervals, currently fixed defaults; update implementation/brief beforecompletion. Queue selected byOwner despiteLow. No inventory upgrade, sourceSyncedsourcesuntouched.
Direct clear daytime sunlight in the Arrakis world wears each equipped tagged, damageable stillsuit piece independently. Water, shade, night, rain, other worlds, Creative, Spectator and dead players do not accumulate wear. Unbreakable and unrelated equipment are untouched. Per-item exposure counters persist in item metadata and pause outside exposure. A complete stillsuit protects against heatstroke until a piece breaks; protection is checked again after the normal durability operation. Water resets the uninterrupted unarmoured heatstroke timer.
`arrakis-sun.stillsuit-wear-seconds` configures Common/Uncommon/Rare/Epic/Legendary intervals, defaulting to15/30/45/60/90 exposed seconds per one-point normal durability attempt. Unknown quality uses Common. Invalid values are bounded to1..86400 and clamped in rarity order to remain strictly increasing. Existing configurations automatically use the defaults without replacing their other settings.
Paper's `Player.damageItemStack(slot,1)` retains normal Unbreaking, item-damage events and break handling. This code never directly writes an armour damage value. Cosmetic ignition and the old blanket sun-related FIRE_TICK cancellation are removed. Other combat/environment handlers and inventory, trade, progression, jobs and menus are unchanged.
## Actual installed-artifact validation
Live Arrakis runs Paper1.21.8 build60 and Java21 on159.69.82.29. Its Core metadata is1.0.27-layout1-jobs1, despite the legacy DuneCore-1.0.10.jar filename. All five planet copies matched recorded Alpha3 SHA256 cb2f4c21846c88bf0e11d2cf099c849357d4cbffe9b0ceb4e6b4b6c81236561d. The checkpoint source includes other undeployed work, so deploying its entire rebuilt JAR would replace unrelated live functionality.
`tools/PatchSunWear374.java` guards that exact original hash, transplants only solar/wear methods and their supplier lambda, removes the old sun fire-damage handler, adds SunWearPolicy and changes plugin version to1.0.27-layout1-jobs1-sun374. It verifies every unrelated JAR entry and every unrelated Core method remains unchanged. It refuses an unexpected original artifact. Reproduce using Java21 and ASM9.7.1/asm-tree9.7.1 from Gradle8.14.3's lib directory after compiling the candidate source; arguments are original.jar, compiled-main-directory, output.jar.
Six new SunWearTest tests PASS against this actual patched artifact: rarity defaults/config bounds, normal per-slot durability boundary, preservation of unrelated/unbreakable equipment, protection loss in the same tick as a break, and exposure gating across nine environmental/player scenarios. Water resets are covered. These are server-API mocks, not real-player gameplay acceptance.
Full-suite comparison with class isolation (`tools/test-sun-artifact.gradle`) against the original installed artifact:76tests/43failures; patched artifact82tests/the same43failures. No new failures, no missing tests, all six added tests passed. The checkpoint-source baseline separately has76tests/37failures with isolation; without isolation it has51failures due partly to leaking Bukkit static mocks. These unrelated suite failures remain unresolved and are not described as passing validation.
Staged verified patch SHA256 acf870cd2b87540b72dd20fd8a1f888e6957392c2f758247136a8c1b5f845759. Binary output and private credentials are not committed. Runtime rollout must retain backups, stop/save the affected Arrakis backend gracefully, replace only the guarded artifact, restart, and inspect current startup/health logs. No server engine, world or database migration is required. Rollback restores the original JAR; no inventory/schema/world downgrade is involved.

View file

@ -321,7 +321,8 @@ public final class DuneCore extends JavaPlugin implements Listener, CommandExecu
if (!(meta instanceof org.bukkit.inventory.meta.Damageable) || meta.isUnbreakable()) continue;
var data = meta.getPersistentDataContainer();
String quality = data.get(qualityKey, PersistentDataType.STRING);
int interval = SunWearPolicy.interval(quality);
int interval = SunWearPolicy.interval(quality, rarity -> getConfig().getInt(
"arrakis-sun.stillsuit-wear-seconds." + rarity, SunWearPolicy.interval(rarity)));
int elapsed = data.getOrDefault(elapsedKey, PersistentDataType.INTEGER, 0);
boolean damage = elapsed >= interval - 1;
data.set(elapsedKey, PersistentDataType.INTEGER, damage ? 0 : Math.max(0, elapsed) + 1);

View file

@ -1,8 +1,21 @@
package com.example.dunerealms;
import java.util.Locale;
import java.util.function.ToIntFunction;
/** Seconds of clear daylight exposure per point of normal durability damage. */
final class SunWearPolicy {
private SunWearPolicy() {}
static int interval(String quality, ToIntFunction<String> configured) {
String selected = quality == null ? "common" : quality.toLowerCase(Locale.ROOT);
String[] qualities = {"common", "uncommon", "rare", "epic", "legendary"};
int previous = 0, result = 0;
for (int i = 0; i < qualities.length; i++) {
// Keep even malformed settings positive, bounded, and strictly increasing.
int seconds = Math.max(previous + 1, Math.min(86400 - (qualities.length - 1 - i), configured.applyAsInt(qualities[i])));
if (i == 0 || qualities[i].equals(selected)) result = seconds;
previous = seconds;
}
return result;
}
static int interval(String quality) {
return switch (quality == null ? "common" : quality.toLowerCase(Locale.ROOT)) {
case "uncommon" -> 30;

View file

@ -32,6 +32,14 @@ arrakis-sun:
enabled: true
lethal-seconds: 300
warning-interval-seconds: 30
# Exposed seconds per normal durability damage attempt, per equipped piece.
# Invalid values are bounded to 1..86400 and made strictly increasing by rarity.
stillsuit-wear-seconds:
common: 15
uncommon: 30
rare: 45
epic: 60
legendary: 90
# One Paper backend per planet, connected through Velocity's BungeeCord plugin messaging support.
network:

View file

@ -10,10 +10,21 @@ import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
import static org.mockito.ArgumentMatchers.*;
class SunWearTest {
@Test void configuredIntervalsStayBoundedAndOrdered() {
assertEquals(120, SunWearPolicy.interval("rare", q -> switch(q) {case "common" -> 40;case "uncommon" -> 80;default -> 120;}));
int previous=0;
for(String q:new String[]{"common","uncommon","rare","epic","legendary"}) {
int value=SunWearPolicy.interval(q, ignored -> Integer.MAX_VALUE);
assertTrue(value>previous && value<=86400);previous=value;
}
assertEquals(1,SunWearPolicy.interval("unknown", ignored -> -99));
assertEquals(5,SunWearPolicy.interval("legendary", ignored -> -99));
}
@Test void rarityIntervalsIncreaseAndUnknownIsCommon(){int previous=0;for(String quality:new String[]{"common","uncommon","rare","epic","legendary"}){int interval=SunWearPolicy.interval(quality);assertTrue(interval>previous);previous=interval;}assertEquals(15,SunWearPolicy.interval(null));assertEquals(15,SunWearPolicy.interval("invalid"));assertEquals(90,SunWearPolicy.interval("LEGENDARY"));}
@Test void actualWearUsesNormalSlotDamageAtBoundaryAndPreservesUnrelatedItems() throws Exception {
for(int elapsed:new int[]{13,14}){
DuneCore core=mock(DuneCore.class,CALLS_REAL_METHODS);Field key=DuneCore.class.getDeclaredField("itemKey");key.setAccessible(true);key.set(core,new NamespacedKey("test","item"));
var config=mock(org.bukkit.configuration.file.FileConfiguration.class);doReturn(config).when(core).getConfig();when(config.getInt(anyString(),anyInt())).thenAnswer(invocation -> invocation.getArgument(1));
Player player=mock(Player.class);PlayerInventory inventory=mock(PlayerInventory.class);when(player.getInventory()).thenReturn(inventory);
ItemStack helmet=mock(ItemStack.class);Damageable meta=mock(Damageable.class);PersistentDataContainer data=mock(PersistentDataContainer.class);when(inventory.getItem(EquipmentSlot.HEAD)).thenReturn(helmet);when(helmet.hasItemMeta()).thenReturn(true);when(helmet.getItemMeta()).thenReturn(meta);when(meta.getPersistentDataContainer()).thenReturn(data);when(data.get(new NamespacedKey("test","item"),PersistentDataType.STRING)).thenReturn("stillsuit");when(data.getOrDefault(new NamespacedKey("dunerealms","sun_wear_seconds"),PersistentDataType.INTEGER,0)).thenReturn(elapsed);
Method wear=DuneCore.class.getDeclaredMethod("wearSunExposedStillsuit",Player.class);wear.setAccessible(true);wear.invoke(core,player);
@ -22,13 +33,40 @@ class SunWearTest {
}
}
@Test void actualExposureLoopResetsInWaterShadeNightAndOtherWorld() throws Exception {
for(int scenario=0;scenario<5;scenario++){
for(int scenario=0;scenario<9;scenario++){
DuneCore core=mock(DuneCore.class,CALLS_REAL_METHODS);Player player=mock(Player.class);org.bukkit.World world=mock(org.bukkit.World.class);org.bukkit.Location location=mock(org.bukkit.Location.class);PlayerInventory inventory=mock(PlayerInventory.class);org.bukkit.configuration.file.FileConfiguration config=mock(org.bukkit.configuration.file.FileConfiguration.class);
doReturn(config).when(core).getConfig();when(config.getBoolean("arrakis-sun.enabled",true)).thenReturn(true);when(config.getInt("arrakis-sun.lethal-seconds",300)).thenReturn(300);when(config.getInt("arrakis-sun.warning-interval-seconds",30)).thenReturn(30);
java.util.UUID id=java.util.UUID.randomUUID();when(player.getUniqueId()).thenReturn(id);when(player.getWorld()).thenReturn(world);when(player.getInventory()).thenReturn(inventory);when(inventory.getArmorContents()).thenReturn(new ItemStack[]{null,null,null,null});when(player.getLocation()).thenReturn(location);when(location.getBlockY()).thenReturn(64);when(world.getName()).thenReturn(scenario==4?"caladan":"arrakis");when(world.isClearWeather()).thenReturn(true);when(world.getTime()).thenReturn(scenario==3?13000L:1000L);when(world.getHighestBlockYAt(location)).thenReturn(scenario==2?70:64);when(player.isInWater()).thenReturn(scenario==1);when(player.getGameMode()).thenReturn(org.bukkit.GameMode.SURVIVAL);
java.util.UUID id=java.util.UUID.randomUUID();when(player.getUniqueId()).thenReturn(id);when(player.getWorld()).thenReturn(world);when(player.getInventory()).thenReturn(inventory);when(inventory.getArmorContents()).thenReturn(new ItemStack[]{null,null,null,null});when(player.getLocation()).thenReturn(location);when(location.getBlockY()).thenReturn(64);when(world.getName()).thenReturn(scenario==4?"caladan":"arrakis");when(world.isClearWeather()).thenReturn(scenario!=5);when(player.isDead()).thenReturn(scenario==6);when(world.getTime()).thenReturn(scenario==3?13000L:1000L);when(world.getHighestBlockYAt(location)).thenReturn(scenario==2?70:64);when(player.isInWater()).thenReturn(scenario==1);when(player.getGameMode()).thenReturn(scenario==7?org.bukkit.GameMode.CREATIVE:scenario==8?org.bukkit.GameMode.SPECTATOR:org.bukkit.GameMode.SURVIVAL);
java.util.Map<java.util.UUID,Integer> exposure=new java.util.HashMap<>();exposure.put(id,10);Field f=DuneCore.class.getDeclaredField("sunExposureSeconds");f.setAccessible(true);f.set(core,exposure);
try(var bukkit=mockStatic(org.bukkit.Bukkit.class)){bukkit.when(org.bukkit.Bukkit::getOnlinePlayers).thenReturn(java.util.List.of(player));Method check=DuneCore.class.getDeclaredMethod("checkArrakisSun");check.setAccessible(true);check.invoke(core);}
if(scenario==0)assertEquals(11,exposure.get(id));else assertFalse(exposure.containsKey(id));verify(player,never()).setFireTicks(anyInt());
}
}
@Test void unbreakableAndUnrelatedEquipmentAreNeverDamaged() throws Exception {
DuneCore core=mock(DuneCore.class,CALLS_REAL_METHODS);Field key=DuneCore.class.getDeclaredField("itemKey");key.setAccessible(true);key.set(core,new NamespacedKey("test","item"));
Player player=mock(Player.class);PlayerInventory inventory=mock(PlayerInventory.class);when(player.getInventory()).thenReturn(inventory);
for(var slot:new EquipmentSlot[]{EquipmentSlot.HEAD,EquipmentSlot.CHEST}) {
ItemStack item=mock(ItemStack.class);Damageable meta=mock(Damageable.class);PersistentDataContainer data=mock(PersistentDataContainer.class);
when(inventory.getItem(slot)).thenReturn(item);when(item.hasItemMeta()).thenReturn(true);when(item.getItemMeta()).thenReturn(meta);when(meta.getPersistentDataContainer()).thenReturn(data);
when(data.get(new NamespacedKey("test","item"),PersistentDataType.STRING)).thenReturn(slot==EquipmentSlot.HEAD?"stillsuit":"ordinary_helmet");when(meta.isUnbreakable()).thenReturn(true);
verify(item,never()).setItemMeta(any());
}
Method wear=DuneCore.class.getDeclaredMethod("wearSunExposedStillsuit",Player.class);wear.setAccessible(true);wear.invoke(core,player);
verify(player,never()).damageItemStack(any(EquipmentSlot.class),anyInt());verify(core,never()).getConfig();
}
@Test void brokenPieceLosesFullSuitProtectionInSameExposureTick() throws Exception {
DuneCore core=mock(DuneCore.class,CALLS_REAL_METHODS);Field key=DuneCore.class.getDeclaredField("itemKey");key.setAccessible(true);NamespacedKey tag=new NamespacedKey("test","item");key.set(core,tag);
var config=mock(org.bukkit.configuration.file.FileConfiguration.class);doReturn(config).when(core).getConfig();when(config.getBoolean("arrakis-sun.enabled",true)).thenReturn(true);when(config.getInt(anyString(),anyInt())).thenAnswer(i->i.getArgument(1));
Player player=mock(Player.class);PlayerInventory inventory=mock(PlayerInventory.class);when(player.getInventory()).thenReturn(inventory);var world=mock(org.bukkit.World.class);var location=mock(org.bukkit.Location.class);when(player.getWorld()).thenReturn(world);when(player.getLocation()).thenReturn(location);when(world.getName()).thenReturn("arrakis");when(world.isClearWeather()).thenReturn(true);when(world.getTime()).thenReturn(1000L);when(player.getGameMode()).thenReturn(org.bukkit.GameMode.SURVIVAL);
java.util.UUID id=java.util.UUID.randomUUID();when(player.getUniqueId()).thenReturn(id);java.util.Map<java.util.UUID,Integer> exposure=new java.util.HashMap<>();Field field=DuneCore.class.getDeclaredField("sunExposureSeconds");field.setAccessible(true);field.set(core,exposure);
ItemStack[] equipped=new ItemStack[4];var slots=new EquipmentSlot[]{EquipmentSlot.HEAD,EquipmentSlot.CHEST,EquipmentSlot.LEGS,EquipmentSlot.FEET};
for(int n=0;n<4;n++) {
ItemStack item=mock(ItemStack.class);Damageable meta=mock(Damageable.class);PersistentDataContainer data=mock(PersistentDataContainer.class);equipped[n]=item;
when(inventory.getItem(slots[n])).thenReturn(item);when(item.hasItemMeta()).thenReturn(true);when(item.getItemMeta()).thenReturn(meta);when(meta.getPersistentDataContainer()).thenReturn(data);when(data.get(tag,PersistentDataType.STRING)).thenReturn("stillsuit");when(data.getOrDefault(new NamespacedKey("dunerealms","sun_wear_seconds"),PersistentDataType.INTEGER,0)).thenReturn(14);
}
when(inventory.getArmorContents()).thenAnswer(i->equipped.clone());
doAnswer(i->{equipped[0]=null;return null;}).when(player).damageItemStack(EquipmentSlot.HEAD,1);
try(var bukkit=mockStatic(org.bukkit.Bukkit.class)) {bukkit.when(org.bukkit.Bukkit::getOnlinePlayers).thenReturn(java.util.List.of(player));Method check=DuneCore.class.getDeclaredMethod("checkArrakisSun");check.setAccessible(true);check.invoke(core);}
assertEquals(1,exposure.get(id));for(var slot:slots)verify(player).damageItemStack(slot,1);verify(player,never()).setHealth(anyDouble());
}
}

View file

@ -0,0 +1,60 @@
import java.nio.file.*;
import java.util.*;
import java.util.jar.*;
import org.objectweb.asm.*;
import org.objectweb.asm.tree.*;
/** Overlay only ticket374 methods onto the exact installed Core artifact.
* Usage: original.jar compiled-main-directory output.jar
* Refuses any original other than the recorded Alpha3 release. */
public final class PatchSunWear374 {
public static void main(String[] args) throws Exception {
Path original=Path.of(args[0]), classes=Path.of(args[1]), output=Path.of(args[2]);
String hash=HexFormat.of().formatHex(java.security.MessageDigest.getInstance("SHA-256").digest(Files.readAllBytes(original)));
if(!hash.equals("cb2f4c21846c88bf0e11d2cf099c849357d4cbffe9b0ceb4e6b4b6c81236561d")) throw new IllegalStateException("Unexpected installed Core: "+hash);
String entry="com/example/dunerealms/DuneCore.class";
try(JarFile jar=new JarFile(original.toFile())) {
ClassNode live=new ClassNode(), candidate=new ClassNode();
new ClassReader(jar.getInputStream(jar.getJarEntry(entry))).accept(live,0);
new ClassReader(Files.readAllBytes(classes.resolve(entry))).accept(candidate,0);
if(live.fields.stream().noneMatch(f->f.name.equals("sunExposureSeconds")&&f.desc.equals("Ljava/util/Map;"))) throw new IllegalStateException("Exposure state missing");
Set<String> replace=new HashSet<>(List.of("checkArrakisSun","wearSunExposedStillsuit"));
candidate.methods.stream().filter(m->m.name.startsWith("lambda$wearSunExposedStillsuit$")).forEach(m->replace.add(m.name));
if(candidate.methods.stream().filter(m->replace.contains(m.name)).count()!=replace.size()) throw new IllegalStateException("Candidate methods missing");
if(live.methods.stream().noneMatch(m->m.name.equals("checkArrakisSun"))||live.methods.stream().noneMatch(m->m.name.equals("onSunDamage"))) throw new IllegalStateException("Unexpected live solar implementation");
live.methods.removeIf(m->replace.contains(m.name)||m.name.equals("onSunDamage"));
candidate.methods.stream().filter(m->replace.contains(m.name)).forEach(live.methods::add);
ClassWriter writer=new ClassWriter(0);live.accept(writer);
try(JarOutputStream out=new JarOutputStream(Files.newOutputStream(output))) {
Enumeration<JarEntry> entries=jar.entries();
while(entries.hasMoreElements()) {
JarEntry e=entries.nextElement();out.putNextEntry(new JarEntry(e.getName()));
byte[] bytes=jar.getInputStream(e).readAllBytes();
if(e.getName().equals(entry)) bytes=writer.toByteArray();
if(e.getName().equals("plugin.yml")) bytes=new String(bytes,java.nio.charset.StandardCharsets.UTF_8).replace("version: 1.0.27-layout1-jobs1","version: 1.0.27-layout1-jobs1-sun374").getBytes(java.nio.charset.StandardCharsets.UTF_8);
out.write(bytes);out.closeEntry();
}
String policy="com/example/dunerealms/SunWearPolicy.class";
if(jar.getJarEntry(policy)!=null) throw new IllegalStateException("Policy already installed");
out.putNextEntry(new JarEntry(policy));out.write(Files.readAllBytes(classes.resolve(policy)));out.closeEntry();
}
try(JarFile patched=new JarFile(output.toFile())) {
for(JarEntry e:Collections.list(jar.entries())) {
if(!e.getName().equals(entry)&&!e.getName().equals("plugin.yml")&&
!Arrays.equals(jar.getInputStream(e).readAllBytes(),patched.getInputStream(patched.getJarEntry(e.getName())).readAllBytes()))
throw new IllegalStateException("Unrelated entry changed: "+e.getName());
}
ClassNode verified=new ClassNode();new ClassReader(patched.getInputStream(patched.getJarEntry(entry))).accept(verified,0);
for(MethodNode method:live.methods) {
if(replace.contains(method.name)) continue;
MethodNode actual=verified.methods.stream().filter(m->m.name.equals(method.name)&&m.desc.equals(method.desc)).findFirst().orElseThrow();
if(!Arrays.equals(methodBytes(method),methodBytes(actual))) throw new IllegalStateException("Unrelated method changed: "+method.name);
}
}
System.out.println("Verified: only solar methods, new policy class and plugin version changed; all unrelated archive entries and methods preserved.");
}
}
private static byte[] methodBytes(MethodNode method) {
ClassWriter writer=new ClassWriter(0);writer.visit(Opcodes.V21,Opcodes.ACC_PUBLIC,"MethodCheck",null,"java/lang/Object",null);method.accept(writer);writer.visitEnd();return writer.toByteArray();
}
}

View file

@ -0,0 +1,16 @@
// Run the repository tests against the actual patched installed artifact.
// gradle -I ../tools/test-sun-artifact.gradle -PsunArtifact=/path/Core.jar test
allprojects {
afterEvaluate {
// Existing test classes leak Bukkit static mocks when their setup fails.
// Isolate classes for a meaningful baseline/candidate comparison.
if (plugins.hasPlugin('java')) tasks.named('test') { forkEvery = 1 }
if (plugins.hasPlugin('java') && project.hasProperty('sunBaseline')) tasks.named('test') { exclude '**/SunWearTest*' }
if (plugins.hasPlugin('java') && project.hasProperty('sunArtifact')) {
tasks.named('test') {
classpath = sourceSets.test.output + files(project.property('sunArtifact')) +
(sourceSets.test.runtimeClasspath - sourceSets.main.output)
}
}
}
}