Java Code Examples for org.bukkit.command.Command

The following are top voted examples for showing how to use org.bukkit.command.Command. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Lukkit   File: CommandPluginList.java   Source Code and License 7 votes vote down vote up
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
    if (command.getName().equals("luaplugins")) {
        if (!commandSender.hasPermission("lukkitplus.listpl")) {
            commandSender.sendMessage(ChatColor.RED + "Sorry, you don't have permission.");
            return true;
        }
        StringBuilder pluginSentence = new StringBuilder();
        int index = 0;
        for (LuaPlugin plugin : Environment.PLUGINS) {
            if (index != (Environment.PLUGINS.size() - 1)) {
                pluginSentence.append(plugin.getName() + ", ");
            } else {
                pluginSentence.append(plugin.getName() + "");
            }
            index++;
        }
        commandSender.sendMessage("Plugins: " + ChatColor.GREEN + pluginSentence.toString());
        return true;
    }
    return false;
}
 
Example 2
Project: HCFCore   File: ReviveCommand.java   Source Code and License 6 votes vote down vote up
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
    if (args.length < 1) {
        sender.sendMessage(ChatColor.RED + "Usage: /" + label + " <playerName>");
        return true;
    }
    final OfflinePlayer target = Bukkit.getOfflinePlayer(args[0]);
    if (!target.hasPlayedBefore() && !target.isOnline()) {
        sender.sendMessage(ChatColor.GOLD + "Player '" + ChatColor.WHITE + args[0] + ChatColor.GOLD + "' not found.");
        return true;
    }
    final UUID targetUUID = target.getUniqueId();
    final FactionUser factionTarget = HCF.getPlugin().getUserManager().getUser(targetUUID);
    final Deathban deathban = factionTarget.getDeathban();
    if (deathban == null || !deathban.isActive()) {
        sender.sendMessage(ChatColor.RED + target.getName() + " is not death-banned.");
        return true;
    }
    factionTarget.removeDeathban();
    Command.broadcastCommandMessage(sender, ChatColor.LIGHT_PURPLE + "A staff has revived " + target.getName() + ".");
    return false;
}
 
Example 3
Project: HCFCore   File: LivesReviveArgument.java   Source Code and License 6 votes vote down vote up
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
    if (args.length != 2) {
        return Collections.emptyList();
    }

    List<String> results = new ArrayList<>();
    Collection<FactionUser> factionUsers = plugin.getUserManager().getUsers().values();
    for (FactionUser factionUser : factionUsers) {
        Deathban deathban = factionUser.getDeathban();
        if (deathban == null || !deathban.isActive())
            continue;

        OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(factionUser.getUserUUID());
        String offlineName = offlinePlayer.getName();
        if (offlineName != null) {
            results.add(offlinePlayer.getName());
        }
    }

    return results;
}
 
Example 4
Project: HCFCore   File: FactionAllyArgument.java   Source Code and License 6 votes vote down vote up
@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;
}
 
Example 5
Project: CustomRecipes   File: ListRecipesCommandExecutor.java   Source Code and License 6 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
	if (args.length == 0) return false;
	
	String recipeType = args[0];
	List<? extends Recipe> recipes = recipesByTypeMapper.apply(recipeType);
	
	if (recipes == null) {
		sender.sendMessage(ChatColor.RED + "Unknown recipe type: " + recipeType);
		return true;
	} else if (recipes.isEmpty()) {
		sender.sendMessage(ChatColor.RED + "No recipes found for type: " + recipeType);
		return true;
	}
	
	return sender instanceof Player ? listPlayer((Player) sender, recipeType, recipes) : listSender(sender, recipeType, recipes);
}
 
Example 6
Project: HCFCore   File: StaffReviveCommand.java   Source Code and License 6 votes vote down vote up
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
    if (args.length != 1) {
        return Collections.emptyList();
    }

    List<String> results = new ArrayList<>();
    for (FactionUser factionUser : plugin.getUserManager().getUsers().values()) {
        Deathban deathban = factionUser.getDeathban();
        if (deathban != null && deathban.isActive()) {
            OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(factionUser.getUserUUID());
            String name = offlinePlayer.getName();
            if (name != null) {
                results.add(name);
            }
        }
    }

    return BukkitUtils.getCompletions(args, results);
}
 
Example 7
Project: ProtocolSupportPocketStuff   File: CommandHandler.java   Source Code and License 6 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
	if (!sender.hasPermission("protocolsupport.admin")) {
		sender.sendMessage(ChatColor.DARK_RED + "You have no power here!");
		return true;
	}
	if (args.length == 0) {
		sender.sendMessage(ChatColor.DARK_PURPLE + "ProtocolSupportPocketStuff");
		sender.sendMessage(ChatColor.GRAY + "/psps reloadpacks");
		return true;
	}
	SubCommand subcommand = subcommands.get(args[0]);
	if (subcommand == null) {
		return false;
	}
	String[] subcommandargs = Arrays.copyOfRange(args, 1, args.length);
	if (subcommandargs.length < subcommand.getMinArgs()) {
		sender.sendMessage(ChatColor.DARK_RED + "Not enough args");
		return true;
	}
	return subcommand.handle(sender, subcommandargs);
}
 
Example 8
Project: HCFCore   File: ReviveCommand.java   Source Code and License 6 votes vote down vote up
public List<String> onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) {
    if (args.length != 1) {
        return Collections.emptyList();
    }
    final List<String> results = new ArrayList<String>();
    for (final FactionUser factionUser : this.plugin.getUserManager().getUsers().values()) {
        final Deathban deathban = factionUser.getDeathban();
        if (deathban != null && deathban.isActive()) {
            final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(factionUser.getUserUUID());
            final String name = offlinePlayer.getName();
            if (name == null) {
                continue;
            }
            results.add(name);
        }
    }
    return BukkitUtils.getCompletions(args, results);
}
 
