Java Code Examples for org.bukkit.command.Command

The following examples show how to use org.bukkit.command.Command. These examples are extracted from open source projects. 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 Project: AACAdditionPro   Author: Photon-GitHub   File: MainCommand.java    License: GNU General Public License v3.0 7 votes vote down vote up
@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 Project: CraftserveRadiation   Author: Craftserve   File: RadiationCommandHandler.java    License: Apache License 2.0 6 votes vote down vote up
@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 #3
Source Project: ServerTutorial   Author: hawkfalcon   File: TutorialReload.java    License: MIT License 6 votes vote down vote up
@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 #4
Source Project: TrMenu   Author: Arasple   File: CommandRunAction.java    License: MIT License 6 votes vote down vote up
@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 #5
Source Project: LagMonitor   Author: games647   File: StackTraceCommand.java    License: MIT License 6 votes vote down vote up
@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 #6
Source Project: TrMenu   Author: Arasple   File: CommandDebug.java    License: MIT License 6 votes vote down vote up
@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 Project: UHC   Author: Eluinhost   File: RequestListCommand.java    License: MIT License 6 votes vote down vote up
@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 #8
@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 #9
Source Project: SuperVanish   Author: MyzelYam   File: Reload.java    License: Mozilla Public License 2.0 6 votes vote down vote up
@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 #10
Source Project: Kettle   Author: KettleFoundation   File: SpigotCommand.java    License: GNU General Public License v3.0 6 votes vote down vote up
@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 #11
Source Project: BungeePerms   Author: weaondara   File: BukkitPlugin.java    License: GNU General Public License v3.0 6 votes vote down vote up
@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 #12
Source Project: EntityAPI   Author: EntityAPIDev   File: EntityAPICore.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 #13
Source Project: ShopChest   Author: EpicEricEE   File: ShopCommand.java    License: MIT License 6 votes vote down vote up
@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 #14
Source Project: LagMonitor   Author: games647   File: LagCommand.java    License: MIT License 6 votes vote down vote up
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 #15
Source Project: helper   Author: lucko   File: CommandMapUtil.java    License: MIT License 6 votes vote down vote up
/**
 * 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 #16
Source Project: Hawk   Author: HawkAnticheat   File: MsgArgument.java    License: GNU General Public License v3.0 6 votes vote down vote up
@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 #17
@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 #18
Source Project: LagMonitor   Author: games647   File: LagCommand.java    License: MIT License 5 votes vote down vote up
public boolean canExecute(CommandSender sender, Command cmd) {
    if (!isCommandWhitelisted(cmd, sender)) {
        sendError(sender, "Command not whitelisted for you!");
        return false;
    }

    return true;
}
 
Example #19
Source Project: LittleBrother   Author: ljyloo   File: LBCommands.java    License: GNU General Public License v2.0 5 votes vote down vote up
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
		if (cmd.getName().equalsIgnoreCase("LittleBrother")) { 
			if (args.length == 0){
				sender.sendMessage(Language.find("help.command"));
				//sender.sendMessage("§a/LittleBrother version - Shows you the version of the plugin.");
				sender.sendMessage(Language.find("help.version"));
				sender.sendMessage(Language.find("help.status"));
				sender.sendMessage(Language.find("help.reload"));
				return true;
			} else if ((args.length == 1) && args[0].equalsIgnoreCase("version")) {
				// version
				sender.sendMessage("§c["+plugin.getDescription().getName() + "-Version] §3" + plugin.getDescription().getVersion());
				return true;
			} else if ((args.length == 1) && args[0].equalsIgnoreCase("status")) {
				//Motd = this.plugin.Motd;
				//port = this.plugin.port;
//				Motd = this.config.getConfig().getString("motd");
//				port = this.config.getConfig().getInt("port");
				Motd = this.config.getString("motd");
				port = this.config.getInt("port");
				sender.sendMessage(Language.find("status.motd") + " " + Motd);
				sender.sendMessage(Language.find("status.port") + " " + port);
				return true;
			} else if ((args.length == 1) && args[0].equalsIgnoreCase("reload")) {
				sender.sendMessage(Language.find("plugin.config.reload.process"));
				this.plugin.reloadConfig();
				//this.plugin.Msg.reloadConfig();
				//plugin.reloadConfig();
				sender.sendMessage("plugin.config.reload.done");
				return true;
			}
		}
		return false;
	}
 
Example #20
Source Project: RedProtect   Author: FabioZumbi12   File: SetMinYCommand.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
    List<String> tab = new ArrayList<>();
    if (args.length == 1)
        tab.add(sender instanceof Player ? String.valueOf(((Player) sender).getLocation().getBlockY()) : "0");
    if (args.length == 3)
        if (args[2].isEmpty())
            tab.addAll(Bukkit.getWorlds().stream().map(World::getName).collect(Collectors.toList()));
        else
            tab.addAll(Bukkit.getWorlds().stream().filter(w -> w.getName().startsWith(args[1])).map(World::getName).collect(Collectors.toList()));
    return tab;
}
 
Example #21
Source Project: FastLogin   Author: games647   File: CrackedCommand.java    License: MIT License 5 votes vote down vote up
private void onCrackedOther(CommandSender sender, Command command, String[] args) {
    if (!hasOtherPermission(sender, command)) {
        return;
    }

    if (forwardCrackedCommand(sender, args[0])) {
        return;
    }

    //todo: load async
    StoredProfile profile = plugin.getCore().getStorage().loadProfile(args[0]);
    if (profile == null) {
        sender.sendMessage("Error occurred");
        return;
    }

    //existing player is already cracked
    if (profile.isSaved() && !profile.isPremium()) {
        plugin.getCore().sendLocaleMessage("not-premium-other", sender);
    } else {
        plugin.getCore().sendLocaleMessage("remove-premium", sender);

        profile.setPremium(false);
        plugin.getScheduler().runAsync(() -> {
            plugin.getCore().getStorage().save(profile);
            plugin.getServer().getPluginManager().callEvent(
                    new BukkitFastLoginPremiumToggleEvent(profile, PremiumToggleReason.COMMAND_OTHER));
        });
    }
}
 
Example #22
Source Project: RedProtect   Author: FabioZumbi12   File: NearCommand.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (sender instanceof ConsoleCommandSender) {
        HandleHelpPage(sender, 1);
        return true;
    }

    Player player = (Player) sender;

    if (args.length == 0) {
        Set<Region> regions = RedProtect.get().rm.getRegionsNear(player, 60);
        if (regions.size() == 0) {
            RedProtect.get().lang.sendMessage(player, "cmdmanager.noregions.nearby");
        } else {
            Iterator<Region> i = regions.iterator();
            RedProtect.get().lang.sendMessage(player, RedProtect.get().lang.get("general.color") + "------------------------------------");
            RedProtect.get().lang.sendMessage(player, "cmdmanager.region.near");
            RedProtect.get().lang.sendMessage(player, RedProtect.get().lang.get("general.color") + "------------------------------------");
            while (i.hasNext()) {
                Region r = i.next();
                player.sendMessage(RedProtect.get().lang.get("cmdmanager.region.name") + r.getName() + RedProtect.get().lang.get("general.color") + ChatColor.translateAlternateColorCodes('&', " | Center (&6X,Z" + RedProtect.get().lang.get("general.color") + "): &6") + r.getCenterX() + ", " + r.getCenterZ());
            }
            RedProtect.get().lang.sendMessage(player, RedProtect.get().lang.get("general.color") + "------------------------------------");
        }
    }

    RedProtect.get().lang.sendCommandHelp(sender, "near", true);
    return true;
}
 
Example #23
Source Project: LagMonitor   Author: games647   File: MonitorCommand.java    License: MIT License 5 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!canExecute(sender, command)) {
        return true;
    }

    if (args.length > 0) {
        String monitorCommand = args[0].toLowerCase();
        switch (monitorCommand) {
            case "start":
                startMonitor(sender);
                break;
            case "stop":
                stopMonitor(sender);
                break;
            case "paste":
                pasteMonitor(sender);
                break;
            default:
                sendError(sender, "Invalid command parameter");
        }
    } else if (monitorTask == null) {
        sendError(sender, "Monitor is not running");
    } else {
        List<BaseComponent[]> lines = new ArrayList<>();
        synchronized (this) {
            MethodMeasurement rootSample = monitorTask.getRootSample();
            printTrace(lines, 0, rootSample, 0);
        }

        Pages pagination = new Pages("Monitor", lines);
        pagination.send(sender);
        this.plugin.getPageManager().setPagination(sender.getName(), pagination);
    }

    return true;
}
 
Example #24
Source Project: RedProtect   Author: FabioZumbi12   File: RemoveAdminCommand.java    License: GNU General Public License v3.0 5 votes vote down vote up
@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 #25
Source Project: FastLogin   Author: games647   File: PremiumCommand.java    License: MIT License 5 votes vote down vote up
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 #26
Source Project: LagMonitor   Author: games647   File: GraphCommand.java    License: MIT License 5 votes vote down vote up
@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 #27
Source Project: UhcCore   Author: Mezy   File: ReviveCommandExecutor.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
    if (args.length != 1 && args.length != 2){
        sender.sendMessage(ChatColor.RED + "Correct usage: '/revive <player>' or use '/revive <player> clear' to respawn the player without giving their items back.");
        return true;
    }

    if (GameManager.getGameManager().getGameState() != GameState.PLAYING){
        sender.sendMessage(ChatColor.RED + "You can only use this command while playing!");
        return true;
    }

    sender.sendMessage(ChatColor.GREEN + "Loading player data ...");

    String name = args[0];
    Player player = Bukkit.getPlayer(name);
    boolean spawnWithItems = args.length != 2 || !args[1].equalsIgnoreCase("clear");

    if (player != null){
        uuidCallback(player.getUniqueId(), player.getName(), spawnWithItems, sender);
        return true;
    }

    Bukkit.getScheduler().runTaskAsynchronously(UhcCore.getPlugin(), new Runnable() {
        @Override
        public void run() {
            uuidCallback(MojangUtils.getPlayerUuid(name), MojangUtils.getPlayerName(name), spawnWithItems, sender);
        }
    });

    return true;
}
 
Example #28
Source Project: EchoPet   Author: DSH105   File: EchoPetPlugin.java    License: GNU General Public License v3.0 5 votes vote down vote up
@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 #29
Source Project: civcraft   Author: netizen539   File: VoteCommand.java    License: GNU General Public License v2.0 5 votes vote down vote up
@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 #30
Source Project: FastAsyncWorldedit   Author: boy0001   File: BukkitCommand.java    License: GNU General Public License v3.0 5 votes vote down vote up
@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;
}