mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-18 01:05:12 +00:00
Made a new interface for CNPC+ script handlers and changed callScript functions to make them more 3rd party API-friendly
This commit is contained in:
1 parent
d433eccef1
commit
3b0879b0db
8 files changed
+59
-25
No files matched your search
@@ -23,7 +23,7 @@ import java.lang.reflect.Array;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class PlayerDataScript implements IScriptHandler {
|
||||
public class PlayerDataScript implements INpcScriptHandler {
|
||||
public List<ScriptContainer> scripts = new ArrayList();
|
||||
public String scriptLanguage = "ECMAScript";
|
||||
private EntityPlayer player;
|
||||
@@ -66,7 +66,16 @@ public class PlayerDataScript implements IScriptHandler {
|
||||
return compound;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return ConfigScript.GlobalPlayerScripts && ScriptController.Instance.playerScripts.enabled && ScriptController.HasStart && (this.player == null || !this.player.worldObj.isRemote);
|
||||
}
|
||||
|
||||
public void callScript(EnumScriptType type, Event event) {
|
||||
this.callScript(type.function, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callScript(String hookName, Event event) {
|
||||
if (this.isEnabled()) {
|
||||
if (ScriptController.Instance.lastLoaded > this.lastInited || ScriptController.Instance.lastPlayerUpdate > this.lastPlayerUpdate) {
|
||||
this.lastInited = ScriptController.Instance.lastLoaded;
|
||||
@@ -76,7 +85,7 @@ public class PlayerDataScript implements IScriptHandler {
|
||||
scriptContainer.errored = false;
|
||||
}
|
||||
|
||||
if (type != EnumScriptType.INIT) {
|
||||
if (!Objects.equals(hookName, EnumScriptType.INIT.function)) {
|
||||
noppes.npcs.scripted.event.PlayerEvent playerEvent = (noppes.npcs.scripted.event.PlayerEvent)event;
|
||||
EventHooks.onPlayerInit(this, playerEvent.player);
|
||||
}
|
||||
@@ -86,14 +95,11 @@ public class PlayerDataScript implements IScriptHandler {
|
||||
if(script == null || script.errored || !script.hasCode() )
|
||||
continue;
|
||||
|
||||
script.run(type, event);
|
||||
script.run(hookName, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return ConfigScript.GlobalPlayerScripts && ScriptController.Instance.playerScripts.enabled && ScriptController.HasStart && (this.player == null || !this.player.worldObj.isRemote);
|
||||
}
|
||||
public boolean isClient() {
|
||||
return this.player.isClientWorld();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user