Example 9
Project: NeverLag   File: MonitorUtils.java   Source Code and License 6 votes vote down vote up
public static Map<String, MonitorRecord> getCommandTimingsByPlugin(Plugin plg) {
	Map<String, MonitorRecord> record = new HashMap<>();
	if (plg == null) {
		return record;
	}
	try {
		SimpleCommandMap simpleCommandMap = Reflection.getField(SimplePluginManager.class, "commandMap", SimpleCommandMap.class).get(Bukkit.getPluginManager());
		for (Command command : simpleCommandMap.getCommands()) {
			if (command instanceof PluginCommand) {
				PluginCommand pluginCommand = (PluginCommand) command;
				if (plg.equals(pluginCommand.getPlugin())) {
					FieldAccessor<CommandExecutor> commandField = Reflection.getField(PluginCommand.class, "executor", CommandExecutor.class);
					CommandExecutor executor = commandField.get(pluginCommand);
					if (executor instanceof CommandInjector) {
						CommandInjector commandInjector = (CommandInjector) executor;
						record = mergeRecordMap(record, commandInjector.getMonitorRecordMap());
					}

				}
			}
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	return record;
}
 
Example 10
Project: RPGPlus   File: StatsGUI.java   Source Code and License 6 votes vote down vote up
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
 {
  Player p = (Player) sender;
  if(label.equalsIgnoreCase("stats")){
   if (args.length == 0)
   {
   openStatsGUI(p);
   
   }else if(args.length == 1){
   	Player playerStat = (Player) Bukkit.getPlayer(args[0]);
   	if(playerStat != null){
   		// openStatsGUIOtherPlayer(playerStat, p);
   	}else{
   		p.sendMessage(ChatColor.RED + args[0] + " is not a valid player. You can only view stats of online players.");
   	}
   }
return false;
     
  }
return false;
 }
 
Example 11
Project: DragonEggDrop   File: DragonTemplateCmd.java   Source Code and License 6 votes vote down vote up
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
	List<String> options = new ArrayList<>();
	
	// Before completion: "/dragontemplate "
	if (args.length == 1) {
		options.add("list");
		plugin.getDEDManager().getDragonTemplates().stream().map(DragonTemplate::getIdentifier).forEach(t -> options.add(t));
	}
	
	// Before completion: "/dragontemplate <template> "
	else if (args.length == 2) {
		options.add("view");
		options.add("edit");
	}
	
	else if (args.length == 3) {
		// Before completion: "/dragontemplate <template> edit "
		if (args[1].equalsIgnoreCase("edit")) {
			options.add("addloot");
			options.add("set");
		}
	}
	
	return options;
}
 
Example 12
Project: HCFCore   File: FactionAllyArgument.java   Source Code and License 6 votes vote down vote up
@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;
}
 
Example 13
Project: MeerChat   File: PlayerCommandListener.java   Source Code and License 6 votes vote down vote up
@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;
}
 
Example 14
Project: Arcadia-Spigot   File: SpectateCommand.java   Source Code and License 6 votes vote down vote up
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
    if(s.equalsIgnoreCase("spec")) {
        if(!(commandSender instanceof Player)) {
            commandSender.sendMessage(ChatColor.RED + "You must be a player to execute this command.");
            return false;
        }
        Player player = (Player) commandSender;
        ArcadiaAPI api = Arcadia.getPlugin(Arcadia.class).getAPI();
        api.getGameManager().setSpectating(player, !api.getGameManager().isSpectating(player));
        if(api.getGameManager().isSpectating(player)) {
            api.getTranslationManager().sendTranslation("command.spec.enabled", player);
        } else {
            api.getTranslationManager().sendTranslation("command.spec.disabled", player);
        }
        if(api.getGameManager().getCurrentGame() != null) {
            if(!api.getGameManager().getCurrentGame().spectatorCache.contains(player)) {
                api.getGameManager().getCurrentGame().spectatorCache.add(player);
            }
        }
    }
    return false;
}
 
Example 15
Project: AutoMessageDisplayer   File: CommandAmdRandom.java   Source Code and License 6 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
	Player p = (Player)sender;
	if(p.hasPermission("automessagedisplayer.setrandom")||p.isOp()) {
		if(args.length >= 1) {
			Boolean randomEnabled = Boolean.parseBoolean(args[0]);
			plugin.getConfig().set(RANDOM_CONFIG, randomEnabled);
			if(randomEnabled) {
				p.sendMessage("�2Random enabled. Do /reload");
			} else {
				p.sendMessage("�4Random disabled. Do /reload");
			}
			plugin.saveConfig();
			plugin.reloadConfig();
			return true;
		}
	}

	return false;
}
 
Example 16
Project: HCFCore   File: EventStartArgument.java   Source Code and License 6 votes vote down vote up
@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;
    }

    Faction faction = plugin.getFactionManager().getFaction(args[1]);

    if (!(faction instanceof EventFaction)) {
        sender.sendMessage(ChatColor.RED + "There is not an event faction named '" + args[1] + "'.");
        return true;
    }

    if (plugin.getTimerManager().getEventTimer().tryContesting(((EventFaction) faction), sender)) {
        sender.sendMessage(ChatColor.YELLOW + "Successfully contested " + faction.getName() + '.');
    }

    return true;
}
 
