use of org.dynmap.common.DynmapCommandSender in project dynmap by webbukkit.
the class DynmapExpCommand method onCommand.
void onCommand(CommandSource sender, String cmd, String[] args) {
DynmapCommandSender dsender;
PlayerEntity psender;
try {
psender = sender.asPlayer();
} catch (com.mojang.brigadier.exceptions.CommandSyntaxException x) {
psender = null;
}
if (psender != null) {
dsender = new ForgePlayer(psender);
} else {
dsender = new ForgeCommandSender(sender);
}
try {
core.processCommand(dsender, cmd, cmd, args);
} catch (Exception x) {
dsender.sendMessage("Command internal error: " + x.getMessage());
Log.severe("Error with command: " + cmd + Arrays.deepToString(args), x);
}
}
use of org.dynmap.common.DynmapCommandSender in project dynmap by webbukkit.
the class DynmapPlugin method handleCommand.
// TODO: Clean a bit
public void handleCommand(ServerCommandSource commandSource, String cmd, String[] args) throws CommandSyntaxException {
DynmapCommandSender dsender;
ServerPlayerEntity psender = null;
// getPlayer throws a CommandSyntaxException, so getEntity and instanceof for safety
if (commandSource.getEntity() instanceof ServerPlayerEntity) {
psender = commandSource.getPlayer();
}
if (psender != null) {
// FIXME: New Player? Why not query the current player list.
dsender = new FabricPlayer(this, psender);
} else {
dsender = new FabricCommandSender(commandSource);
}
core.processCommand(dsender, cmd, cmd, args);
}
use of org.dynmap.common.DynmapCommandSender in project dynmap by webbukkit.
the class DynmapPlugin method handleCommand.
// TODO: Clean a bit
public void handleCommand(ServerCommandSource commandSource, String cmd, String[] args) throws CommandSyntaxException {
DynmapCommandSender dsender;
ServerPlayerEntity psender = null;
// getPlayer throws a CommandSyntaxException, so getEntity and instanceof for safety
if (commandSource.getEntity() instanceof ServerPlayerEntity) {
psender = commandSource.getPlayer();
}
if (psender != null) {
// FIXME: New Player? Why not query the current player list.
dsender = new FabricPlayer(this, psender);
} else {
dsender = new FabricCommandSender(commandSource);
}
core.processCommand(dsender, cmd, cmd, args);
}
use of org.dynmap.common.DynmapCommandSender in project dynmap by webbukkit.
the class DynmapPlugin method handleCommand.
// TODO: Clean a bit
public void handleCommand(ServerCommandSource commandSource, String cmd, String[] args) throws CommandSyntaxException {
DynmapCommandSender dsender;
ServerPlayerEntity psender = null;
// getPlayer throws a CommandSyntaxException, so getEntity and instanceof for safety
if (commandSource.getEntity() instanceof ServerPlayerEntity) {
psender = commandSource.getPlayer();
}
if (psender != null) {
// FIXME: New Player? Why not query the current player list.
dsender = new FabricPlayer(this, psender);
} else {
dsender = new FabricCommandSender(commandSource);
}
core.processCommand(dsender, cmd, cmd, args);
}
use of org.dynmap.common.DynmapCommandSender in project dynmap by webbukkit.
the class DynmapCore method getTabCompletions.
/**
* Returns a list of tab completion suggestions for the given sender, command and command arguments.
*
* @param sender - The sender of the tab completion, used for permission checks
* @param cmd - The top level command being tab completed
* @param args - Array of extra command arguments
* @return List of tab completion suggestions
*/
public List<String> getTabCompletions(DynmapCommandSender sender, String cmd, String[] args) {
if (mapManager == null || args.length == 0) {
return Collections.emptyList();
}
if (args.length == 1) {
return getSubcommandSuggestions(sender, cmd, args[0]);
}
if (cmd.equalsIgnoreCase("dmap")) {
return dmapcmds.getTabCompletions(sender, args, this);
}
if (cmd.equalsIgnoreCase("dmarker")) {
return markerapi.getTabCompletions(sender, args, this);
}
if (cmd.equalsIgnoreCase("dynmapexp")) {
return dynmapexpcmds.getTabCompletions(sender, args, this);
}
if (!cmd.equalsIgnoreCase("dynmap")) {
return Collections.emptyList();
}
/* Re-parse args - handle double quotes */
args = parseArgs(args, sender, true);
if (args == null || args.length <= 1) {
return Collections.emptyList();
}
String subcommand = args[0];
DynmapPlayer player = null;
if (sender instanceof DynmapPlayer) {
player = (DynmapPlayer) sender;
}
if (subcommand.equals("radiusrender") && checkPlayerPermission(sender, "radiusrender")) {
if (args.length == 2) {
// /dynmap radiusrender *<world>* <x> <z> <radius> <map>
return getWorldSuggestions(args[1]);
}
if (args.length == 3 && player != null) {
// /dynmap radiusrender <radius> *<mapname>*
try (Scanner sc = new Scanner(args[1])) {
if (sc.hasNextInt(10)) {
// Only show map suggestions if a number was entered before
return getMapSuggestions(player.getLocation().world, args[2], false);
}
}
} else if (args.length == 6) {
// /dynmap radiusrender <world> <x> <z> <radius> *<map>*
return getMapSuggestions(args[1], args[5], false);
}
} else if (subcommand.equals("updaterender") && checkPlayerPermission(sender, "updaterender")) {
if (args.length == 2) {
// /dynmap updaterender *<world>* <x> <z> <map>/*<map>*
List<String> suggestions = getWorldSuggestions(args[1]);
if (player != null) {
suggestions.addAll(getMapSuggestions(player.getLocation().world, args[1], false));
}
return suggestions;
} else if (args.length == 5) {
// /dynmap updaterender <world> <x> <z> *<map>*
return getMapSuggestions(args[1], args[4], false);
}
} else if (subcommand.equals("hide") && checkPlayerPermission(sender, "hide.others")) {
if (args.length == 2) {
// /dynmap hide *<player>*
final String arg = args[1];
return playerList.getVisiblePlayers().stream().map(DynmapPlayer::getName).filter(name -> name.startsWith(arg)).collect(Collectors.toList());
}
} else if (subcommand.equals("show") && checkPlayerPermission(sender, "show.others")) {
if (args.length == 2) {
// /dynmap show *<player>*
final String arg = args[1];
return playerList.getHiddenPlayers().stream().map(DynmapPlayer::getName).filter(name -> name.startsWith(arg)).collect(Collectors.toList());
}
} else if (subcommand.equals("fullrender") && checkPlayerPermission(sender, "fullrender")) {
// World suggestions
List<String> suggestions = getWorldSuggestions(args[args.length - 1]);
// world:map suggestions
suggestions.addAll(getMapSuggestions(args[args.length - 1]));
// Remove suggestions present in other arguments
for (String arg : args) {
suggestions.remove(arg.contains(" ") ? "\"" + arg + "\"" : arg);
}
// Add resume if previous argument wasn't resume
if ("resume".startsWith(args[args.length - 1]) && (args.length == 2 || !args[args.length - 2].equals("resume"))) {
suggestions.add("resume");
}
return suggestions;
} else if ((subcommand.equals("cancelrender") && checkPlayerPermission(sender, "cancelrender")) || (subcommand.equals("purgequeue") && checkPlayerPermission(sender, "purgequeue"))) {
List<String> suggestions = getWorldSuggestions(args[args.length - 1]);
// Remove worlds present in other arguments
suggestions.removeAll(Arrays.asList(args));
return suggestions;
} else if (subcommand.equals("purgemap") && checkPlayerPermission(sender, "purgemap")) {
if (args.length == 2) {
// /dynmap purgemap *<world>* <map>
return getWorldSuggestions(args[1]);
} else if (args.length == 3) {
// /dynmap purgemap <world> *<map>*
return getMapSuggestions(args[1], args[2], false);
}
} else if ((subcommand.equals("purgeworld") && checkPlayerPermission(sender, "purgeworld")) || (subcommand.equals("stats") && checkPlayerPermission(sender, "stats")) || (subcommand.equals("resetstats") && checkPlayerPermission(sender, "resetstats"))) {
if (args.length == 2) {
return getWorldSuggestions(args[1]);
}
} else if (subcommand.equals("pause") && checkPlayerPermission(sender, "pause")) {
List<String> suggestions = Arrays.asList("full", "update", "all", "none");
if (args.length == 2) {
final String arg = args[1];
return suggestions.stream().filter(suggestion -> suggestion.startsWith(arg)).collect(Collectors.toList());
}
} else if ((subcommand.equals("ips-for-id") && checkPlayerPermission(sender, "ips-for-id")) || (subcommand.equals("add-id-for-ip") && checkPlayerPermission(sender, "add-id-for-ip")) || (subcommand.equals("del-id-for-ip") && checkPlayerPermission(sender, "del-id-for-ip")) || (subcommand.equals("webregister") && checkPlayerPermission(sender, "webregister.other"))) {
if (args.length == 2) {
final String arg = args[1];
return Arrays.stream(playerList.getOnlinePlayers()).map(DynmapPlayer::getName).filter(name -> name.startsWith(arg)).collect(Collectors.toList());
}
} else if (subcommand.equals("help")) {
if (args.length == 2) {
return getSubcommandSuggestions(sender, "dynmap", args[1]);
}
}
return Collections.emptyList();
}
Aggregations