player() returns consistently on player scoped apps.

This commit is contained in:
gnembon committed 2020-12-23 11:55:45 -04:00
1 parent d99ab4fc24
commit 6225e5f632
3 files changed
+16 -6

No files matched your search

+1 -1
View File
@@ -91,7 +91,7 @@ public abstract class ScriptHost
protected ScriptHost parent;
protected boolean perUser;
protected String user;
public String user;
public String getName() {return main ==null?null: main.getName();}
+11 -4
View File
@@ -45,10 +45,17 @@ public class Entities {
{
expression.addLazyFunction("player", -1, (c, t, lv) ->
{
if (lv.size() ==0)
if (lv.size() == 0)
{
Entity callingEntity = ((CarpetContext)c).s.getEntity();
CarpetContext cc = (CarpetContext)c;
if (cc.host.user != null)
{
ServerPlayerEntity player = cc.s.getMinecraftServer().getPlayerManager().getPlayer(cc.host.user);
if (player == null) return LazyValue.NULL;
Value ret = new EntityValue(player);
return (_c, _t) -> ret;
}
Entity callingEntity = cc.s.getEntity();
if (callingEntity instanceof PlayerEntity)
{
Value retval = new EntityValue(callingEntity);
@@ -108,7 +115,7 @@ public class Entities {
retval = new EntityValue(player);
}
Value finalVar = retval;
return (cc, tt) -> finalVar;
return (_c, _t) -> finalVar;
});
expression.addLazyFunction("spawn", -1, (c, t, lv) ->