Example 17
Project: HCFCore   File: FactionSubclaimDeleteArgument.java   Source Code and License 6 votes vote down vote up
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
    if (args.length != 3 || !(sender instanceof Player)) {
        return Collections.emptyList();
    }

    Player player = (Player) sender;
    PlayerFaction playerFaction = plugin.getFactionManager().getPlayerFaction(player);
    if (playerFaction == null || playerFaction.getMember(player.getUniqueId()).getRole() == Role.MEMBER) {
        return Collections.emptyList();
    }

    List<String> results = new ArrayList<>();
    for (Claim claim : playerFaction.getClaims()) {
        results.addAll(claim.getSubclaims().stream().map(Subclaim::getName).collect(Collectors.toList()));
    }

    return results;
}
 
Example 18
Project: HCFCore   File: FactionSetDtrRegenArgument.java   Source Code and License 6 votes vote down vote up
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
    if (args.length != 2) {
        return Collections.emptyList();
    } else if (args[1].isEmpty()) {
        return null;
    } else {
        List<String> results = new ArrayList<>(plugin.getFactionManager().getFactionNameMap().keySet());
        Player senderPlayer = sender instanceof Player ? ((Player) sender) : null;
        for (Player player : Bukkit.getOnlinePlayers()) {
            // Make sure the player can see.
            if (senderPlayer == null || senderPlayer.canSee(player)) {
                results.add(player.getName());
            }
        }

        return results;
    }
}
 
Example 19
Project: HCFCore   File: FactionLeaderArgument.java   Source Code and License 6 votes vote down vote up
@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 || (playerFaction.getMember(player.getUniqueId()).getRole() != Role.LEADER)) {
        return Collections.emptyList();
    }

    List<String> results = new ArrayList<>();
    Map<UUID, FactionMember> members = playerFaction.getMembers();
    for (Map.Entry<UUID, FactionMember> entry : members.entrySet()) {
        if (entry.getValue().getRole() != Role.LEADER) {
            OfflinePlayer target = Bukkit.getOfflinePlayer(entry.getKey());
            String targetName = target.getName();
            if (targetName != null && !results.contains(targetName)) {
                results.add(targetName);
            }
        }
    }

    return results;
}
 
Example 20
Project: HCFCore   File: LivesSetArgument.java   Source Code and License 6 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (args.length < 3) {
        sender.sendMessage(ChatColor.RED + "Usage: " + getUsage(label));
        return true;
    }

    Integer amount = JavaUtils.tryParseInt(args[2]);

    if (amount == null) {
        sender.sendMessage(ChatColor.RED + "'" + args[2] + "' is not a number.");
        return true;
    }

    OfflinePlayer target = BukkitUtils.offlinePlayerWithNameOrUUID(args[1]);

    if (!target.hasPlayedBefore() && !target.isOnline()) {
        sender.sendMessage(String.format(BaseConstants.PLAYER_WITH_NAME_OR_UUID_NOT_FOUND, args[1]));
        return true;
    }

    plugin.getDeathbanManager().setLives(target.getUniqueId(), amount);

    sender.sendMessage(ChatColor.YELLOW + target.getName() + " now has " + ChatColor.GOLD + amount + ChatColor.YELLOW + " lives.");
    return true;
}
 
Example 21
Project: HCFCore   File: FactionSubclaimMembersArgument.java   Source Code and License 6 votes vote down vote up
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
    if (args.length != 3 || !(sender instanceof Player)) {
        return Collections.emptyList();
    }

    Player player = (Player) sender;
    PlayerFaction playerFaction = plugin.getFactionManager().getPlayerFaction(player);
    if (playerFaction == null || playerFaction.getMember(player.getUniqueId()).getRole() == Role.MEMBER) {
        return Collections.emptyList();
    }

    List<String> results = new ArrayList<>();
    for (Claim claim : playerFaction.getClaims()) {
        results.addAll(claim.getSubclaims().stream().map(Subclaim::getName).collect(Collectors.toList()));
    }

    return results;
}
 
Example 22
Project: HCFCore   File: FactionInviteArgument.java   Source Code and License 6 votes vote down vote up
@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 || (playerFaction.getMember(player.getUniqueId()).getRole() == Role.MEMBER)) {
        return Collections.emptyList();
    }

    List<String> results = new ArrayList<>();
    for (Player target : Bukkit.getOnlinePlayers()) {
        if (player.canSee(target) && !results.contains(target.getName())) {
            if (playerFaction != plugin.getFactionManager().getPlayerFaction(target.getUniqueId())) {
                results.add(target.getName());
            }
        }
    }

    return results;
}
 
Example 23
Project: HCFCore   File: FactionForceJoinArgument.java   Source Code and License 6 votes vote down vote up
@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;
    }
}
 
Example 24
Project: HCFCore   File: KothHelpArgument.java   Source Code and License 6 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    sender.sendMessage(ChatColor.GRAY + "m--------------------");
    sender.sendMessage(ChatColor.AQUA + "KoTH Help");
    for (CommandArgument argument : kothExecutor.getArguments()) {
        if (argument != this) {
            String permission = argument.getPermission();
            if (permission == null || sender.hasPermission(permission)) {
                sender.sendMessage(ChatColor.GRAY + argument.getUsage(label) + " - " + argument.getDescription() + '.');
            }
        }
    }

    sender.sendMessage(ChatColor.GRAY + "/f show <kothName> - View information about a KOTH.");
            sender.sendMessage(ChatColor.GRAY + "m--------------------");
    return true;
}
 
