web/DuneRealmsGUI/src/main/java/com/dunerealms/gui/DragonController.java
2026-11-21 20:22:37 +01:00

14 lines
812 B
Java

package com.dunerealms.gui;
import java.lang.reflect.Field;
/** Detach only the lobby's vanilla End fight, without killing entities or editing NBT. */
final class DragonController {
record Detached(Object handle,Field field,Object previous){
void restore() throws IllegalAccessException {if(field.get(handle)==null)field.set(handle,previous);}
}
static Detached detach(Object handle)throws ReflectiveOperationException {
for(Class<?> type=handle.getClass();type!=null;type=type.getSuperclass())for(Field field:type.getDeclaredFields())if(field.getType().getSimpleName().equals("EndDragonFight")){
field.setAccessible(true);Object previous=field.get(handle);field.set(handle,null);return new Detached(handle,field,previous);
}
throw new NoSuchFieldException("Lobby EndDragonFight controller");
}
}