Added ability to use parse subcommand from console when targeting a player, Added ability to broadcast a parse message with bcparse subcommand

This commit is contained in:
extendedclip 2018-06-16 20:05:12 -04:00
parent 0f51b4f2a5
commit be96238800

View File

@ -36,7 +36,6 @@ import org.bukkit.entity.Player;
public class PlaceholderAPICommands implements CommandExecutor {
private PlaceholderAPIPlugin plugin;
private CommandExecutor eCloud;
public PlaceholderAPICommands(PlaceholderAPIPlugin i) {
@ -46,15 +45,15 @@ public class PlaceholderAPICommands implements CommandExecutor {
@Override
public boolean onCommand(CommandSender s, Command c, String label, String[] args) {
if (args.length == 0) {
Msg.msg(s, "PlaceholderAPI &7version &b&o" + plugin.getDescription().getVersion(),
"&fCreated by&7: &bextended_clip");
return true;
} else {
if (args[0].equalsIgnoreCase("help")) {
Msg.msg(s, "PlaceholderAPI &aHelp &e(&f" + plugin.getDescription().getVersion() + "&e)",
"&b/papi",
"&fView plugin info/version info",
@ -64,11 +63,12 @@ public class PlaceholderAPICommands implements CommandExecutor {
"&fView information for a specific expansion",
"&b/papi parse <(playername)/me> <...args>",
"&fParse a String with placeholders",
"&b/papi bcparse <(playername)/me> <...args>",
"&fParse a String with placeholders and broadcast the message",
"&b/papi parserel <player one> <player two> <...args>",
"&fParse a String with relational placeholders",
"&b/papi reload",
"&fReload the config settings");
if (s.hasPermission("placeholderapi.ecloud")) {
if (plugin.getExpansionCloud() == null) {
Msg.msg(s, "&b/papi enablecloud",
@ -80,119 +80,107 @@ public class PlaceholderAPICommands implements CommandExecutor {
"&fView ecloud command usage");
}
}
return true;
} else if (args[0].equalsIgnoreCase("ecloud")) {
if (!s.hasPermission("placeholderapi.ecloud")) {
Msg.msg(s, "&cYou don't have permission to do that!");
return true;
}
if (plugin.getExpansionCloud() == null) {
Msg.msg(s, "&7The expansion cloud is not enabled!");
return true;
}
return eCloud.onCommand(s, c, label, args);
} else if (args[0].equalsIgnoreCase("enablecloud")) {
if (!s.hasPermission("placeholderapi.ecloud")) {
Msg.msg(s, "&cYou don't have permission to do that!");
return true;
}
if (plugin.getExpansionCloud() != null) {
Msg.msg(s, "&7The cloud is already enabled!");
return true;
}
plugin.enableCloud();
plugin.getPlaceholderAPIConfig().setCloudEnabled(true);
Msg.msg(s, "&aThe cloud has been enabled!");
return true;
} else if (args[0].equalsIgnoreCase("disablecloud")) {
if (!s.hasPermission("placeholderapi.ecloud")) {
Msg.msg(s, "&cYou don't have permission to do that!");
return true;
}
if (plugin.getExpansionCloud() == null) {
Msg.msg(s, "&7The cloud is already disabled!");
return true;
}
plugin.disableCloud();
plugin.getPlaceholderAPIConfig().setCloudEnabled(false);
Msg.msg(s, "&aThe cloud has been disabled!");
return true;
} else if (args.length > 1 && args[0].equalsIgnoreCase("info")) {
if (!s.hasPermission("placeholderapi.info")) {
Msg.msg(s, "&cYou don't have permission to do that!");
return true;
}
PlaceholderExpansion ex = plugin.getExpansionManager().getRegisteredExpansion(args[1]);
if (ex == null) {
Msg.msg(s, "&cThere is no expansion loaded with the identifier: &f" + args[1]);
return true;
}
Msg.msg(s, "&7Placeholder expansion info for: &f" + ex.getName());
Msg.msg(s, "&7Status: " + (ex.isRegistered() ? "&aRegistered" : "&cNot registered"));
if (ex.getAuthor() != null) {
Msg.msg(s, "&7Created by: &f" + ex.getAuthor());
}
if (ex.getVersion() != null) {
Msg.msg(s, "&7Version: &f" + ex.getVersion());
}
if (ex.getRequiredPlugin() != null) {
Msg.msg(s, "&7Requires plugin: &f" + ex.getRequiredPlugin());
}
if (ex.getPlaceholders() != null) {
Msg.msg(s, "&8&m-- &r&7Placeholders &8&m--");
for (String placeholder : ex.getPlaceholders()) {
Msg.msg(s, placeholder);
}
}
return true;
} else if (args.length > 2 && args[0].equalsIgnoreCase("parse")) {
} else if (args.length > 2 && args[0].equalsIgnoreCase("parse")
|| args.length > 2 && args[0].equalsIgnoreCase("bcparse")) {
if (!(s instanceof Player)) {
Msg.msg(s, "&cThis command can only be used in game!");
if (!s.hasPermission("placeholderapi.parse")) {
Msg.msg(s, "&cYou don't have permission to do that!");
return true;
} else {
if (!s.hasPermission("placeholderapi.parse")) {
Msg.msg(s, "&cYou don't have permission to do that!");
}
OfflinePlayer pl = null;
if (args[1].equalsIgnoreCase("me")) {
if (s instanceof Player) {
pl = (Player) s;
} else {
Msg.msg(s, "&cThis command must target a player when used by console");
return true;
}
}
OfflinePlayer pl = null;
if (args[1].equalsIgnoreCase("me")) {
pl = ((Player) s).getPlayer();
} else {
pl = Bukkit.getOfflinePlayer(args[1]);
if (Bukkit.getPlayer(args[1]) != null) {
pl = Bukkit.getPlayer(args[1]);
} 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));
if (args[0].equalsIgnoreCase("bcparse")) {
Msg.broadcast("&r" + PlaceholderAPI.setPlaceholders(pl, parse));
} else {
Msg.msg(s, "&r" + PlaceholderAPI.setPlaceholders(pl, parse));
}
return true;
} else if (args.length > 3 && args[0].equalsIgnoreCase("parserel")) {
@ -205,24 +193,18 @@ public class PlaceholderAPICommands implements CommandExecutor {
return true;
}
}
Player one = Bukkit.getPlayer(args[1]);
if (one == null) {
Msg.msg(s, args[1] + " &cis not online!");
return true;
}
Player two = Bukkit.getPlayer(args[2]);
if (two == null) {
Msg.msg(s, args[2] + " &cis not online!");
return true;
}
String parse = StringUtils.join(args, " ", 3, args.length);
Msg.msg(s, "&r" + PlaceholderAPI.setRelationalPlaceholders(one, two, parse));
return true;
} else if (args[0].equalsIgnoreCase("reload")) {
@ -232,11 +214,8 @@ public class PlaceholderAPICommands implements CommandExecutor {
return true;
}
}
Msg.msg(s, "&fPlaceholder&7API &bconfiguration reloaded!");
plugin.reloadConf(s);
} else if (args[0].equalsIgnoreCase("list")) {
if (s instanceof Player) {
@ -247,7 +226,6 @@ public class PlaceholderAPICommands implements CommandExecutor {
}
Set<String> registered = PlaceholderAPI.getRegisteredIdentifiers();
if (registered.isEmpty()) {
Msg.msg(s, "&7There are no placeholder hooks currently registered!");
return true;
@ -258,7 +236,6 @@ public class PlaceholderAPICommands implements CommandExecutor {
Msg.msg(s, "&cIncorrect usage! &7/papi help");
}
}
return true;
}