Example 25
Project: mczone   File: MatchCmd.java   Source Code and License 6 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
	Gamer g = Gamer.get(sender);
	
	MatchStats stats = Nexus.getMatchStats();
	int kills = stats.getKills(g);
	int deaths = stats.getDeaths(g);
	int killstreak = stats.getKillstreak(g);
	double kd = stats.getKD(g);
	
	String line1 = "&fMatch: &cTDM &7on &a" + Nexus.getRotary().getCurrentMap().getTitle();
	String line2 = "&fKD: " + (kd >= 1 ? ChatColor.GREEN : ChatColor.RED) + kd;
	String line3 = "&fKillstreak: &f" + killstreak;
	String line4 = "&fKills: &f" + kills;
	String line5 = "&fDeaths: &f" + deaths;

	Chat.player(g, line1 + "\n" + line2 + "\n" + line3 + "\n" + line4 + "\n" + line5);
	return true;		
}
 
Example 26
Project: SuperiorCraft   File: AddMin.java   Source Code and License 6 votes vote down vote up
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
	ArrayList<String> a = null;
	
	if (command.getName().equalsIgnoreCase("addmin")) {
		a = new ArrayList<String>();
		if (args.length <= 1) {
			if ("troll".startsWith(args[0])) {
				a.add("troll");
			}
		}
		else if (args.length == 2) {
			if ("fakechat".startsWith(args[1])) {
				a.add("fakechat");
			}
			if ("noreload".startsWith(args[1])) {
				a.add("noreload");
			}
		}
	}
	
	return a;
}
 
Example 27
Project: Lukkit   File: CommandPlugin.java   Source Code and License 6 votes vote down vote up
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
    if (command.getName().equals("luaplugin")) {
        if (!commandSender.hasPermission("lukkitplus.pl")) {
            commandSender.sendMessage(ChatColor.RED + "Sorry, you don't have permission.");
            return true;
        }
        if (strings.length != 1) {
            commandSender.sendMessage(ChatColor.RED + "Usage: /luaplugin <name>");
            return true;
        }
        LuaPlugin plugin = Environment.findByName(strings[0]);
        if (plugin == null) {
            commandSender.sendMessage(ChatColor.RED + "Plugin specified doesn't exist.");
            return true;
        }
        commandSender.sendMessage("Name: " + ChatColor.GREEN + plugin.getName());
        commandSender.sendMessage("Version: " + ChatColor.GREEN + plugin.getVersion());
        commandSender.sendMessage("Description: " + ChatColor.GREEN + plugin.getDescription());
        return true;
    }
    return false;
}
 
Example 28
Project: MT_Core   File: AdminCommands.java   Source Code and License 5 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
	if (!(sender instanceof Player)) {
		sender.sendMessage("Admin commands are currently only available from ingame.");
		return true;
	}

	Player p = (Player) sender;

	if (!p.isOp())
		return true;

	if (args.length == 0) {
		p.sendMessage(helpPage);
		return true;
	}

	if (cmd.getName().equalsIgnoreCase("supplydrop")) {
		if (args.length == 1) {
			if (args[0].equalsIgnoreCase("drop")) {
				main.getSupplyDropManager().deliverSupplyDrop(p.getWorld());

			}
		}
	}

	return true;
}
 
Example 29
Project: HCFCore   File: ToggleBroadcastsCommand.java   Source Code and License 5 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {

    if (!sender.hasPermission("Core.staff")) {
        sender.sendMessage(ChatColor.RED + "No permission.");
        return true;
    }

    boolean newStatus = !SettingsYML.DIAMOND_ORE_ALERTS;
    SettingsYML.DIAMOND_ORE_ALERTS = newStatus;
    Bukkit.broadcastMessage(ChatColor.GOLD + "" + sender.getName() + ChatColor.YELLOW + " has "
            + (newStatus ? ChatColor.GREEN +"enabled" : ChatColor.RED + "disabled") + ChatColor.YELLOW + " found diamond ore notifications.");
    return true;
}
 
Example 30
Project: VanillaPlus   File: CPManager.java   Source Code and License 5 votes vote down vote up
@SuppressWarnings("unchecked")
public CPManager(VanillaPlus instance) {
   	super(String.class, CommandPlus.class);
   	if(CPManager.instance != null || instance == null)return;
   	register(CPChannelSet.class,		"CHANNEL_SET");
   	register(CPChannelState.class,		"CHANNEL_STATE");
   	register(CPChannelTalk.class,		"CHANNEL_TALK");
   	register(CPCurrencyPay.class,		"CURRENCY_PAY");
   	register(CPCurrencySet.class, 		"CURRENCY_SET");
   	register(CPGamemode.class, 			"GAMEMODE");
   	register(CPLang.class, 				Node.LANG.get());
   	register(CPMenuOpen.class, 			"MENU_OPEN");
   	register(CPMessageSend.class, 		"MESSAGE_SEND");
   	register(CPMessagePrivate.class, 	"MESSAGE_PRIVATE");
   	register(CPMulti.class, 			"MULTI");
   	register(CPNick.class, 				"NICK");
   	register(CPNode.class, 				Node.NODE.get());
   	register(CPOp.class, 				"OP");
   	register(CPProfil.class, 			"PROFIL");
   	register(CPReward.class,			"REWARD");
   	register(CPTeleportLocation.class,	"TELEPORT_LOCATION");
   	register(CPTeleportPlayer.class,	"TELEPORT_PLAYER");
   	register(CPTOD.class, 				"TOD");
   	//TODO show top ( stat / money )
   	CPManager.instance = instance;
	commandMap = (Map<String, Command>) ReflectionUtils.getDeclaredField("knownCommands",
			ReflectionUtils.invoke(ReflectionUtils.getMethod("getCommandMap",
					ReflectionUtils.getBukkitClass("CraftServer")), Bukkit.getServer()));
   }
 
Example 31
Project: QuestsXL   File: CreateQuestCommand.java   Source Code and License 5 votes vote down vote up
public CreateQuestCommand(Player player, Command command, String label, String[] args)
{
    this.player = player;
    this.command = command;
    this.label = label;
    this.args = args;

}
 
