Test actual sun exposure reset in water, shade, night and other worlds

This commit is contained in:
Dev 2026-11-05 21:01:05 +01:00
commit 2c01dd709b

View file

@ -21,4 +21,14 @@ class SunWearTest {
verify(player,never()).setFireTicks(anyInt());verify(player,never()).damage(anyDouble());
}
}
@Test void actualExposureLoopResetsInWaterShadeNightAndOtherWorld() throws Exception {
for(int scenario=0;scenario<5;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.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());
}
}
}