mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 22:27:32 +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
@@ -1,26 +1,14 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import noppes.npcs.config.ConfigScript;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class RecipeScript implements IScriptHandler {
|
||||
public IScriptUnit container;
|
||||
public String scriptLanguage = "ECMAScript";
|
||||
public boolean enabled = false;
|
||||
public class RecipeScript extends ScriptHandler {
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
||||
compound.setString("ScriptLanguage", scriptLanguage);
|
||||
@@ -39,90 +27,11 @@ public class RecipeScript implements IScriptHandler {
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled && ScriptController.HasStart && container != null && ConfigScript.ScriptingEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callScript(EnumScriptType type, Event event) {
|
||||
this.callScript(type.function, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callScript(String s, Event event) {
|
||||
if (!this.isEnabled())
|
||||
return;
|
||||
if (container != null) {
|
||||
container.run(s, event);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClient() {
|
||||
return FMLCommonHandler.instance().getEffectiveSide().isClient();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean b) {
|
||||
this.enabled = b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLanguage() {
|
||||
return this.scriptLanguage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLanguage(String s) {
|
||||
this.scriptLanguage = s;
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String noticeString() {
|
||||
return "RecipeScript";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, String> getConsoleText() {
|
||||
TreeMap<Long, String> map = new TreeMap<>();
|
||||
int tab = 0;
|
||||
for (IScriptUnit script : this.getScripts()) {
|
||||
++tab;
|
||||
for (Map.Entry<Long, String> entry : script.getConsole().entrySet()) {
|
||||
map.put(entry.getKey(), " tab " + tab + ":\n" + entry.getValue());
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearConsole() {
|
||||
for (IScriptUnit script : this.getScripts()) {
|
||||
script.clearConsole();
|
||||
}
|
||||
}
|
||||
|
||||
public void saveScript(ByteBuf buffer) throws IOException {
|
||||
int tab = buffer.readInt();
|
||||
int totalScripts = buffer.readInt();
|
||||
|
||||
Reference in new issue
Block a user