Example 32
Project: DragonEggDrop   File: DragonEggDropCmd.java   Source Code and License 5 votes vote down vote up
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
	List<String> options = new ArrayList<>();
	
	if (args.length == 1) {
		options.add("help");
		options.add("reload");
	}
	
	return options;
}
 
Example 33
Project: SurvivalAPI   File: CommandNextEvent.java   Source Code and License 5 votes vote down vote up
/**
 * Command executor
 *
 * @param commandSender Sender
 * @param command Command instance
 * @param s Command's name
 * @param strings Command's arguments
 *
 * @return {@code true} is successfully executed or {@code false}
 */
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings)
{
    if (game.getSurvivalGameLoop() != null && game.isGameStarted())
        game.getSurvivalGameLoop().forceNextEvent();
    else
        commandSender.sendMessage(ChatColor.RED + "Erreur: la partie n'a pas commencé !");

    return true;
}
 
Example 34
Project: Uranium   File: SpigotConfig.java   Source Code and License 5 votes vote down vote up
public static void init()
{
    config = YamlConfiguration.loadConfiguration( CONFIG_FILE );
    config.options().header( HEADER );
    config.options().copyDefaults( true );

    commands = new HashMap<String, Command>();

    version = getInt( "config-version", 7 );
    set( "config-version", 7 );
    readConfig( SpigotConfig.class, null );
}
 
Example 35
Project: NeverLag   File: CommandDispatcher.java   Source Code and License 5 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
	if ("neverlag".equalsIgnoreCase(cmd.getName())) {
		if (args.length == 0) {
			// TODO 显示帮助信息
			throw new UnsupportedOperationException();
		}

		AbstractSubCommand executor = subCommandMap.get(args[0].toLowerCase());
		if (executor == null) {
			sender.sendMessage(i18n.tr("subCommandNotFound"));
			return true;
		}
		if (!sender.hasPermission(executor.getPermission())) {
			sender.sendMessage(i18n.tr("noPermission"));
			return true;
		}
		if (executor.isPlayerRequired() && !(sender instanceof Player)) {  // 如果命令要求玩家才能执行, 而发送者又不是玩家
			sender.sendMessage(i18n.tr("playerOnly"));
		}
		String[] subCommandArgs = Arrays.copyOfRange(args, 1, args.length);
		if (executor.getMinimumArgCount() > 0 && subCommandArgs.length < executor.getMinimumArgCount()) {
			sender.sendMessage(executor.getUsage());
			return true;
		}

		try {
			executor.onCommand(sender, subCommandArgs);
		} catch (MissingCommandArgumentException ex) {
			if (ex.getLocalizedMessage() == null) {
				sender.sendMessage(executor.getUsage());
			} else {
				sender.sendMessage(ex.getLocalizedMessage());
			}
		}
	}
	return true;
}
 
Example 36
Project: mczone   File: LeaveCmd.java   Source Code and License 5 votes vote down vote up
@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;
}
 
Example 37
Project: helper   File: CommandMapUtil.java   Source Code and License 5 votes vote down vote up
private static Map<String, Command> getKnownCommandMap() {
    try {
        //noinspection unchecked
        return (Map<String, Command>) KNOWN_COMMANDS_FIELD.get(getCommandMap());
    } catch (Exception e) {
        throw new RuntimeException("Could not get known commands map", e);
    }
}
 
Example 38
Project: KevsPermissions   File: PermissionsCommand.java   Source Code and License 5 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
	if (args.length == 0) {
		sender.sendMessage(PREFIX + "You are running version " + KevsPermissions.getPluginDetails().getVersion()
				+ " of KevsPermissions, developed by §e" + KevsPermissions.getPluginDetails().getAuthor() + "§7.");
		sender.sendMessage("§7GitHub: https://github.com/KevSlashNull/KevsPermissions");
		return true;
	}
	if (!sender.hasPermission("kp.command")) {
		sender.sendMessage(PREFIX + "§cSorry, but you are lacking a permission.");
		return true;
	}
	if (args[0].equalsIgnoreCase("help")) {
		SubHelp.a(sender, label, args);
		return true;
	} else if (args[0].equalsIgnoreCase("groups")) {
		SubGroups.a(sender, label, args);
		return true;
	} else if (args[0].equalsIgnoreCase("group")) {
		SubGroup.a(sender, label, args);
		return true;
	} else if (args[0].equalsIgnoreCase("players")) {
		SubPlayers.a(sender, label, args);
		return true;
	} else if (args[0].equalsIgnoreCase("player")) {
		SubPlayer.a(sender, label, args);
		return true;
	} else if (args[0].equalsIgnoreCase("reload")) {
		SubReload.a(sender, label, args);
		return true;
	} else {
		error(sender);
	}
	return true;
}
 
Example 39
Project: HCFCore   File: EventSetAreaArgument.java   Source Code and License 5 votes vote down vote up
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
    if (args.length != 2) {
        return Collections.emptyList();
    }

    return plugin.getFactionManager().getFactions().stream().filter(faction -> faction instanceof EventFaction).map(Faction::getName).collect(Collectors.toList());
}
 
