single argument print(foo) in player scoped apps will always target the player instance for chat message output.

This commit is contained in:
gnembon committed 2023-04-20 20:46:33 +02:00
1 parent c9b93e598a
commit 51fae27708
2 files changed
+13 -6

No files matched your search

+12 -6
View File
@@ -505,25 +505,31 @@ public class Auxiliary
{
throw new InternalExpressionException("'print' takes one or two arguments");
}
CommandSourceStack s = ((CarpetContext) c).source();
CarpetContext cc = (CarpetContext) c;
CommandSourceStack s = cc.source();
MinecraftServer server = s.getServer();
Value res = lv.get(0);
List<ServerPlayer> targets = null;
List<CommandSourceStack> targets = null;
if (lv.size() == 2)
{
List<Value> playerValues = (res instanceof ListValue list) ? list.getItems() : Collections.singletonList(res);
List<ServerPlayer> playerTargets = new ArrayList<>();
List<CommandSourceStack> playerTargets = new ArrayList<>();
playerValues.forEach(pv -> {
ServerPlayer player = EntityValue.getPlayerByValue(server, pv);
if (player == null)
{
throw new InternalExpressionException("Cannot target player " + pv.getString() + " in print");
}
playerTargets.add(player);
playerTargets.add(player.createCommandSourceStack());
});
targets = playerTargets;
res = lv.get(1);
}
} else if (c.host.user != null) {
ServerPlayer player = cc.server().getPlayerList().getPlayerByName(cc.host.user);
if (player != null) {
targets = Collections.singletonList(player.createCommandSourceStack());
}
} // optionally retrieve from CC.host.responsibleSource to print?
Component message = FormattedTextValue.getTextByValue(res);
if (targets == null)
{
@@ -531,7 +537,7 @@ public class Auxiliary
}
else
{
targets.forEach(p -> p.createCommandSourceStack().sendSuccess(message, false));
targets.forEach(p -> p.sendSuccess(message, false));
}
return res; // pass through for variables
});