org.bukkit.command.Command Java Examples
The following examples show how to use
org.bukkit.command.Command.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainCommand.java From AACAdditionPro with GNU General Public License v3.0 | 7 votes |
@Override public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) { // Search for the deepest child command InternalCommand currentCommand = this; InternalCommand potentialChildCommand; int currentArgumentIndex = 0; while (currentArgumentIndex < args.length) { potentialChildCommand = currentCommand.childCommands.get(args[currentArgumentIndex].toLowerCase(Locale.ENGLISH)); if (potentialChildCommand == null) { // Stop looping once no child command was found. break; } currentCommand = potentialChildCommand; currentArgumentIndex++; } return currentArgumentIndex == args.length ? // No tab filtering as the player has not started typing currentCommand.getTabCompleteSupplier().getTabPossibilities() : // Player has started typing. currentCommand.getTabCompleteSupplier().getTabPossibilities(args[currentArgumentIndex]); }
Example #2
Source File: Reload.java From SuperVanish with Mozilla Public License 2.0 | 6 votes |
@Override public void execute(Command cmd, CommandSender p, String[] args, String label) { if (canDo(p, CommandAction.RELOAD, true)) { long before = System.currentTimeMillis(); plugin.reload(); if (!Bukkit.getPluginManager().isPluginEnabled(plugin)) { p.sendMessage(ChatColor.RED + "Failed to reload SuperVanish since it failed to restart itself. " + "More information is in the console. (" + (System.currentTimeMillis() - before) + "ms)"); return; } plugin.sendMessage(p, plugin.getMessage("PluginReloaded").replace("%time%", (System.currentTimeMillis() - before) + ""), p); } }
Example #3
Source File: RadiationCommandHandler.java From CraftserveRadiation with Apache License 2.0 | 6 votes |
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (!(sender instanceof Player)) { sender.sendMessage(ChatColor.RED + "Only players may execute this command."); return true; } Player player = (Player) sender; if (args.length > 0) { switch (args[0]) { case "potion": return onPotion(player); case "safe": return onSafe(player, label, args); } } sender.sendMessage(ChatColor.RED + command.getUsage()); return true; }
Example #4
Source File: BukkitPlugin.java From BungeePerms with GNU General Public License v3.0 | 6 votes |
@Override public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) { Runnable r = new Runnable() { @Override public void run() { if (!BukkitPlugin.this.onCommand(sender, cmd, label, args)) sender.sendMessage(Color.Error + "[BungeePerms] Command not found"); } }; if (conf.isAsyncCommands()) Bukkit.getScheduler().runTaskAsynchronously(instance, r); else r.run(); return true; }
Example #5
Source File: RequestListCommand.java From UHC with MIT License | 6 votes |
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { final List<TeamRequest> requests = requestManager.getRequests(); if (requests.size() == 0) { sender.sendMessage(messages.getRaw("no requests")); return true; } for (final TeamRequest request : requests) { final Map<String, Object> context = ImmutableMap.<String, Object>builder() .put("id", request.getId()) .put("name", request.getOwnerName()) .put("members", Joiner.on(", ").join(request.getOthers())) .build(); sender.sendMessage(messages.evalTemplate("list request", context)); } return true; }
Example #6
Source File: CommandDebug.java From TrMenu with MIT License | 6 votes |
@Override public void onCommand(CommandSender sender, Command command, String label, String[] args) { if (sender instanceof Player) { Player player = (Player) sender; if (player.hasMetadata("TrMenu-Debug")) { player.removeMetadata("TrMenu-Debug", TrMenu.getPlugin()); sender.sendMessage("§7Canceled..."); } else { player.setMetadata("TrMenu-Debug", new FixedMetadataValue(TrMenu.getPlugin(), "")); sender.sendMessage("§aEnabled..."); } return; } sender.sendMessage("§3--------------------------------------------------"); sender.sendMessage(""); sender.sendMessage("§2Total Menus: §6" + TrMenuAPI.getMenus().size()); sender.sendMessage("§2Cached Skulls: §6" + Skulls.getSkulls().size()); sender.sendMessage("§2Running Tasks: §6" + Bukkit.getScheduler().getActiveWorkers().stream().filter(t -> t.getOwner() == TrMenu.getPlugin()).count() + Bukkit.getScheduler().getPendingTasks().stream().filter(t -> t.getOwner() == TrMenu.getPlugin()).count()); sender.sendMessage("§2Metrics: §6" + MetricsHandler.getMetrics().isEnabled()); sender.sendMessage("§2TabooLib: §f" + Plugin.getVersion()); sender.sendMessage(""); sender.sendMessage("§2TrMenu Built-Time: §b" + YamlConfiguration.loadConfiguration(new InputStreamReader(Files.getResource(TrMenu.getPlugin(), "plugin.yml"))).getString("built-time", "Null")); sender.sendMessage(""); sender.sendMessage("§3--------------------------------------------------"); }
Example #7
Source File: SpigotCommand.java From Kettle with GNU General Public License v3.0 | 6 votes |
@Override public boolean execute(CommandSender sender, String commandLabel, String[] args) { if (!testPermission(sender)) return true; if (args.length != 1) { sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage); return false; } if (args[0].equals("reload")) { Command.broadcastCommandMessage(sender, ChatColor.RED + "Please note that this command is not supported and may cause issues."); Command.broadcastCommandMessage(sender, ChatColor.RED + "If you encounter any issues please use the /stop command to restart your server."); MinecraftServer console = MinecraftServer.getServerCB(); org.spigotmc.SpigotConfig.init((File) console.options.valueOf("spigot-settings")); for (WorldServer world : console.worlds) { world.spigotConfig.init(); } console.server.reloadCount++; Command.broadcastCommandMessage(sender, ChatColor.GREEN + "Reload complete."); } return true; }
Example #8
Source File: MsgArgument.java From Hawk with GNU General Public License v3.0 | 6 votes |
@Override public boolean process(CommandSender sender, Command cmd, String label, String[] args) { if (args.length < 3) return false; Player target = Bukkit.getPlayer(args[1]); if (target == null) { sender.sendMessage(ChatColor.RED + "Unknown player \"" + args[1] + "\""); return true; } List<String> list = new LinkedList<>(Arrays.asList(args)); list.remove(0); list.remove(0); String msg = Hawk.FLAG_PREFIX + ChatColor.translateAlternateColorCodes('&', String.join(" ", list)); target.sendMessage(msg); sender.sendMessage(ChatColor.GOLD + "Sent message to " + target.getName() + "."); return true; }
Example #9
Source File: StackTraceCommand.java From LagMonitor with MIT License | 6 votes |
@Override public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) { List<String> result = new ArrayList<>(); StringBuilder builder = new StringBuilder(); for (String arg : args) { builder.append(arg).append(' '); } String requestName = builder.toString(); ThreadInfo[] threads = ManagementFactory.getThreadMXBean().dumpAllThreads(false, false); return Arrays.stream(threads) .map(ThreadInfo::getThreadName) .filter(name -> name.startsWith(requestName)) .sorted(String.CASE_INSENSITIVE_ORDER) .collect(Collectors.toList()); }
Example #10
Source File: CommandRunAction.java From TrMenu with MIT License | 6 votes |
@Override public void onCommand(CommandSender sender, Command command, String label, String[] args) { Player player = Bukkit.getPlayerExact(args[0].startsWith("#") ? args[0].substring(1) : args[0]); if (player == null || !player.isOnline()) { TLocale.sendTo(sender, "COMMANDS.NO-PLAYER"); return; } String actionString = ArrayUtil.arrayJoin(args, 1); boolean print = args[0].startsWith("#"); TrAction.readActions(actionString).forEach(action -> { if (print) { player.sendMessage("§7Action Details: §3" + action.toString()); } action.run(player); }); }
Example #11
Source File: CommandMapUtil.java From helper with MIT License | 6 votes |
/** * Unregisters a CommandExecutor with the server * * @param command the command instance * @param <T> the command executor class type * @return the command executor */ @Nonnull public static <T extends CommandExecutor> T unregisterCommand(@Nonnull T command) { CommandMap map = getCommandMap(); try { //noinspection unchecked Map<String, Command> knownCommands = (Map<String, Command>) KNOWN_COMMANDS_FIELD.get(map); Iterator<Command> iterator = knownCommands.values().iterator(); while (iterator.hasNext()) { Command cmd = iterator.next(); if (cmd instanceof PluginCommand) { CommandExecutor executor = ((PluginCommand) cmd).getExecutor(); if (command == executor) { cmd.unregister(map); iterator.remove(); } } } } catch (Exception e) { throw new RuntimeException("Could not unregister command", e); } return command; }
Example #12
Source File: PerworldInventoryCommandHandlingTest.java From PerWorldInventory with GNU General Public License v3.0 | 6 votes |
@Test public void shouldRunConvertCommand() { // given CommandSender sender = mock(CommandSender.class); Command command = newCommandWithName("Pwi"); given(convertCommand.getRequiredPermission()).willCallRealMethod(); given(permissionManager.hasPermission(sender, AdminPermission.CONVERT)).willReturn(true); // when boolean result = plugin.onCommand(sender, command, "pwi", "convert", "abc", "def"); // then assertThat(result, equalTo(true)); verify(permissionManager).hasPermission(sender, AdminPermission.CONVERT); verify(convertCommand).executeCommand(sender, Arrays.asList("abc", "def")); }
Example #13
Source File: PerworldInventoryCommandHandlingTest.java From PerWorldInventory with GNU General Public License v3.0 | 6 votes |
@Test public void shouldRunConvertCommand() { // given CommandSender sender = mock(CommandSender.class); Command command = newCommandWithName("Pwi"); given(convertCommand.getRequiredPermission()).willCallRealMethod(); given(permissionManager.hasPermission(sender, AdminPermission.CONVERT)).willReturn(true); // when boolean result = plugin.onCommand(sender, command, "pwi", "convert", "abc", "def"); // then assertThat(result, equalTo(true)); verify(permissionManager).hasPermission(sender, AdminPermission.CONVERT); verify(convertCommand).executeCommand(sender, Arrays.asList("abc", "def")); }
Example #14
Source File: TutorialReload.java From ServerTutorial with MIT License | 6 votes |
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (!Permissions.RELOAD.hasPerm(sender)) { sender.sendMessage(ChatColor.RED + "You don't have permission for this!"); return true; } for (String playerName : TutorialManager.getManager().getAllInTutorial()) { Player player = plugin.getServer().getPlayer(playerName); plugin.getEndTutorial().reloadEndTutorial(player); } Caching.getCaching().reCasheTutorials(); Caching.getCaching().reCacheConfigs(); Caching.getCaching().reCachePlayerData(); Caching.getCaching().reCacheTempPlayerData(); sender.sendMessage(ChatColor.RED + "Server Tutorial Reloaded!"); return true; }
Example #15
Source File: ShopCommand.java From ShopChest with MIT License | 6 votes |
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (args.length > 0) { for (ShopSubCommand subCommand : subCommands) { if (subCommand.getName().equalsIgnoreCase(args[0])) { if (!(sender instanceof Player) && subCommand.isPlayerCommand()) { sender.sendMessage(ChatColor.RED + "Only players can use this command."); return true; } if (!subCommand.execute(sender, command, label, args)) { sendBasicHelpMessage(sender); } return true; } } sendBasicHelpMessage(sender); } else { sendBasicHelpMessage(sender); } return true; }
Example #16
Source File: LagCommand.java From LagMonitor with MIT License | 6 votes |
private boolean isCommandWhitelisted(Command cmd, CommandSender sender) { if (!(sender instanceof Player)) { return true; } FileConfiguration config = plugin.getConfig(); Collection<String> aliases = new ArrayList<>(cmd.getAliases()); aliases.add(cmd.getName()); for (String alias : aliases) { List<String> aliasWhitelist = config.getStringList("whitelist-" + alias); if (!aliasWhitelist.isEmpty()) { return aliasWhitelist.contains(sender.getName()); } } //whitelist doesn't exist return true; }
Example #17
Source File: EntityAPICore.java From EntityAPI with GNU Lesser General Public License v3.0 | 6 votes |
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (label.equalsIgnoreCase("entityapi")) { if (args.length == 0) { sender.sendMessage(ChatColor.GOLD + "EntityAPI v" + this.getDescription().getVersion() + " by " + StringUtil.join(this.getDescription().getAuthors(), ", ")); return true; } else if (args.length == 1) { if (args[0].equalsIgnoreCase("update")) { if (sender.hasPermission("entityapi.update")) { if (updateChecked) { new Updater(this, 74914, this.getFile(), Updater.UpdateType.NO_VERSION_CHECK, true); return true; } else { sender.sendMessage(ChatColor.GOLD + "An update is not available."); return true; } } } } } return false; }
Example #18
Source File: RemoveAdminCommand.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@Override public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) { if (sender instanceof Player) { Region r = RedProtect.get().rm.getTopRegion(((Player) sender).getLocation()); if (r != null && args.length == 1) { if (args[0].isEmpty()) return r.getAdmins().stream().map(PlayerRegion::getPlayerName).collect(Collectors.toList()); else return r.getAdmins().stream().filter(p -> p.getPlayerName().toLowerCase().startsWith(args[0].toLowerCase())).map(PlayerRegion::getPlayerName).collect(Collectors.toList()); } } return new ArrayList<>(); }
Example #19
Source File: EchoPetPlugin.java From EchoPet with GNU General Public License v3.0 | 5 votes |
@Override public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { if (commandLabel.equalsIgnoreCase("ecupdate")) { if (sender.hasPermission("echopet.update")) { if (updateChecked) { @SuppressWarnings("unused") Updater updater = new Updater(this, 53655, this.getFile(), Updater.UpdateType.NO_VERSION_CHECK, true); return true; } else { sender.sendMessage(this.prefix + ChatColor.GOLD + " An update is not available."); return true; } } else { Lang.sendTo(sender, Lang.NO_PERMISSION.toString().replace("%perm%", "echopet.update")); return true; } } else if (commandLabel.equalsIgnoreCase("echopet")) { if (sender.hasPermission("echopet.petadmin")) { PluginDescriptionFile pdFile = this.getDescription(); sender.sendMessage(ChatColor.RED + "-------- EchoPet --------"); sender.sendMessage(ChatColor.GOLD + "Author: " + ChatColor.YELLOW + "DSH105"); sender.sendMessage(ChatColor.GOLD + "Version: " + ChatColor.YELLOW + pdFile.getVersion()); sender.sendMessage(ChatColor.GOLD + "Website: " + ChatColor.YELLOW + pdFile.getWebsite()); sender.sendMessage(ChatColor.GOLD + "Commands are registered at runtime to provide you with more dynamic control over the command labels."); sender.sendMessage(ChatColor.GOLD + "" + ChatColor.UNDERLINE + "Command Registration:"); sender.sendMessage(ChatColor.GOLD + "Main: " + this.OPTIONS.getCommandString()); sender.sendMessage(ChatColor.GOLD + "Admin: " + this.OPTIONS.getCommandString() + "admin"); } else { Lang.sendTo(sender, Lang.NO_PERMISSION.toString().replace("%perm%", "echopet.petadmin")); return true; } } return false; }
Example #20
Source File: GraphCommand.java From LagMonitor with MIT License | 5 votes |
@Override public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) { if (args.length != 1) { return Collections.emptyList(); } String lastArg = args[args.length - 1]; return graphTypes.keySet().stream() .filter(type -> type.startsWith(lastArg)) .sorted(String.CASE_INSENSITIVE_ORDER) .collect(toList()); }
Example #21
Source File: MigrateCommand.java From Statz with GNU General Public License v3.0 | 5 votes |
@Override public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) { if (args.length < 2) { sender.sendMessage(Lang.INCORRECT_COMMAND_USAGE.getConfigValue(this.getUsage())); return true; } if (args[1].equalsIgnoreCase("stats3")) { // This type is no longer supported. sender.sendMessage(org.bukkit.ChatColor.RED + "This migration type is no longer supported."); } else if (args[1].equalsIgnoreCase("minecraft")) { plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() { @Override public void run() { try { int importedPlayers = plugin.getImportManager().importFromVanilla().get(); sender.sendMessage(ChatColor.GREEN + "Imported statistics of " + importedPlayers + " players."); } catch (InterruptedException | ExecutionException e) { sender.sendMessage(ChatColor.RED + "Could not import data from Minecraft!"); e.printStackTrace(); } } }); } else { sender.sendMessage(org.bukkit.ChatColor.RED + "You provided an invalid migration type. You can only use " + "'stats3' or 'minecraft'."); } return true; }
Example #22
Source File: TimingCommand.java From LagMonitor with MIT License | 5 votes |
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (!canExecute(sender, command)) { return true; } if (isTimingsEnabled()) { sendError(sender,"The server deactivated timing reports"); sendError(sender,"Go to paper.yml or spigot.yml and activate timings"); return true; } return true; }
Example #23
Source File: ShowHelp.java From SuperVanish with Mozilla Public License 2.0 | 5 votes |
@Override public void execute(Command cmd, CommandSender sender, String[] args, String label) { if (canDo(sender, CommandAction.SHOW_HELP, true)) { plugin.sendMessage(sender, "HelpHeader", sender); for (CommandAction action : CommandAction.values()) { if (canDo(sender, action, false)) { plugin.sendMessage(sender, plugin.getMessage("HelpFormat") .replace("%usage%", action.getUsage()) .replace("%description%", action.getDescription()) .replace("%permission%", action.getMainPermission()), sender); } } } }
Example #24
Source File: NoDatabaseWorker.java From Minepacks with GNU General Public License v3.0 | 5 votes |
@Override public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command cmd, @NotNull String s, String[] strings) { if(strings.length != 1 || !strings[0].equalsIgnoreCase("reload")) { commandSender.sendMessage(MessageColor.RED + "Only \"/backpack reload\" is available at the moment!"); } else { if(commandSender.hasPermission(Permissions.RELOAD)) { command.unregisterCommand(); HandlerList.unregisterAll(this); try { plugin.getConfiguration().reload(); Reflection.getMethod(plugin.getClass(), "load").invoke(plugin); } catch(Exception e) { e.printStackTrace(); } } else { commandSender.sendMessage(MessageColor.RED + "You don't have the permission to do that!"); } } return true; }
Example #25
Source File: BukkitCommand.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Override public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) { final FawePlayer plr = Fawe.imp().wrap(sender); if (!sender.hasPermission(this.cmd.getPerm()) && !sender.isOp()) { BBC.NO_PERM.send(plr, this.cmd.getPerm()); return true; } this.cmd.executeSafe(plr, args); return true; }
Example #26
Source File: VoteCommand.java From civcraft with GNU General Public License v2.0 | 5 votes |
@Override public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { if (args.length < 1) { CivMessage.sendError(sender, "/vote [civ name] - votes for your favorite civ for a diplomatic victory!"); return false; } if (sender instanceof Player) { Player player = (Player)sender; Resident resident = CivGlobal.getResident(player); if (!resident.hasTown()) { CivMessage.sendError(sender, "You must be a member of a town in order to cast a vote."); return false; } Civilization civ = CivGlobal.getCiv(args[0]); if (civ == null) { CivMessage.sendError(sender, "Couldn't find eligable civ named '"+args[0]+"'."); return false; } if (!EndConditionDiplomacy.canPeopleVote()) { CivMessage.sendError(sender, "Council of Eight not yet built. Cannot vote for civs until then."); return false; } EndConditionDiplomacy.addVote(civ, resident); return true; } else { return false; } }
Example #27
Source File: CommandFramework.java From ChestCommands with GNU General Public License v3.0 | 5 votes |
/** * Default implementation of Bukkit's command executor. */ @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { try { execute(sender, label, args); } catch (CommandException ex) { if (ex.getMessage() != null && !ex.getMessage().isEmpty()) { // Use RED by default sender.sendMessage(ChatColor.RED + ex.getMessage()); } } return true; }
Example #28
Source File: PremiumCommand.java From FastLogin with MIT License | 5 votes |
private void onPremiumSelf(CommandSender sender, Command cmd, String[] args) { if (isConsole(sender)) { return; } if (forwardPremiumCommand(sender, sender.getName())) { return; } UUID id = ((Player) sender).getUniqueId(); if (plugin.getConfig().getBoolean("premium-warning") && !plugin.getCore().getPendingConfirms().contains(id)) { sender.sendMessage(plugin.getCore().getMessage("premium-warning")); plugin.getCore().getPendingConfirms().add(id); return; } plugin.getCore().getPendingConfirms().remove(id); //todo: load async StoredProfile profile = plugin.getCore().getStorage().loadProfile(sender.getName()); if (profile.isPremium()) { plugin.getCore().sendLocaleMessage("already-exists", sender); } else { //todo: resolve uuid profile.setPremium(true); plugin.getScheduler().runAsync(() -> { plugin.getCore().getStorage().save(profile); plugin.getServer().getPluginManager().callEvent( new BukkitFastLoginPremiumToggleEvent(profile, PremiumToggleReason.COMMAND_SELF)); }); plugin.getCore().sendLocaleMessage("add-premium", sender); } }
Example #29
Source File: GraphCommand.java From LagMonitor with MIT License | 5 votes |
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (!canExecute(sender, command)) { return true; } if (sender instanceof Player) { Player player = (Player) sender; if (args.length > 0) { if (args.length > 1) { buildCombinedGraph(player, args); } else { String graph = args[0]; GraphRenderer renderer = graphTypes.get(graph); if (renderer == null) { sendError(sender, "Unknown graph type"); } else { giveMap(player, installRenderer(player, renderer)); } } return true; } //default is heap usage GraphRenderer graphRenderer = graphTypes.get("heap"); MapView mapView = installRenderer(player, graphRenderer); giveMap(player, mapView); } else { sendError(sender, "Not implemented for the console"); } return true; }
Example #30
Source File: RemoveMemberCommand.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (args.length == 3 && (sender instanceof ConsoleCommandSender || RedProtect.get().ph.hasPerm(sender, "redprotect.command.admin.removemember"))) { World w = RedProtect.get().getServer().getWorld(args[2]); if (w == null) { RedProtect.get().lang.sendMessage(sender, RedProtect.get().lang.get("cmdmanager.region.invalidworld")); return true; } Region r = RedProtect.get().rm.getRegion(args[1], w.getName()); if (r == null) { RedProtect.get().lang.sendMessage(sender, RedProtect.get().lang.get("cmdmanager.region.doesntexist") + ": " + args[1]); return true; } handleRemoveMember(sender, args[0], r); return true; } else if (sender instanceof Player) { Player player = (Player) sender; if (args.length == 1) { handleRemoveMember(player, args[0], null); return true; } } RedProtect.get().lang.sendCommandHelp(sender, "removemember", true); return true; }