Example 40
Project: ProjectAres   File: BukkitCommandRegistry.java   Source Code and License 5 votes vote down vote up
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
    // Save the word being completed, before and after decoding
    final String encodedWord = args[args.length - 1];
    args = decode(args);
    final String decodedWord = args[args.length - 1];

    List<String> options = handleCompletion(sender, command.getName(), args);

    if(options != null) {
        // If sender is a player, encode the completion results.
        // A single result doesn't need to be encoded, because the
        // client won't try to cycle through the results.
        if(sender instanceof Player && options.size() > 1) {
            options = encode(options);
        }

        // When completing a word with an encoded space, we have to add the
        // part that was lost from decoding back to each completion result
        // e.g. the client tries to complete "the-fen", but the command method
        // returns results for "fen", so we have to restore "the-" for each result.
        if(!encodedWord.equals(decodedWord)) {
            final String extra = encodedWord.substring(0, encodedWord.length() - decodedWord.length());
            options = Lists.transform(options, option -> extra + option);
        }
    }

    return options;
}
 
Example 41
Project: HCFCore   File: FactionMapArgument.java   Source Code and License 5 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 + "This command is only executable by players.");
        return true;
    }

    Player player = (Player) sender;
    UUID uuid = player.getUniqueId();

    final FactionUser factionUser = plugin.getUserManager().getUser(uuid);
    final VisualType visualType;
    if (args.length <= 1) {
        visualType = VisualType.CLAIM_MAP;
    } else if ((visualType = GuavaCompat.getIfPresent(VisualType.class, args[1]).orNull()) == null) {
        player.sendMessage(ChatColor.RED + "Visual type " + args[1] + " not found.");
        return true;
    }

    boolean newShowingMap = !factionUser.isShowClaimMap();
    if (newShowingMap) {
        if (!LandMap.updateMap(player, plugin, visualType, true)) {
            return true;
        }
    } else {
        plugin.getVisualiseHandler().clearVisualBlocks(player, visualType, null);
        sender.sendMessage(ChatColor.RED + "Claim pillars are no longer shown.");
    }

    factionUser.setShowClaimMap(newShowingMap);
    return true;
}
 
Example 42
Project: EscapeLag   File: EscapeLag.java   Source Code and License 5 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
	if (label.equalsIgnoreCase("el")) {
		return PluginCommand.DoCommand(sender, cmd, label, args);
	}
	return true;
}
 
Example 43
Project: HCFCore   File: FactionAnnouncementArgument.java   Source Code and License 5 votes vote down vote up
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
    if (!(sender instanceof Player)) {
        return Collections.emptyList();
    } else if (args.length == 2) {
        return CLEAR_LIST;
    } else {
        return Collections.emptyList();
    }
}
 
Example 44
Project: SayNoToMcLeaks   File: Commands.java   Source Code and License 5 votes vote down vote up
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
	List<String> suggests = new ArrayList<String>();
	if((alias.equalsIgnoreCase("saynotomcleaks") || alias.equalsIgnoreCase("mcleaks")) && args.length <= 1) {
		suggests.add("help");
		if (sender.hasPermission(BukkitSayNoToMcLeaks.PERMISSION_RELOAD)) {
			suggests.add("reload");
		}
	}
	return suggests;
}
 
Example 45
Project: AutoMessageDisplayer   File: CommandAmdTime.java   Source Code and License 5 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
	Player p = (Player)sender;
	if(p.hasPermission("automessagedisplayer.settime")||p.isOp()) {
		plugin.getConfig().set(TIME_CONFIG, Integer.parseInt(args[0]));
		p.sendMessage("�9Time set to : �f"+args[0]);
		plugin.saveConfig();
		plugin.reloadConfig();
		return true;
	}
	return false;
}
 
Example 46
Project: HCFCore   File: FactionInvitesArgument.java   Source Code and License 5 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 can have faction invites.");
        return true;
    }

    List<String> receivedInvites = new ArrayList<>();
    for (Faction faction : plugin.getFactionManager().getFactions()) {
        if (faction instanceof PlayerFaction) {
            PlayerFaction targetPlayerFaction = (PlayerFaction) faction;
            if (targetPlayerFaction.getInvitedPlayerNames().contains(sender.getName())) {
                receivedInvites.add(targetPlayerFaction.getDisplayName(sender));
            }
        }
    }

    PlayerFaction playerFaction = plugin.getFactionManager().getPlayerFaction((Player) sender);
    String delimiter = ChatColor.WHITE + ", " + ChatColor.GRAY;

    if (playerFaction != null) {
        Set<String> sentInvites = playerFaction.getInvitedPlayerNames();
        sender.sendMessage(ChatColor.AQUA + "Sent by " + playerFaction.getDisplayName(sender) + ChatColor.AQUA + " (" + sentInvites.size() + ')' + ChatColor.DARK_AQUA + ": " + ChatColor.GRAY
                + (sentInvites.isEmpty() ? "Your faction has not invited anyone." : StringUtils.join(sentInvites, delimiter) + '.'));
    }

    sender.sendMessage(ChatColor.AQUA + "Requested (" + receivedInvites.size() + ')' + ChatColor.DARK_AQUA + ": " + ChatColor.GRAY
            + (receivedInvites.isEmpty() ? "No factions have invited you." : StringUtils.join(receivedInvites, ChatColor.WHITE + delimiter) + '.'));

    return true;
}
 
Example 47
Project: mczone   File: TeamCmd.java   Source Code and License 5 votes vote down vote up
@Override
  public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
      if (!(sender instanceof Player)) {
          Chat.player(sender, "&cThis command is only available for players!");
          return true;
      }
      
      final Player p = (Player) sender;
      Gamer g = Gamer.get(p);
      if (g.getRank().getType() == RankType.USER) {
          Chat.player(sender, "&cGo to www.mczone.co/donate to get this command!");
          return true;
      }
      
      if (!State.PRE) {
          Chat.player(sender, "&cThe game has already started!");
          return true;
      }
      
Team team = Walls.BLUE;
if (cmd.getName().equalsIgnoreCase("red"))
	team = Walls.RED;
