Require a player be specified when using /papi parse command

This commit is contained in:
extendedclip 2018-06-14 15:17:46 -04:00
parent 46839c4bf2
commit e4a672e57e

View File

@ -20,19 +20,19 @@
*/
package me.clip.placeholderapi.commands;
import java.util.Set;
import me.clip.placeholderapi.PlaceholderAPI;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import me.clip.placeholderapi.util.Msg;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.Set;
public class PlaceholderAPICommands implements CommandExecutor {
private PlaceholderAPIPlugin plugin;
@ -62,7 +62,7 @@ public class PlaceholderAPICommands implements CommandExecutor {
"&fList all placeholder expansions that are currently active",
"&b/papi info <placeholder name>",
"&fView information for a specific expansion",
"&b/papi parse <...args>",
"&b/papi parse <(playername)/me> <...args>",
"&fParse a String with placeholders",
"&b/papi parserel <player one> <player two> <...args>",
"&fParse a String with relational placeholders",
@ -167,7 +167,7 @@ public class PlaceholderAPICommands implements CommandExecutor {
}
return true;
} else if (args.length > 1 && args[0].equalsIgnoreCase("parse")) {
} else if (args.length > 2 && args[0].equalsIgnoreCase("parse")) {
if (!(s instanceof Player)) {
Msg.msg(s, "&cThis command can only be used in game!");
@ -179,12 +179,20 @@ public class PlaceholderAPICommands implements CommandExecutor {
}
}
Player p = (Player) s;
OfflinePlayer pl = null;
String parse = StringUtils.join(args, " ", 1, args.length);
Msg.msg(s, "&r" + PlaceholderAPI.setPlaceholders(p, parse));
if (args[1].equalsIgnoreCase("me")) {
pl = ((Player) s).getPlayer();
} else {
pl = Bukkit.getOfflinePlayer(args[1]);
}
if (pl == null || !pl.hasPlayedBefore()) {
Msg.msg(s, "&cFailed to find player: &f" + args[1]);
return true;
}
String parse = StringUtils.join(args, " ", 2, args.length);
Msg.msg(s, "&r" + PlaceholderAPI.setPlaceholders(pl, parse));
return true;
} else if (args.length > 3 && args[0].equalsIgnoreCase("parserel")) {
@ -244,7 +252,7 @@ public class PlaceholderAPICommands implements CommandExecutor {
Msg.msg(s, "&7There are no placeholder hooks currently registered!");
return true;
}
Msg.msg(s, registered.size()+" &7Placeholder hooks registered:");
Msg.msg(s, registered.size() + " &7Placeholder hooks registered:");
Msg.msg(s, registered.toString());
} else {
Msg.msg(s, "&cIncorrect usage! &7/papi help");