mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 20:07:32 +00:00
Made ScriptContext class based instead
This commit is contained in:
1 parent
576401ebde
commit
5b36cdac1b
1 file changed
+34
-14
@@ -1,5 +1,7 @@
|
||||
package noppes.npcs.constants;
|
||||
|
||||
import noppes.npcs.api.event.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@@ -30,35 +32,34 @@ public class ScriptContext {
|
||||
// ==================== BUILT-IN CONTEXTS ====================
|
||||
|
||||
public static final ScriptContext NPC = register("NPC",
|
||||
"INpcEvent",
|
||||
"IProjectileEvent"
|
||||
INpcEvent.class,
|
||||
IProjectileEvent.class
|
||||
);
|
||||
|
||||
public static final ScriptContext PLAYER = register("PLAYER",
|
||||
"IPlayerEvent",
|
||||
"IAnimationEvent",
|
||||
"IPartyEvent",
|
||||
"IDialogEvent",
|
||||
"IQuestEvent",
|
||||
"IFactionEvent",
|
||||
"ICustomGuiEvent",
|
||||
"IEffectEvent"
|
||||
IPlayerEvent.class,
|
||||
IAnimationEvent.class,
|
||||
IPartyEvent.class,
|
||||
IDialogEvent.class,
|
||||
IQuestEvent.class,
|
||||
IFactionEvent.class,
|
||||
ICustomGuiEvent.class
|
||||
);
|
||||
|
||||
public static final ScriptContext BLOCK = register("BLOCK",
|
||||
"IBlockEvent"
|
||||
IBlockEvent.class
|
||||
);
|
||||
|
||||
public static final ScriptContext ITEM = register("ITEM",
|
||||
"IItemEvent"
|
||||
IItemEvent.class
|
||||
);
|
||||
|
||||
public static final ScriptContext FORGE = register("FORGE",
|
||||
"IForgeEvent"
|
||||
IForgeEvent.class
|
||||
);
|
||||
|
||||
public static final ScriptContext GLOBAL = register("GLOBAL",
|
||||
"Global"
|
||||
"Global" // Special case: Global namespace doesn't have a corresponding event class
|
||||
);
|
||||
|
||||
// ==================== INSTANCE FIELDS ====================
|
||||
@@ -134,6 +135,25 @@ public class ScriptContext {
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new script context using event interface classes.
|
||||
* Automatically extracts the simple name from each class.
|
||||
*
|
||||
* Example:
|
||||
* ScriptContext.register("NPC", INpcEvent.class, IProjectileEvent.class);
|
||||
*
|
||||
* @param id Unique identifier (e.g., "DBC", "CUSTOM")
|
||||
* @param eventClasses The event interface classes (simple names will be extracted)
|
||||
* @return The registered ScriptContext
|
||||
*/
|
||||
public static ScriptContext register(String id, Class<?>... eventClasses) {
|
||||
String[] namespaces = new String[eventClasses.length];
|
||||
for (int i = 0; i < eventClasses.length; i++) {
|
||||
namespaces[i] = eventClasses[i].getSimpleName();
|
||||
}
|
||||
return register(id, namespaces);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a script context by its ID.
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user