mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 15:45:10 +00:00
New ScriptHandler, which is an abstract IScriptHandler implementation
This commit is contained in:
1 parent
cda43fe67a
commit
f829926f00
4 files changed
+67
-253
No files matched your search
@@ -0,0 +1,64 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import noppes.npcs.config.ConfigScript;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class ScriptHandler implements IScriptHandler {
|
||||
public IScriptUnit container;
|
||||
protected String scriptLanguage = "ECMAScript";
|
||||
protected boolean enabled = false;
|
||||
|
||||
protected boolean canRunScripts() {
|
||||
return enabled && ScriptController.HasStart && ConfigScript.ScriptingEnabled && container != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callScript(String hookName, Event event) {
|
||||
if (!canRunScripts()) {
|
||||
return;
|
||||
}
|
||||
container.run(hookName, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLanguage() {
|
||||
return scriptLanguage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLanguage(String language) {
|
||||
this.scriptLanguage = language;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScripts(List<IScriptUnit> list) {
|
||||
if (list == null || list.isEmpty()) {
|
||||
container = null;
|
||||
return;
|
||||
}
|
||||
container = list.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IScriptUnit> getScripts() {
|
||||
if (container == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return Collections.singletonList(container);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user