web/tools/probes/QuestRoleProbe.java
2026-11-27 23:43:05 +00:00

6 lines
2 KiB
Java

package com.dunerealms.gui;
import org.bukkit.*;import org.bukkit.entity.*;import org.bukkit.plugin.java.JavaPlugin;import org.bukkit.persistence.PersistentDataType;import java.util.*;
public final class QuestRoleProbe extends JavaPlugin{
public void onEnable(){Bukkit.getScheduler().runTaskLater(this,()->{try{World w=Bukkit.getWorlds().getFirst();getLogger().info("Probe world "+w.getName());if(!w.getName().equals("arrakis"))throw new AssertionError("Unexpected isolated world name "+w.getName());Location spawn=w.getSpawnLocation();spawn.setY(w.getHighestBlockYAt(spawn)+1);w.setSpawnLocation(spawn);var roles=new PolQuestNpc(this,(p,r)->{});var ensure=PolQuestNpc.class.getDeclaredMethod("ensure",World.class);ensure.setAccessible(true);ensure.invoke(roles,w);var expected=Set.of("stilgar","shadout_mapes","chani","liet_kynes","alia_atreides","esmar_tuek");Map<String,UUID> ids=new HashMap<>();for(var e:w.getEntitiesByClass(LivingEntity.class)){String key=e.getPersistentDataContainer().get(PolQuestNpc.KEY,PersistentDataType.STRING);if(key!=null){if(ids.put(key,e.getUniqueId())!=null)throw new AssertionError("Duplicate NPC "+key);if(!e.isPersistent()||!e.isInvulnerable())throw new AssertionError("Unprotected NPC "+key);}}
if(!ids.keySet().equals(expected))throw new AssertionError("Incorrect NPC roles "+ids.keySet());var next=new PolQuestNpc(this,(p,r)->{});ensure.invoke(next,w);Map<String,UUID> after=new HashMap<>();for(var e:w.getEntitiesByClass(LivingEntity.class)){String key=e.getPersistentDataContainer().get(PolQuestNpc.KEY,PersistentDataType.STRING);if(key!=null&&after.put(key,e.getUniqueId())!=null)throw new AssertionError("Duplicate subsequent NPC "+key);}if(!ids.equals(after))throw new AssertionError("Stationary identities changed");getLogger().info("QUEST_ROLE_PROBE_PASS six stationary named NPCs, preserved IDs on reloading positions");}catch(Throwable failure){getLogger().severe("QUEST_ROLE_PROBE_FAIL "+failure);failure.printStackTrace();}finally{Bukkit.shutdown();}},80L);}
}