if (cmd.getName().equalsIgnoreCase("green"))
	team = Walls.GREEN;
if (cmd.getName().equalsIgnoreCase("yellow"))
	team = Walls.YELLOW;

team.join(p);
p.setDisplayName(team.getColor() + p.getName());
      Chat.setPlayerListName(p, team.getColor() + p.getName());
      p.setDisplayName(team.getColor() + p.getName());
      p.teleport(team.getSpawn());
      Chat.player(sender, "&aYou have changed to team " + team.getColor() + team.getColor().name() + "&a!");
      return true;
  }
 
Example 48
Project: ArmorPlus   File: UserCommand.java   Source Code and License 5 votes vote down vote up
@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;
}
 
Example 49
Project: HCFCore   File: TimerCheckArgument.java   Source Code and License 5 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (args.length < 3) {
        sender.sendMessage(ChatColor.RED + "Usage: " + getUsage(label));
        return true;
    }

    PlayerTimer temporaryTimer = null;
    for (Timer timer : plugin.getTimerManager().getTimers()) {
        if (timer instanceof PlayerTimer && timer.getName().equalsIgnoreCase(args[1])) {
            temporaryTimer = (PlayerTimer) timer;
            break;
        }
    }

    if (temporaryTimer == null) {
        sender.sendMessage(ChatColor.RED + "Timer '" + args[1] + "' not found.");
        return true;
    }

    final PlayerTimer playerTimer = temporaryTimer;
    new BukkitRunnable() {
        @Override
        public void run() {
            UUID uuid;
            try {
                uuid = UUIDFetcher.getUUIDOf(args[2]);
            } catch (Exception ex) {
                sender.sendMessage(ChatColor.GOLD + "Player '" + ChatColor.WHITE + args[2] + ChatColor.GOLD + "' not found.");
                return;
            }

            long remaining = playerTimer.getRemaining(uuid);
            sender.sendMessage(ChatColor.YELLOW + args[2] + " has timer " + playerTimer.getName() + " for another " + DurationFormatUtils.formatDurationWords(remaining, true, true));
        }
    }.runTaskAsynchronously(plugin);
    return true;
}
 
Example 50
Project: Anti-Rooktube   File: Main.java   Source Code and License 5 votes vote down vote up
@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;
 }
 
Example 51
Project: Eldin-Land-Plugin   File: Land.java   Source Code and License 5 votes vote down vote up
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
// Ensure that the Database database connection is established
Database.connect();
if (!Database.isConnected()) {
    Database.connect();
}

Player p = (Player) sender;
String pUUID = p.getUniqueId().toString().replace("-","");

String wildLand,cityLand,netherLand,endLand,totalLand;

if (Database.isConnected()) {
    try {
        // Prepare SQL statement
        ResultSet rs = Database.getPlayerLand(pUUID);
        while (rs.next()) {
            // Send land information to user
            wildLand = Integer.toString(rs.getInt("wild_count"));
            cityLand = Integer.toString(rs.getInt("city_count"));
            netherLand = Integer.toString(rs.getInt("nether_count"));
            endLand = Integer.toString(rs.getInt("end_count"));
            totalLand = Integer.toString(Integer.parseInt(wildLand) + Integer.parseInt(cityLand) + Integer.parseInt(netherLand) + Integer.parseInt(endLand));
            p.sendMessage(ChatColor.BLUE + "Total Land Tiles: " + totalLand);
            p.sendMessage(ChatColor.GREEN + "Total Wild Tiles: " + wildLand);
            p.sendMessage(ChatColor.GOLD + "Total City Tiles: " + cityLand);
            p.sendMessage(ChatColor.RED + "Total Nether Tiles: " + netherLand);
            p.sendMessage(ChatColor.DARK_PURPLE + "Total End Tiles: " + endLand);
        }
    } catch (SQLException ex) {
        System.out.print("SQLExeception: " + ex.getMessage());
        System.out.println("SQLState: " + ex.getSQLState());
        System.out.println("VendorError: " + ex.getErrorCode());
    }
} else {
    p.sendMessage(ChatColor.RED + "There was an issue connecting to the database!");
}
return true;
}
 
Example 52
Project: HCFCore   File: FactionClaimForArgument.java   Source Code and License 5 votes vote down vote up
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;
    }
    if (args.length < 2)
    {
        sender.sendMessage(ChatColor.RED + "Usage: " + getUsage(label));
        return true;
    }
    Faction targetFaction = this.plugin.getFactionManager().getFaction(args[1]);
    if (!(targetFaction instanceof ClaimableFaction))
    {
        sender.sendMessage(ChatColor.RED + "Claimable faction named " + args[1] + " not found.");
        return true;
    }
    Player player = (Player)sender;
    WorldEditPlugin worldEditPlugin = this.plugin.getWorldEdit();
    if (worldEditPlugin == null)
    {
        sender.sendMessage(ChatColor.RED + "WorldEdit must be installed to set claim areas.");
        return true;
    }
    Selection selection = worldEditPlugin.getSelection(player);
    if (selection == null)
    {
        sender.sendMessage(ChatColor.RED + "You must make a WorldEdit selection to do this.");
        return true;
    }
    ClaimableFaction claimableFaction = (ClaimableFaction)targetFaction;
    if (claimableFaction.addClaim(new Claim(claimableFaction, selection.getMinimumPoint(), selection.getMaximumPoint()), sender)) {
        sender.sendMessage(ChatColor.YELLOW + "Successfully claimed this land for " + ChatColor.RED + targetFaction.getName() + ChatColor.YELLOW + '.');
    }
    return true;
}
 
