Container event spam when no container is open fixed. Fixed scripted player and forge events not launching after merging ScriptContainer and EventScriptContainer.

This commit is contained in:
luisc committed 2021-12-03 18:17:52 -06:00
1 parent 23686dc3b8
commit 547f5ab82d
4 files changed
+41 -65

No files matched your search

+2
View File
@@ -64,3 +64,5 @@ processResources
exclude 'mcmod.info'
}
}
sourceSets {main { output.resourcesDir = output.classesDir }}
@@ -28,6 +28,7 @@ import cpw.mods.fml.common.network.FMLNetworkEvent;
import cpw.mods.fml.relauncher.Side;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ContainerPlayer;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldServer;
@@ -173,7 +174,7 @@ public class ScriptPlayerEventHandler {
@SubscribeEvent
public void invoke(PlayerOpenContainerEvent event) {
if(event.entityPlayer.worldObj instanceof WorldServer) {
if(event.entityPlayer.worldObj instanceof WorldServer && !(event.entityPlayer.openContainer instanceof ContainerPlayer)) {
PlayerDataScript handler = PlayerData.get(event.entityPlayer).scriptData;
EventHooks.onPlayerContainerOpen(handler, event.entityPlayer.openContainer);
}
@@ -109,54 +109,6 @@ public class ScriptContainer {
}
public void run(String type, Object event) {
if (!this.errored && this.hasCode() && !this.unknownFunctions.contains(type)) {
this.setEngine(this.handler.getLanguage());
if (this.engine != null) {
if (ScriptController.Instance.lastLoaded > this.lastCreated) {
this.lastCreated = ScriptController.Instance.lastLoaded;
this.init = false;
}
String var3 = "lock";
synchronized("lock") {
Current = this;
CurrentType = type;
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
this.engine.getContext().setWriter(pw);
this.engine.getContext().setErrorWriter(pw);
try {
if (!this.init) {
this.engine.eval(this.getFullCode());
this.init = true;
}
if (this.engine.getFactory().getLanguageName().equals("lua")) {
Object ob = this.engine.get(type);
if (ob == null) {
this.unknownFunctions.add(type);
}
} else {
((Invocable)this.engine).invokeFunction(type, new Object[]{event});
}
} catch (NoSuchMethodException var13) {
this.unknownFunctions.add(type);
} catch (Throwable var14) {
this.errored = true;
var14.printStackTrace(pw);
} finally {
this.appandConsole(sw.getBuffer().toString().trim());
pw.close();
Current = null;
}
}
}
}
}
/*public void run(String type, Object event) {
if (!this.errored && this.hasCode() && !this.unknownFunctions.contains(type)) {
this.setEngine(this.handler.getLanguage());
if (this.engine != null) {
@@ -195,7 +147,7 @@ public class ScriptContainer {
}
}
}
}*/
}
public void appandConsole(String message) {
if (message != null && !message.isEmpty()) {
@@ -78,50 +78,71 @@ public class PlayerDataScript implements IScriptHandler {
}
public void callScript(EnumScriptType type, Event event, Object... obs) {
if (this.isEnabled()) {
if(this.isEnabled()) {
ScriptContainer script;
if (ScriptController.Instance.lastLoaded > this.lastInited || ScriptController.Instance.lastPlayerUpdate > this.lastPlayerUpdate) {
if(ScriptController.Instance.lastLoaded > this.lastInited || ScriptController.Instance.lastPlayerUpdate > this.lastPlayerUpdate) {
this.lastInited = ScriptController.Instance.lastLoaded;
errored.clear();
if (this.player != null) {
//ScriptController.Instance.playerScripts.errored.clear();
if(this.player != null) {
this.scripts.clear();
Iterator var3 = ScriptController.Instance.playerScripts.scripts.iterator();
Iterator i = ScriptController.Instance.playerScripts.scripts.iterator();
while(var3.hasNext()) {
script = (ScriptContainer)var3.next();
while(i.hasNext()) {
script = (ScriptContainer)i.next();
ScriptContainer s = new ScriptContainer(this);
s.readFromNBT(script.writeToNBT(new NBTTagCompound()));
this.scripts.add(s);
}
}
this.lastPlayerUpdate = ScriptController.Instance.lastPlayerUpdate;
if (type != EnumScriptType.INIT) {
if(type != EnumScriptType.INIT) {
EventHooks.onPlayerInit(this);
}
}
for(int i = 0; i < this.scripts.size(); ++i) {
script = (ScriptContainer)this.scripts.get(i);
if (!errored.contains(i)) {
for(int var7 = 0; var7 < this.scripts.size(); ++var7) {
script = (ScriptContainer)this.scripts.get(var7);
if(!ScriptController.Instance.playerScripts.errored.contains(Integer.valueOf(var7))) {
if(script == null || script.errored || !script.hasCode())
return;
script.setEngine(scriptLanguage);
if(script.engine == null)
return;
for(int i = 0; i + 1 < obs.length; i += 2){
Object ob = obs[i + 1];
if(ob instanceof Entity)
ob = ScriptController.Instance.getScriptForEntity((Entity)ob);
script.engine.put(obs[i].toString(), ob);
}
ScriptEngine engine = script.engine;
engine.put("world", dummyWorld);
engine.put("player", dummyPlayer);
PlayerEvent result = (PlayerEvent) engine.get("event");
if(result == null)
engine.put("event", result = new PlayerEvent(this.getPlayer()));
script.engine.put("API", new WrapperNpcAPI());
script.run(type, event);
if (script.errored) {
errored.add(i);
ScriptController.Instance.playerScripts.errored.add(var7);
}
Iterator var8 = script.console.entrySet().iterator();
while(var8.hasNext()) {
Entry<Long, String> entry = (Entry)var8.next();
if (!console.containsKey(entry.getKey())) {
console.put(entry.getKey(), " tab " + (i + 1) + ":\n" + (String)entry.getValue());
if (!ScriptController.Instance.playerScripts.console.containsKey(entry.getKey())) {
ScriptController.Instance.playerScripts.console.put(entry.getKey(), " tab " + (var7 + 1) + ":\n" + (String)entry.getValue());
}
}
script.console.clear();
}
}
}
}