single argument print(foo) in player scoped apps will always target the player instance for chat message output.
This commit is contained in:
1 parent
c9b93e598a
commit
51fae27708
2 files changed
+13
-6
No files matched your search
@@ -245,6 +245,7 @@ produce an exception.
|
|||||||
### `print(expr)`, `print(player/player_list, expr)`
|
### `print(expr)`, `print(player/player_list, expr)`
|
||||||
|
|
||||||
Displays the result of the expression to the chat. Overrides default `scarpet` behaviour of sending everything to stderr.
|
Displays the result of the expression to the chat. Overrides default `scarpet` behaviour of sending everything to stderr.
|
||||||
|
For player scoped apps it always by default targets the player for whom the app runs on behalf.
|
||||||
Can optionally define player or list of players to send the message to.
|
Can optionally define player or list of players to send the message to.
|
||||||
|
|
||||||
### `format(components, ...)`, `format([components, ...])`
|
### `format(components, ...)`, `format([components, ...])`
|
||||||
|
|||||||
@@ -505,25 +505,31 @@ public class Auxiliary
|
|||||||
{
|
{
|
||||||
throw new InternalExpressionException("'print' takes one or two arguments");
|
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();
|
MinecraftServer server = s.getServer();
|
||||||
Value res = lv.get(0);
|
Value res = lv.get(0);
|
||||||
List<ServerPlayer> targets = null;
|
List<CommandSourceStack> targets = null;
|
||||||
if (lv.size() == 2)
|
if (lv.size() == 2)
|
||||||
{
|
{
|
||||||
List<Value> playerValues = (res instanceof ListValue list) ? list.getItems() : Collections.singletonList(res);
|
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 -> {
|
playerValues.forEach(pv -> {
|
||||||
ServerPlayer player = EntityValue.getPlayerByValue(server, pv);
|
ServerPlayer player = EntityValue.getPlayerByValue(server, pv);
|
||||||
if (player == null)
|
if (player == null)
|
||||||
{
|
{
|
||||||
throw new InternalExpressionException("Cannot target player " + pv.getString() + " in print");
|
throw new InternalExpressionException("Cannot target player " + pv.getString() + " in print");
|
||||||
}
|
}
|
||||||
playerTargets.add(player);
|
playerTargets.add(player.createCommandSourceStack());
|
||||||
});
|
});
|
||||||
targets = playerTargets;
|
targets = playerTargets;
|
||||||
res = lv.get(1);
|
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);
|
Component message = FormattedTextValue.getTextByValue(res);
|
||||||
if (targets == null)
|
if (targets == null)
|
||||||
{
|
{
|
||||||
@@ -531,7 +537,7 @@ public class Auxiliary
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
targets.forEach(p -> p.createCommandSourceStack().sendSuccess(message, false));
|
targets.forEach(p -> p.sendSuccess(message, false));
|
||||||
}
|
}
|
||||||
return res; // pass through for variables
|
return res; // pass through for variables
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user