mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 06:25:11 +00:00
Large Cleanup to Code Imports and Formatting
This commit is contained in:
1 parent
31aac0d6b3
commit
a9b602713c
155 files changed
+4089
-2194
No files matched your search
@@ -6,7 +6,6 @@ import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
@@ -15,24 +14,24 @@ import java.util.TreeMap;
|
||||
* This allows GuiScriptInterface to work with both script types uniformly.
|
||||
*/
|
||||
public interface IScriptUnit {
|
||||
|
||||
|
||||
// NBT type identifiers
|
||||
String NBT_TYPE_KEY = "ScriptUnitType";
|
||||
String TYPE_ECMASCRIPT = "ECMAScript";
|
||||
String TYPE_JANINO = "Janino";
|
||||
|
||||
|
||||
/**
|
||||
* Create an IScriptUnit from NBT data.
|
||||
* Uses the "ScriptUnitType" tag to determine which implementation to create.
|
||||
*
|
||||
*
|
||||
* @param compound The NBT data
|
||||
* @param handler The script handler (used for ScriptContainer)
|
||||
* @param handler The script handler (used for ScriptContainer)
|
||||
* @return A ScriptContainer or JaninoScript based on the NBT type
|
||||
*/
|
||||
static IScriptUnit createFromNBT(NBTTagCompound compound, IScriptHandler handler) {
|
||||
String type = compound.getString(NBT_TYPE_KEY);
|
||||
IScriptUnit unit;
|
||||
|
||||
|
||||
if (TYPE_JANINO.equals(type)) {
|
||||
// Create appropriate JaninoScript based on handler
|
||||
unit = handler.createJaninoScriptUnit();
|
||||
@@ -44,96 +43,97 @@ public interface IScriptUnit {
|
||||
// Default to ScriptContainer for ECMAScript or missing type
|
||||
unit = new ScriptContainer(handler);
|
||||
}
|
||||
|
||||
|
||||
unit.readFromNBT(compound);
|
||||
return unit;
|
||||
}
|
||||
|
||||
|
||||
// ==================== SCRIPT CONTENT ====================
|
||||
|
||||
|
||||
/**
|
||||
* Get the main script text content.
|
||||
*/
|
||||
String getScript();
|
||||
|
||||
|
||||
/**
|
||||
* Set the main script text content.
|
||||
*/
|
||||
void setScript(String script);
|
||||
|
||||
|
||||
/**
|
||||
* Get the list of external script file names loaded for this unit.
|
||||
*/
|
||||
List<String> getExternalScripts();
|
||||
|
||||
|
||||
/**
|
||||
* Set the list of external script file names to load.
|
||||
*/
|
||||
void setExternalScripts(List<String> scripts);
|
||||
|
||||
|
||||
// ==================== CONSOLE ====================
|
||||
|
||||
|
||||
/**
|
||||
* Get the console output map (timestamp -> message).
|
||||
*/
|
||||
TreeMap<Long, String> getConsole();
|
||||
|
||||
|
||||
/**
|
||||
* Clear all console output.
|
||||
*/
|
||||
void clearConsole();
|
||||
|
||||
|
||||
/**
|
||||
* Append a message to the console.
|
||||
*/
|
||||
void appendConsole(String message);
|
||||
|
||||
|
||||
// ==================== LANGUAGE ====================
|
||||
|
||||
|
||||
/**
|
||||
* Get the scripting language for this unit.
|
||||
* Returns "ECMAScript", "Java", etc.
|
||||
*/
|
||||
String getLanguage();
|
||||
|
||||
|
||||
/**
|
||||
* Set the scripting language for this unit.
|
||||
*
|
||||
* @param language The language name (e.g., "ECMAScript", "Java")
|
||||
*/
|
||||
void setLanguage(String language);
|
||||
|
||||
|
||||
/**
|
||||
* Check if this script unit uses Janino (Java) compilation.
|
||||
*/
|
||||
default boolean isJanino() {
|
||||
return "Java".equals(getLanguage());
|
||||
}
|
||||
|
||||
|
||||
// ==================== HOOK GENERATION ====================
|
||||
|
||||
|
||||
/**
|
||||
* Generate a stub/template for the given hook name.
|
||||
* ECMAScript: function hookName(event) { }
|
||||
* Janino: full Java method signature with return type
|
||||
*
|
||||
*
|
||||
* @param hookName The hook name to generate a stub for
|
||||
* @param hookData Optional data (e.g., Method object for Janino)
|
||||
* @return The generated stub string
|
||||
*/
|
||||
String generateHookStub(String hookName, Object hookData);
|
||||
|
||||
|
||||
// ==================== NBT ====================
|
||||
|
||||
|
||||
/**
|
||||
* Write this script unit to NBT.
|
||||
*/
|
||||
NBTTagCompound writeToNBT(NBTTagCompound compound);
|
||||
|
||||
|
||||
/**
|
||||
* Read this script unit from NBT.
|
||||
*/
|
||||
void readFromNBT(NBTTagCompound compound);
|
||||
|
||||
|
||||
// ==================== STATE ====================
|
||||
|
||||
/**
|
||||
@@ -141,43 +141,43 @@ public interface IScriptUnit {
|
||||
* No-op for ScriptContainer.
|
||||
*/
|
||||
void ensureCompiled();
|
||||
|
||||
|
||||
/**
|
||||
* Check if this script unit has any code (script or external scripts).
|
||||
*/
|
||||
boolean hasCode();
|
||||
|
||||
|
||||
/**
|
||||
* Check if this script unit has encountered an error during execution.
|
||||
*/
|
||||
boolean hasErrored();
|
||||
|
||||
|
||||
/**
|
||||
* Set the error state of this script unit.
|
||||
*/
|
||||
void setErrored(boolean errored);
|
||||
|
||||
|
||||
// ==================== EXECUTION ====================
|
||||
|
||||
|
||||
/**
|
||||
* Execute this script unit for the given hook type and event.
|
||||
*
|
||||
* @param type The script hook type
|
||||
*
|
||||
* @param type The script hook type
|
||||
* @param event The event object
|
||||
*/
|
||||
void run(EnumScriptType type, Event event);
|
||||
|
||||
|
||||
/**
|
||||
* Execute this script unit for the given hook name and event.
|
||||
*
|
||||
* @param hookName The hook name (e.g., "init", "interact")
|
||||
* @param event The event object
|
||||
* @param event The event object
|
||||
*/
|
||||
void run(String hookName, Object event);
|
||||
|
||||
/**
|
||||
* Call a script function by name and return its result.
|
||||
*
|
||||
* <p>
|
||||
* Default implementation returns null (not supported).
|
||||
*/
|
||||
default Object callFunction(String hookName, Object... args) {
|
||||
|
||||
Reference in new issue
Block a user