本文整理匯總了Java中org.bukkit.command.Command類的典型用法代碼示例。如果您正苦於以下問題:Java Command類的具體用法?Java Command怎麽用?Java Command使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Command類屬於org.bukkit.command包,在下文中一共展示了Command類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onCommand
import org.bukkit.command.Command; //導入依賴的package包/類
@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;
}
示例2: onCommand
import org.bukkit.command.Command; //導入依賴的package包/類
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;
}
示例3: onTabComplete
import org.bukkit.command.Command; //導入依賴的package包/類
@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;
}
示例4: onTabComplete
import org.bukkit.command.Command; //導入依賴的package包/類
@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;
}
示例5: onCommand
import org.bukkit.command.Command; //導入依賴的package包/類
@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);
}
示例6: onTabComplete
import org.bukkit.command.Command; //導入依賴的package包/類
@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);
}
示例7: onCommand
import org.bukkit.command.Command; //導入依賴的package包/類
@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);
}
示例8: onTabComplete
import org.bukkit.command.Command; //導入依賴的package包/類
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);
}
示例9: getCommandTimingsByPlugin
import org.bukkit.command.Command; //導入依賴的package包/類
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;
}
示例10: onCommand
import org.bukkit.command.Command; //導入依賴的package包/類
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;
}
示例11: onTabComplete
import org.bukkit.command.Command; //導入依賴的package包/類
@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;
}
示例12: onCommand
import org.bukkit.command.Command; //導入依賴的package包/類
@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;
}
示例13: onCommand
import org.bukkit.command.Command; //導入依賴的package包/類
@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;
}
示例14: onCommand
import org.bukkit.command.Command; //導入依賴的package包/類
@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;
}
示例15: onCommand
import org.bukkit.command.Command; //導入依賴的package包/類
@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;
}