Example 53
Project: Stats4   File: StatsMainCommand.java   Source Code and License 5 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
    if (args.length == 0) {
        // Send own statistics
        if (!(sender instanceof Player)) {
            sender.sendMessage(ChatColor.RED + "Cannot send stats to a non-player!");
            sender.sendMessage(ChatColor.RED + "For help, see /stats help");
            return true;
        }
        sendStatistics(sender, (Player) sender);
        return true;
    }
    sender.sendMessage(ChatColor.RED + "Not implemented yet");
    return false;
}
 
Example 54
Project: HCFCore   File: FactionSubclaimDeleteArgument.java   Source Code and License 5 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 + "This command is only executable by players.");
        return true;
    }

    if (args.length < 3) {
        sender.sendMessage(ChatColor.RED + "Usage: " + getUsage(label));
        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;
    }

    if (playerFaction.getMember(player.getUniqueId()).getRole() == Role.MEMBER) {
        sender.sendMessage(ChatColor.RED + "You must be a faction officer to edit subclaims.");
        return true;
    }

    for (Claim claim : playerFaction.getClaims()) {
        for (Iterator<Subclaim> iterator = claim.getSubclaims().iterator(); iterator.hasNext();) {
            Subclaim subclaim = iterator.next();
            if (subclaim.getName().equalsIgnoreCase(args[2])) {
                iterator.remove();
                sender.sendMessage(ChatColor.AQUA + "Removed subclaim named " + subclaim.getName() + '.');
                return true;
            }
        }
    }

    sender.sendMessage(ChatColor.RED + "Your faction does not have a subclaim named " + args[2] + '.');
    return true;
}
 
Example 55
Project: WC   File: WCCore.java   Source Code and License 5 votes vote down vote up
@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;
}
 
Example 56
Project: HCFCore   File: ConquestSetpointsArgument.java   Source Code and License 5 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (args.length < 3) {
        sender.sendMessage(ChatColor.RED + "Usage: " + getUsage(label));
        return true;
    }

    Faction faction = plugin.getFactionManager().getFaction(args[1]);

    if (!(faction instanceof PlayerFaction)) {
        sender.sendMessage(ChatColor.RED + "Faction " + args[1] + " is either not found or is not a player faction.");
        return true;
    }

    Integer amount = JavaUtils.tryParseInt(args[2]);

    if (amount == null) {
        sender.sendMessage(ChatColor.RED + "'" + args[2] + "' is not a number.");
        return true;
    }

    if (amount > SettingsYML.CONQUEST_REQUIRED_WIN_POINTS) {
        sender.sendMessage(ChatColor.RED + "Maximum points for Conquest is " + SettingsYML.CONQUEST_REQUIRED_WIN_POINTS + '.');
        return true;
    }

    PlayerFaction playerFaction = (PlayerFaction) faction;
    ((ConquestTracker) EventType.CONQUEST.getEventTracker()).setPoints(playerFaction, amount);

    Command.broadcastCommandMessage(sender, ChatColor.YELLOW + "Set the points of faction " + playerFaction.getName() + " to " + amount + '.');
    return true;
}
 
Example 57
Project: HCFCore   File: FactionUnallyArgument.java   Source Code and License 5 votes vote down vote up
@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();
    }

    return Lists.newArrayList(Iterables.concat(COMPLETIONS, playerFaction.getAlliedFactions().stream().map(Faction::getName).collect(Collectors.toList())));
}
 
Example 58
Project: Punishments   File: PunishCommand.java   Source Code and License 5 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) 
{
	Player player = (Player) sender;
	PunishGUI.open(player);
	return false;
}
 
Example 59
Project: Debuggery   File: CommandBase.java   Source Code and License 5 votes vote down vote up
@Override
public final List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
    if (!sender.hasPermission(this.permission)) {
        sender.sendMessage(ChatColor.RED + "You do not have permission to do that!");
        return Collections.emptyList();
    }

    if (this.requiresPlayer && !(sender instanceof Player)) {
        sender.sendMessage(ChatColor.RED + "This command can only be used by players!");
        return Collections.emptyList();
    }

    return this.tabCompleteLogic(sender, command, alias, args);
}
 
Example 60
Project: HCFCore   File: SpawnCommand.java   Source Code and License 5 votes vote down vote up
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
    if (!(sender instanceof Player)) {
        sender.sendMessage(ChatColor.RED + "This command is only executable by players.");
        return true;
    }
    final Player player = (Player)sender;
    World world = player.getWorld();
    Location spawn = world.getSpawnLocation().clone().add(0.5, 0.5, 0.5);
    if (!sender.hasPermission(command.getPermission() + ".teleport")) {
        sender.sendMessage(ChatColor.RED + "This server does not have a spawn command, you must travel there. " + "Spawn can be found at " + ChatColor.GRAY + '(' + spawn.getBlockX() + ", " + spawn.getBlockZ() + ')');
        return true;
    }
    if (!sender.hasPermission(command.getPermission() + ".teleport")) {
        this.plugin.getTimerManager().teleportTimer.teleport(player, Bukkit.getWorld("world").getSpawnLocation(), TimeUnit.SECONDS.toMillis(15L), ChatColor.GRAY + "Teleporting to spawn in " + 15 + " seconds.", PlayerTeleportEvent.TeleportCause.COMMAND);
        return true;
    }
    if (args.length > 0) {
        world = Bukkit.getWorld(args[0]);
        if (world == null) {
            sender.sendMessage(ChatColor.RED + "There is not a world named " + args[0] + '.');
            return true;
        }
        spawn = world.getSpawnLocation().clone().add(0.5, 0.0, 0.5);
    }
    player.teleport(spawn, PlayerTeleportEvent.TeleportCause.COMMAND);
    return true;
}