@Override public List<String> onTabComplete(CommandSender sender, String[] args) { if (args.length == 0) { return new ArrayList<>(this.commandArguments.keySet()); } else { if (this.commandArguments.containsKey(args[0].toLowerCase())) { return this.commandArguments.get(args[0].toLowerCase()).onTabComplete(sender, args); } else { List<String> completions = new ArrayList<>(); for (String key : this.commandArguments.keySet()) { if (key.toLowerCase().startsWith(args[0].toLowerCase())) { completions.add(key); } } return completions; } } }
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (!(sender instanceof Player)) { sender.sendMessage(ChatColor.RED + "This command is only executable by players."); return true; } Player player = (Player) sender; LogoutTimer logoutTimer = plugin.getTimerManager().getLogoutTimer(); if (!logoutTimer.setCooldown(player, player.getUniqueId())) { sender.sendMessage(ChatColor.YELLOW + "Your " + logoutTimer.getDisplayName() + ChatColor.YELLOW + " timer is already active."); return true; } sender.sendMessage(ChatColor.YELLOW + "Your " + logoutTimer.getDisplayName() + ChatColor.YELLOW + " timer has started."); return true; }
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (args.length < 2) { sender.sendMessage(ChatColor.RED + "Usage: " + getUsage(label)); return true; } long duration = JavaUtils.parse(args[1]); if (duration == -1L) { sender.sendMessage(ChatColor.RED + "Invalid duration, use the correct format: 10m 1s"); return true; } SettingsYML.DEFAULT_DEATHBAN_DURATION = duration; Command.broadcastCommandMessage(sender, ChatColor.RED + "Base death-ban time set to " + DurationFormatUtils.formatDurationWords(duration, true, true) + " (not including multipliers, etc)."); return true; }
@Override public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) { if (args.length != 2 || !(sender instanceof Player)) { return Collections.emptyList(); } Player player = (Player) sender; PlayerFaction playerFaction = plugin.getFactionManager().getPlayerFaction(player); if (playerFaction == null) { return Collections.emptyList(); } List<String> results = new ArrayList<>(); for (Player target : Bukkit.getOnlinePlayers()) { if (!target.equals(player) && player.canSee(target) && !results.contains(target.getName())) { Faction targetFaction = plugin.getFactionManager().getPlayerFaction(target); if (targetFaction != null && playerFaction != targetFaction) { if (playerFaction.getRequestedRelations().get(targetFaction.getUniqueID()) != RELATION && playerFaction.getRelations().get(targetFaction.getUniqueID()) != RELATION) { results.add(targetFaction.getName()); } } } } return results; }
public boolean processCmd(CommandSender s, String[] arg) { sender = s; args = arg; if (forcePlayer) { if (!(s instanceof Player)) { sender.sendMessage(new Messaging.MessageFormatter().format("error.must-be-player")); return false; } else { player = (Player) s; } } if (!Util.hp(sender, cmdName)) sender.sendMessage(new Messaging.MessageFormatter().format("error.cmd-no-perm")); else if (argLength > arg.length) s.sendMessage(ChatColor.DARK_RED + "Wrong usage: " + ChatColor.GRAY +"/swr " + helper()); else return run(); return true; }
@WithCommand public void run(CommandSender sender, @WithName("plugin") @WithOptional Plugin plugin) { Collection<HotbarId> hotbars; if (plugin != null) { Registry<HotbarId> reg = hotbars().get(plugin); hotbars = reg.get(); } else hotbars = hotbars().get(); StringJoiner str = new StringJoiner(GRAY + ", "); for (HotbarId hotbar : hotbars) str.add(AQUA + hotbar.getGlobalId()); if (hotbars.size() > 0) sender.sendMessage(GOLD + "Showing " + hotbars.size() + " hotbars: " + str); else sender.sendMessage(RED + "No hotbar found."); }
@Command( aliases = {"on", "start"}, desc = "Start logging packets", min = 0, max = 1 ) public void start(CommandContext args, CommandSender sender) throws CommandException { if(sender instanceof Player || args.argsLength() >= 1) { final Player player = (Player) getCommandSenderOrSelf(args, sender, 0); if(PacketTracer.start(player, Bukkit.getLogger())) { sender.sendMessage("Started packet trace for " + player.getName(sender)); } } else if(traceAll.compareAndSet(false, true)) { onlinePlayers.all().forEach(player -> PacketTracer.start(player, Bukkit.getLogger())); sender.sendMessage("Started global packet trace"); } }
@Override public boolean onCommand(CommandSender sender, Command command, String alias, String[] args) { Plugin plugin = getServer().getPluginManager().getPlugin("MeerChat"); Player senderPlayer = getServer().getPlayer(sender.getName()); // If the command was completed by the user. if (senderPlayer != null) { senderPlayer.sendMessage("§o[MeerChat is being reloaded - " + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()) + "]§o"); restartPlugin(plugin); senderPlayer.sendMessage("§o[MeerChat has been reloaded - " + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()) + "]§o"); } // If the command was completed by the console. else { Bukkit.broadcastMessage("[Server] §o[MeerChat is being reloaded - " + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()) + "]§o"); restartPlugin(plugin); Bukkit.broadcastMessage("[Server] §o[MeerChat has been reloaded - " + new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()) + "]§o"); } return true; }
@Override public void setInputs(CommandSender initiator, String[] args) { if (this.shouldLearn) { initiator .sendMessage("Stop the learning before testing. use /nn stoplearning"); return; } if (args.length > 1) { boolean test = false; try { test = Boolean.parseBoolean(args[1]); } catch (Exception e) { } binary.changeValueAt(0, 0, test); } else { initiator.sendMessage("Provide one value (True or false)"); } }
@Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { Player p = (Player) sender; if (args.length != 1) { Chat.player(sender, "&4[SG] &cPlease include the world name"); return true; } String name = args[0]; World w = Bukkit.getWorld(name); if (w == null) Bukkit.createWorld(new WorldCreator(name)); w = Bukkit.getWorld(name); p.teleport(w.getSpawnLocation()); Chat.player(sender, "&2[SG] &aTeleported to " + w.getName() + " spawn point"); return true; }
@Override public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) { if (args.length != 2 || !(sender instanceof Player)) { return Collections.emptyList(); } else if (args[1].isEmpty()) { return null; } else { Player player = (Player) sender; List<String> results = new ArrayList<>(plugin.getFactionManager().getFactionNameMap().keySet()); for (Player target : Bukkit.getOnlinePlayers()) { if (player.canSee(target) && !results.contains(target.getName())) { results.add(target.getName()); } } return results; } }
@Inject PlayerOrderCache(IdentityProvider identityProvider, BukkitUserStore userStore, MinecraftService minecraftService) { prioritiesByPlayer = CacheUtils.newWeakKeyCache(player -> userStore .getUser(player) .minecraft_flair() .stream() .filter(flair -> minecraftService.getLocalServer().realms().contains(flair.realm)) .map(flair -> flair.priority) .min(Integer::compare) .orElse(Integer.MAX_VALUE) ); comparatorsByViewer = CacheUtils.newWeakKeyCache(strongViewer -> { final WeakReference<CommandSender> weakViewer = new WeakReference<>(strongViewer); return (a, b) -> { // Do not reference strongViewer in here final CommandSender viewer = weakViewer.get(); if(viewer == null) return 0; final Identity aIdentity = identityProvider.currentIdentity(a); final Identity bIdentity = identityProvider.currentIdentity(b); return ComparisonChain.start() .compareTrueFirst(a == viewer, b == viewer) .compareTrueFirst(aIdentity.isFriend(viewer), bIdentity.isFriend(viewer)) .compare(priority(a, aIdentity, viewer), priority(b, bIdentity, viewer)) .compare(aIdentity.getName(viewer), bIdentity.getName(viewer), String::compareToIgnoreCase) .result(); }; }); }
@Override protected void onCommand(CommandSender sender, String[] args) { if (this.toggle.shouldConfirm() && getToggle((Player) sender, this.toggle)) { sender.sendMessage(ChatColor.GRAY + "Are you sure you want to " + ChatColor.RED + "disable" + ChatColor.GRAY + " the " + this.toggle.getDescription() + "?"); Callbacks.promptConfirm((Player) sender, () -> KCPlayer.getWrapper(sender).toggle(this.toggle)); return; } KCPlayer.getWrapper(sender).toggle(this.toggle); }
@Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (sender instanceof ConsoleCommandSender) { return true; } Player player = (Player) sender; Location location = player.getLocation(); if (label.equalsIgnoreCase("tphere")) { if (!(args.length == 0)) { if (args.length == 0) { player.sendMessage(ChatColor.RED + "Please specify the player you want to teleport to or use /teleport help for more info."); TeleportHereMenu.newInventory(sender); return true; } if (!sender.hasPermission("core.tp")) { player.sendMessage(ChatColor.RED + "Sorry, you need core.tp permission to execute /tphere."); return true; } if (args[0].equals(player.getName())) { player.sendMessage(ChatColor.RED + "Lol, you cannot teleport to yourself dummy."); return true; } Player target1 = Bukkit.getServer().getPlayer(args[1]); if (target1 == null) { player.sendMessage(ChatColor.RED + "Can't find user specified."); return true; } target1.teleport(player); player.sendMessage(ChatColor.YELLOW + "You've teleported " + ChatColor.GREEN + target1.getDisplayName() + ChatColor.YELLOW + " to you!"); player.playSound(location, Sound.ENTITY_ENDERMEN_TELEPORT, 100, 1); player.playEffect(location, Effect.ENDER_SIGNAL, 1); target1.playEffect(location, Effect.ENDER_SIGNAL, 1); return true; } } return false; }
@Override protected void onCommand(CommandSender sender, String[] args) { Player player = (Player) sender; String x, y, z, yaw, pitch, world; x = args[0]; y = args[1]; z = args[2]; yaw = args.length > 3 ? args[3] : Float.toString(player.getLocation().getYaw()); pitch = args.length > 4 ? args[4] : Float.toString(player.getLocation().getPitch()); world = args.length > 5 ? args[5] : player.getWorld().getName(); World worldParsed = Bukkit.getWorld(world); if (worldParsed == null) { sender.sendMessage(ChatColor.RED + "Invalid world: " + world); showUsage(player); return; } try { player.teleport(new Location( worldParsed, Double.parseDouble(x), Double.parseDouble(y), Double.parseDouble(z), Float.parseFloat(yaw), Float.parseFloat(pitch) )); player.sendMessage(ChatColor.GREEN + "Teleported to location."); } catch (NumberFormatException e) { showUsage(player); } }
private void sendHelp(CommandSender sender) { sender.sendMessage(""); sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&aSlimefun &2v" + plugin.getDescription().getVersion())); sender.sendMessage(""); for (int i = 0; i < arguments.size(); i++) { sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&3" + arguments.get(i) + " &b") + descriptions.get(i)); } }
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (command.getName().equalsIgnoreCase("anti-rooktube")) { if(sender instanceof Player) { Player p = (Player) sender; reloadConfig(); Util.sendMsg(p, ChatColor.GREEN + "Reloaded Anti-Rooktube's config!"); Util.sendMsg(p, ChatColor.LIGHT_PURPLE + "Grabbing Rook's current spigot name 1 sec..."); } else { reloadConfig(); sender.sendMessage(ChatColor.GREEN + "Reloaded Anti-Rooktube's config!"); sender.sendMessage(ChatColor.LIGHT_PURPLE + "Grabbing Rook's current spigot name 1 sec..."); } String spigotname = null; try { spigotname = JsonReader.grabRookSpigot(args); } catch (JSONException | IOException e) { e.printStackTrace(); } sender.sendMessage(ChatColor.GREEN + "Rook's current spigot name is: " + ChatColor.RED + "" + ChatColor.BOLD + spigotname); return true; } return false; }
public void call(CommandSender s, String label, String arg1) { if (OMGPI.g.state != GameState.INGAME) { s.sendMessage(ChatColor.RED + "Game is not running."); return; } try { int i = Integer.parseInt(arg1); OMGPI.g.broadcast(ChatColor.AQUA + (s instanceof Player ? s.getName() : "Console") + " set time to " + arg1 + "."); OMGPI.g.timerTicks = i; } catch (NumberFormatException e) { s.sendMessage("Cannot set time to " + arg1); } }
@Override public boolean onCommand(CommandSender cs, Command cmd, String s, String[] args) { if(cs instanceof Player){ Player p = (Player) cs; GUI.openGUI(p); } else Bukkit.getConsoleSender().sendMessage("[ArmorPlus] §c콘솔에서는 사용이 불가능한 명령어입니다!"); return false; }
@Override protected void onCommand(CommandSender sender, String[] args) { QueryTools.queryData(data -> { sender.sendMessage(ChatColor.RED + "Accounts with IPs that start with '" + args[0] + "': "); sender.sendMessage(data.filter(k -> k.getLastIP() != null &&k.getLastIP().startsWith(args[0])) .map(KCPlayer::getUsername).collect(Collectors.joining(", "))); }); }
@Override protected boolean commandLogic(CommandSender sender, Command command, String label, String[] args) { Player player = (Player) sender; if (args.length == 0) { sender.sendMessage(player.toString()); return true; } return doReflectionLookups(sender, args, player); }
@SuppressWarnings("deprecation") @SubCommand(value = "select", permission = "town.player.select") public void commandSelect(CommandSender sender, Arguments args) { if (args.length() == 3 && sender.hasPermission("town.admin")) { String name = args.nextString(); SpawnLocation spawnLocation = plugin.config.spawnConfig.spawns.get(name); if (spawnLocation == null || (SpawnConfig.DEFAULT.equals(name) && !sender.hasPermission("town.admin"))) { msg(sender, "user.spawn.not_found", name); return; } String playerName = args.nextString(); OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(playerName); if (offlinePlayer != null) { plugin.setPlayerSpawn(offlinePlayer, spawnLocation); if (offlinePlayer.isOnline() && plugin.hasSpawn(offlinePlayer)) { plugin.teleport(offlinePlayer.getPlayer(), plugin.getPlayerSpawn(offlinePlayer)); } } else { msg(sender, "user.info.player_not_found", name); } } else if (!plugin.config.lock_spawn || !plugin.hasSpawn(asPlayer(sender))) { Player player = asPlayer(sender); SpawnGUI spawnGUI = new SpawnGUI(this.plugin, player); spawnGUI.openGUI(player, 1); } else { msg(sender, "user.select.lock"); } }
@Override public void onExecute(String[] args, CommandSender sender) { FPlayer fPlayer = getFSenderOrFromArg(sender, args, 1); if (fPlayer != null) { ParsingUtil.sendMessage(sender, FMessage.CMD_POWER.getMessage(), fPlayer, fPlayer.getPower()); } }
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (command == null) return false; if (sender == null) return false; if (!command.getName().equalsIgnoreCase(getName())) return false; if (sender instanceof Player) { Player p = (Player) sender; PlayerData pd = plugin.getPD(p); if (pd == null || !pd.loadedSQL) { p.sendMessage(ChatColor.RED + "Please wait a moment while your data is loaded."); return true; } if (!pd.check(requiredRank)) { p.sendMessage(ChatColor.RED + "You don't have permission to use that command!"); return true; } execute(sender, args); executePlayer(p, pd, args); } else if (sender instanceof ConsoleCommandSender) { execute(sender, args); executeConsole(sender, args); } System.out.println("Executing /" + command.getName() + " for " + sender.getName() + " with args " + Arrays.toString(args)); return true; }
/** * Sends this message to multiple command senders. * @param senders The command senders who will receive the message. * @see #send(CommandSender) */ public void send(final Iterable<? extends CommandSender> senders) { String string = toJSONString(); for (final CommandSender sender : senders) { send(sender, string); } }
@Override public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) { if (args.length != 2) { return Collections.emptyList(); } EventType[] values = EventType.values(); List<String> results = new ArrayList<>(values.length); for (EventType eventType : values) { results.add(eventType.name()); } return results; }
public void call(CommandSender s, String label, String arg1) { if (!(s instanceof Player)) { OMGPI.wLog("Console can't ask for kits."); return; } for (OMGKit k : OMGKit.kits) if (k.getName().equalsIgnoreCase(arg1)) { OMGPI.g.player_request_kit(OMGPlayer.get((Player) s), k); return; } s.sendMessage(ChatColor.DARK_AQUA + "Cannot find team \"" + arg1 + "\"."); }
public Player senderToPlayer(CommandSender sender) throws CommandException { if(sender instanceof Player) { return (Player) sender; } else { throw new TranslatableCommandException("command.onlyPlayers"); } }
@CommandAlias("%cmd") public void onMainCommand(CommandSender sender) { sender.sendMessage("§3[§bRankVouchers§3] §7Running §bv%version% §7by §bfiver.io§7." .replace("%version%", Main.getInstance().getDescription().getVersion())); sender.sendMessage("§3[§bRankVouchers§3] §7Developer: §bChazmondo§7."); sender.sendMessage("§3[§bRankVouchers§3] §7Use §b/voucher help §7for commands."); }
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (!(sender instanceof Player)) { sender.sendMessage(ChatColor.RED + "This command is only executable by players."); return true; } Player player = (Player) sender; PlayerFaction playerFaction = plugin.getFactionManager().getPlayerFaction(player); if (playerFaction == null) { sender.sendMessage(ChatColor.RED + "You are not in a faction."); return true; } List<String> subclaimNames = new ArrayList<>(); for (Claim claim : playerFaction.getClaims()) { subclaimNames.addAll(claim.getSubclaims().stream().map(Subclaim::getName).collect(Collectors.toList())); } if (subclaimNames.isEmpty()) { sender.sendMessage(ChatColor.RED + "Your faction does not own any subclaims."); return true; } sender.sendMessage(ChatColor.YELLOW + "Factions' Subclaims (" + subclaimNames.size() + "): " + ChatColor.AQUA + StringUtils.join(subclaimNames, ", ")); return true; }
@Command(aliases = {"cancel"}, desc = "Cancel all countdowns.") @CommandPermissions({"tgm.cancel"}) public static void cancel(CommandContext cmd, CommandSender sender) { for (Countdown countdown : TGM.get().getModules(Countdown.class)) { countdown.cancel(); } sender.sendMessage(ChatColor.GREEN + "Countdowns cancelled."); }
@Override public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) { if (args.length != 2 || !(sender instanceof Player)) { return Collections.emptyList(); } VisualType[] values = VisualType.values(); List<String> results = new ArrayList<>(values.length); for (VisualType visualType : values) { results.add(visualType.name()); } return results; }
public void handle(@Nonnull CommandIssuer sender, @Nonnull List<String> args, @Nonnull Throwable e) { if (enableBugsnag) { bugsnag.notify(e, Severity.ERROR, (report) -> { report.addToTab(COMMAND_INFO_TAB, "sender", ((CommandSender) sender.getIssuer()).getName()); report.addToTab(COMMAND_INFO_TAB, "args", args.stream().collect(Collectors.joining(" "))); }); } log.info("Caught exception"); }
@Override public boolean execute(CommandSender sender, String label, String[] args) { if (McLink.instance.bot != null) { McLink.instance.bot.broadcast(String.join(" ", args)); } return true; }
@Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { Gamer g = Gamer.get(sender); if (g.getVariable("arena") == null) { Chat.player(sender, "&cYou are not in an arena!"); return true; } Arena a = (Arena) g.getVariable("arena"); a.leave(g.getPlayer()); g.teleport(Walls.getLobby().getSpawn()); Chat.player(sender, "&aYou have left your current match."); return true; }
@SneakyThrows static String had(CommandSender p, Iterator<String> itr) { try { ColorMapping mapping = ColorMapping.valueOf(join(itr)); int all = getBean((Player) p).getAllBuy(); int v = mapping.getValue(); return String.valueOf((all & v) == v); } catch (IllegalArgumentException ign) { } return "false"; }
public void details(CommandContext args, CommandSender sender, Destroyable destroyable) throws CommandException { List<String> lines = new ArrayList<>(); lines.add(ChatColor.GRAY + "Destroyable " + ChatColor.AQUA + destroyable.slug()); lines.add(formatProperty("name", destroyable.getName())); lines.add(formatProperty("owner", destroyable.getOwner().getColoredName())); lines.add(formatProperty("size", destroyable.getMaxHealth())); lines.add(formatProperty("completion", destroyable.getBreaksRequired() + " (" + destroyable.renderDestructionRequired() + ")")); sender.sendMessage(lines.toArray(new String[lines.size()])); }
@Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { try { WCCommands.onCmd(sender, cmd, label, args); } catch (Exception ex) { log(WCServer.Level.SEVERE, "Error al ejecutar el comando '" + label + Arrays.toString(args) + "'"); ex.printStackTrace(); } return true; }
public void newClientAuthKey(String username, CommandSender sender) { String token = new BigInteger(130, random).toString(32); playerAuthKeys.put(username, token); // TODO: persist to disk String url = publicURL + "#++" + username + "+" + token; if (clickableLinks && sender instanceof Player) { ClickableLinks.sendLink((Player) sender, url, clickableLinksTellraw); } else { sender.sendMessage("Visit this URL to login: " + url); } }
public boolean sendHelpMessage(CommandSender sender, String command) { try { StringBuilder helpMessage = new StringBuilder(); jcommander.usage(helpMessage); sender.sendMessage(helpMessage.toString()); return true; } catch (Exception exception) { plugin.getServer().getLogger().info("Something went wrong sending a help message."); return false; } }