Merge pull request #1060 from PlaceholderAPI/fix/parse-command-improvements

Parse command improvements
This commit is contained in:
PiggyPiglet 2024-05-21 18:08:19 +08:00 committed by GitHub
commit 2d1a0ee157
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -87,7 +87,8 @@ public final class CommandParse extends PlaceholderCommand {
final boolean command) { final boolean command) {
if (params.size() < 2) { if (params.size() < 2) {
Msg.msg(sender, Msg.msg(sender,
"&cYou must supply a target, and a message: &b/papi " + (broadcast ? "bcparse" : "parse") "&cYou must provide a target and message: &b/papi "
+ (command ? "cmdparse" : (broadcast ? "bcparse" : "parse"))
+ " &7{target} &a{message}"); + " &7{target} &a{message}");
return; return;
} }
@ -132,24 +133,49 @@ public final class CommandParse extends PlaceholderCommand {
@NotNull @Unmodifiable final List<String> params) { @NotNull @Unmodifiable final List<String> params) {
if (params.size() < 3) { if (params.size() < 3) {
Msg.msg(sender, Msg.msg(sender,
"&cYou must supply two targets, and a message: &b/papi parserel &7{target one} {target two} &a{message}"); "&cYou must supply two targets, and a message: &b/papi parserel &7{target one} "
+ "{target two} &a{message}");
return; return;
} }
final OfflinePlayer targetOne = resolvePlayer(params.get(0)); OfflinePlayer playerOne;
if (targetOne == null || !targetOne.isOnline()) {
if ("me".equalsIgnoreCase(params.get(0))) {
if (!(sender instanceof Player)) {
Msg.msg(sender, "&cYou must be a player to use &7me&c as a target!");
return;
}
playerOne = ((Player) sender);
} else {
playerOne = resolvePlayer(params.get(0));
}
if (playerOne == null || !playerOne.isOnline()) {
Msg.msg(sender, "&cFailed to find player: &f" + params.get(0)); Msg.msg(sender, "&cFailed to find player: &f" + params.get(0));
return; return;
} }
final OfflinePlayer targetTwo = resolvePlayer(params.get(1)); OfflinePlayer playerTwo;
if (targetTwo == null || !targetTwo.isOnline()) {
if ("me".equalsIgnoreCase(params.get(1))) {
if (!(sender instanceof Player)) {
Msg.msg(sender, "&cYou must be a player to use &7me&c as a target!");
return;
}
playerTwo = ((Player) sender);
} else {
playerTwo = resolvePlayer(params.get(1));
}
if (playerTwo == null || !playerTwo.isOnline()) {
Msg.msg(sender, "&cFailed to find player: &f" + params.get(1)); Msg.msg(sender, "&cFailed to find player: &f" + params.get(1));
return; return;
} }
final String message = PlaceholderAPI final String message = PlaceholderAPI
.setRelationalPlaceholders(((Player) targetOne), ((Player) targetTwo), .setRelationalPlaceholders((Player) playerOne, (Player) playerTwo,
String.join(" ", params.subList(2, params.size()))); String.join(" ", params.subList(2, params.size())));
sender.sendMessage(message); sender.sendMessage(message);