mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 17:47:32 +00:00
Defaulted IScriptHandler methods to clean up duplicate code across implementations
This commit is contained in:
1 parent
68bc02a5d4
commit
cda43fe67a
6 files changed
+39
-124
No files matched your search
@@ -416,26 +416,7 @@ public class TileScripted extends TileEntity implements IScriptBlockHandler {
|
||||
public List<IScriptUnit> getScripts() {
|
||||
return scripts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, String> getConsoleText() {
|
||||
Map<Long, String> map = new TreeMap<>();
|
||||
int tab = 0;
|
||||
for (IScriptUnit script : getScripts()) {
|
||||
tab++;
|
||||
for (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 : getScripts()) {
|
||||
script.clearConsole();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
|
||||
@@ -5,15 +5,11 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.NBTTags;
|
||||
import noppes.npcs.config.ConfigScript;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class ForgeDataScript implements IScriptHandler {
|
||||
private List<IScriptUnit> scripts = new ArrayList<>();
|
||||
@@ -56,10 +52,6 @@ public class ForgeDataScript implements IScriptHandler {
|
||||
return compound;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callScript(EnumScriptType var1, Event var2) {
|
||||
this.callScript(var1.function, var2);
|
||||
}
|
||||
|
||||
public void callScript(String type, Event event) {
|
||||
if (this.isEnabled()) {
|
||||
@@ -117,25 +109,5 @@ public class ForgeDataScript implements IScriptHandler {
|
||||
return this.scripts;
|
||||
}
|
||||
|
||||
public String noticeString() {
|
||||
return "ForgeScript";
|
||||
}
|
||||
|
||||
public Map<Long, String> getConsoleText() {
|
||||
TreeMap<Long, String> map = new TreeMap<>();
|
||||
int tab = 0;
|
||||
for (IScriptUnit script : this.getScripts()) {
|
||||
++tab;
|
||||
for (Entry<Long, String> entry : script.getConsole().entrySet()) {
|
||||
map.put(entry.getKey(), " tab " + tab + ":\n" + entry.getValue());
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public void clearConsole() {
|
||||
for (IScriptUnit script : this.getScripts()) {
|
||||
script.clearConsole();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import net.minecraft.util.math.BlockPos;
|
||||
import noppes.npcs.NBTTags;
|
||||
import noppes.npcs.api.entity.ICustomNpc;
|
||||
import noppes.npcs.config.ConfigScript;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
@@ -76,9 +75,6 @@ public class GlobalNPCDataScript implements IScriptHandler {
|
||||
return ConfigScript.GlobalNPCScripts && this.enabled && ScriptController.HasStart && this.scripts.size() > 0;
|
||||
}
|
||||
|
||||
public void callScript(EnumScriptType type, Event event) {
|
||||
this.callScript(type.function, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callScript(String hookName, Event event) {
|
||||
@@ -145,23 +141,6 @@ public class GlobalNPCDataScript implements IScriptHandler {
|
||||
return this.npcAPI;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public void clearConsole() {
|
||||
for (IScriptUnit script : this.getScripts()) {
|
||||
script.clearConsole();
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ToStringHelper {
|
||||
private final String className;
|
||||
|
||||
@@ -1,17 +1,25 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public interface IScriptHandler {
|
||||
void callScript(EnumScriptType type, Event event);
|
||||
default void callScript(EnumScriptType type, Event event) {
|
||||
if (type != null)
|
||||
callScript(type.function, event);
|
||||
|
||||
}
|
||||
|
||||
void callScript(String hookName, Event event);
|
||||
|
||||
boolean isClient();
|
||||
default boolean isClient() {
|
||||
return FMLCommonHandler.instance().getEffectiveSide().isClient();
|
||||
}
|
||||
|
||||
boolean getEnabled();
|
||||
|
||||
@@ -25,11 +33,28 @@ public interface IScriptHandler {
|
||||
|
||||
List<IScriptUnit> getScripts();
|
||||
|
||||
String noticeString();
|
||||
default String noticeString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
Map<Long, String> getConsoleText();
|
||||
default Map<Long, String> getConsoleText() {
|
||||
Map<Long, String> map = new TreeMap<>();
|
||||
int tab = 0;
|
||||
|
||||
for (IScriptUnit script : getScripts()) {
|
||||
++tab;
|
||||
for (Map.Entry<Long, String> entry : script.getConsole().entrySet()) {
|
||||
map.put(entry.getKey(), " tab " + tab + ":\n" + entry.getValue());
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
void clearConsole();
|
||||
default void clearConsole() {
|
||||
for (IScriptUnit script : getScripts())
|
||||
script.clearConsole();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Janino (Java) script unit for this handler.
|
||||
|
||||
@@ -1,21 +1,12 @@
|
||||
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 LinkedItemScript implements IScriptHandler {
|
||||
public IScriptUnit container;
|
||||
@@ -106,26 +97,6 @@ public class LinkedItemScript implements IScriptHandler {
|
||||
return "LinkedItem";
|
||||
}
|
||||
|
||||
@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();
|
||||
|
||||
@@ -89,9 +89,6 @@ public class PlayerDataScript implements IScriptHandler {
|
||||
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) {
|
||||
@@ -187,10 +184,9 @@ public class PlayerDataScript implements IScriptHandler {
|
||||
public String noticeString() {
|
||||
if (this.player == null) {
|
||||
return "Global script";
|
||||
} else {
|
||||
BlockPos pos = new BlockPos(this.player);
|
||||
return PlayerDataScript.toStringHelper(this.player).add("x", pos.getX()).add("y", pos.getY()).add("z", pos.getZ()).toString();
|
||||
}
|
||||
BlockPos pos = new BlockPos(this.player);
|
||||
return PlayerDataScript.toStringHelper(this.player).add("x", pos.getX()).add("y", pos.getY()).add("z", pos.getZ()).toString();
|
||||
}
|
||||
|
||||
public IPlayer getPlayer() {
|
||||
@@ -201,28 +197,19 @@ public class PlayerDataScript implements IScriptHandler {
|
||||
}
|
||||
|
||||
public Map<Long, String> getConsoleText() {
|
||||
if (ConfigScript.IndividualPlayerScripts)
|
||||
if (ConfigScript.IndividualPlayerScripts) {
|
||||
return console;
|
||||
|
||||
TreeMap<Long, String> map = new TreeMap<>();
|
||||
int tab = 0;
|
||||
for (IScriptUnit script : this.getScripts()) {
|
||||
++tab;
|
||||
for (Entry<Long, String> entry : script.getConsole().entrySet()) {
|
||||
map.put(entry.getKey(), " tab " + tab + ":\n" + entry.getValue());
|
||||
}
|
||||
}
|
||||
return map;
|
||||
return IScriptHandler.super.getConsoleText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearConsole() {
|
||||
if (ConfigScript.IndividualPlayerScripts)
|
||||
if (ConfigScript.IndividualPlayerScripts) {
|
||||
console.clear();
|
||||
else {
|
||||
for (IScriptUnit script : this.getScripts()) {
|
||||
script.clearConsole();
|
||||
}
|
||||
return;
|
||||
}
|
||||
IScriptHandler.super.clearConsole();
|
||||
}
|
||||
|
||||
public static final class ToStringHelper {
|
||||
|
||||
Reference in new issue
Block a user