当前位置: 首页>>代码示例>>Java>>正文


Java CommandContext类代码示例

本文整理汇总了Java中org.spongepowered.api.command.args.CommandContext的典型用法代码示例。如果您正苦于以下问题:Java CommandContext类的具体用法?Java CommandContext怎么用?Java CommandContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CommandContext类属于org.spongepowered.api.command.args包,在下文中一共展示了CommandContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import org.spongepowered.api.command.args.CommandContext; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource source, CommandContext context) throws CommandException
{
    try
    {
        MainConfig.getConfig().load();
        FactionsConfig.getConfig().load();

        source.sendMessage(Text.of(PluginInfo.PluginPrefix, "Configs have been reloaded!"));
    }
    catch (Exception exception)
    {
        exception.printStackTrace();
    }

    return CommandResult.success();
}
 
开发者ID:Aquerr,项目名称:EagleFactions,代码行数:18,代码来源:ReloadCommand.java

示例2: execute

import org.spongepowered.api.command.args.CommandContext; //导入依赖的package包/类
/**
 * Callback for the execution of a command.
 *
 * @param src  The commander who is executing this command
 * @param args The parsed command arguments for this command
 * @return the result of executing this command
 * @throws CommandException If a user-facing error occurs while executing this command
 */
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
	if (!(src instanceof Player))
		return execServer(src, args);

	Player player = (Player) src;
	Region region = new Region(player.getLocation());
	LoadedRegion.ChunkType type = args.<LoadedRegion.ChunkType>getOne("type").orElse(LoadedRegion.ChunkType.WORLD);
	LoadedRegion loadedRegion = new LoadedRegion(region, player, type);

	if (dataStore.isRegionLoaded(loadedRegion))
		throw new CommandException(Text.of(TextColors.RED, "You've already allocated this region."));

	loadedRegion.assignTicket();
	if (loadedRegion.isValid())
		throw new CommandException(Text.of(TextColors.RED, "Failed to allocate a loading ticket and force region."));

	dataStore.addPlayerRegion(player, loadedRegion);
	loadedRegion.forceChunks();
	database.saveRegionData(loadedRegion);

	player.sendMessage(Text.of(TextColors.GREEN, "Successfully loaded the region."));

	return CommandResult.success();
}
 
开发者ID:DevOnTheRocks,项目名称:StickyChunk,代码行数:33,代码来源:CommandLoad.java

示例3: execServer

import org.spongepowered.api.command.args.CommandContext; //导入依赖的package包/类
private CommandResult execServer(CommandSource src, CommandContext args) {
	if (dataStore.getCollatedRegions().isEmpty())
		src.sendMessage(Text.of(TextColors.RED, "There are no loaded regions to display"));

	dataStore.getCollatedRegions().forEach(region -> {
		Optional<Player> oPlayer = server.getPlayer(region.getOwner());
		String owner = (oPlayer.isPresent()) ? oPlayer.get().getName() : region.getOwner().toString();

		src.sendMessage(
			Text.of(
				TextColors.GREEN, owner, " ",
				TextColors.GOLD, region.getChunks().size(),
				TextColors.GREEN, " [", (region.getType() == LoadedRegion.ChunkType.WORLD) ? 'W' : 'P', "]",
				TextColors.WHITE, " chunks in world ",
				TextColors.GOLD, region.getWorld().getName(),
				TextColors.WHITE, " from (", TextColors.LIGHT_PURPLE, region.getRegion().getFrom().getX(), TextColors.WHITE,
				", ", TextColors.LIGHT_PURPLE, region.getRegion().getFrom().getZ(), TextColors.WHITE, ")",
				TextColors.WHITE, " to (", TextColors.LIGHT_PURPLE, region.getRegion().getTo().getX(), TextColors.WHITE,
				", ", TextColors.LIGHT_PURPLE, region.getRegion().getTo().getZ(), TextColors.WHITE, ")"
			)
		);
	});

	return CommandResult.success();
}
 
开发者ID:DevOnTheRocks,项目名称:StickyChunk,代码行数:26,代码来源:CommandList.java

示例4: complete

import org.spongepowered.api.command.args.CommandContext; //导入依赖的package包/类
/**
 * Fetch completions for command arguments.
 *
 * @param src     The source requesting tab completions
 * @param args    The arguments currently provided
 * @param context The context to store state in
 * @return Any relevant completions
 */
@Override
@NonnullByDefault
public List<String> complete(CommandSource src, CommandArgs args, CommandContext context) {
	try {
		String type = args.peek().toLowerCase();
		return LoadedRegion.ChunkType.asMap().entrySet().stream()
			.filter(s -> s.getKey().startsWith(type))
			.filter(s -> Permissions.hasPermission(src, s.getKey()))
			.map(Map.Entry::getKey)
			.collect(Collectors.toList());
	} catch (ArgumentParseException e) {
		e.printStackTrace();
	}

	return Lists.newArrayList();
}
 
开发者ID:DevOnTheRocks,项目名称:StickyChunk,代码行数:25,代码来源:ChunkTypeArgument.java

示例5: execute

import org.spongepowered.api.command.args.CommandContext; //导入依赖的package包/类
@Override public CommandResult execute(CommandSource commandSource, CommandContext commandContext) throws CommandException {
    if(commandContext.getOne("type").isPresent()) {
        String type = commandContext.<String>getOne("type").get();
        VirtualCrate virtualCrate = HuskyCrates.instance.getCrateUtilities().getVirtualCrate(type);
        int quantity = commandContext.getOne("quantity").isPresent() ? commandContext.<Integer>getOne("quantity").get() : 1;
        if (virtualCrate == null) {
            commandSource.sendMessage(Text.of("Invalid crate id: " + type + ". Please check your config."));
            return CommandResult.empty();
        }
        commandSource.sendMessage(Text.of("Gave everyone " + quantity + " vkeys."));
        virtualCrate.givePlayersVirtualKeys(Sponge.getServer().getOnlinePlayers(),quantity);
        for(Player e: Sponge.getServer().getOnlinePlayers()){
            if(commandSource != e) {
                e.sendMessage(Text.of(TextColors.GREEN,"You received " + quantity + " virtual keys for a ", TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName),"."));
            }
        }
    }else{
        commandSource.sendMessage(Text.of("Usage: /crate vkeyall <id> [count]"));
    }
    return CommandResult.success();
}
 
开发者ID:codeHusky,项目名称:HuskyCrates-Sponge,代码行数:22,代码来源:VirtualKeyAll.java

示例6: execute

import org.spongepowered.api.command.args.CommandContext; //导入依赖的package包/类
@Override public CommandResult execute(CommandSource commandSource, CommandContext commandContext) throws CommandException {
    if (!(commandSource instanceof Player)) {
        commandSource.sendMessage(Text.of("You need to be in game or specify a player for this command to work."));
        return CommandResult.empty();
    }
    Player plr = (Player)commandSource;
    if(!plr.getItemInHand(HandTypes.MAIN_HAND).isPresent()){
        commandSource.sendMessage(Text.of("You must be holding an item to deposit a key."));
        return CommandResult.empty();
    }
    ItemStack key = plr.getItemInHand(HandTypes.MAIN_HAND).get();
    if(HuskyCrates.instance.crateUtilities.vcFromKey(key) == null){
        commandSource.sendMessage(Text.of(TextColors.RED,"Not a valid key."));
        return CommandResult.empty();
    }
    VirtualCrate virtualCrate = HuskyCrates.instance.crateUtilities.vcFromKey(plr.getItemInHand(HandTypes.MAIN_HAND).get());
    int keyCount = key.getQuantity();
    plr.setItemInHand(HandTypes.MAIN_HAND,null);
    virtualCrate.giveVirtualKeys(plr,keyCount);
    //commandSource.sendMessage(Text.of(TextColors.GREEN,"Successfully deposited " + keyCount + " ", TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName),TextColors.GREEN," Key(s)."));
    commandSource.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(
            virtualCrate.getLangData().formatter(virtualCrate.getLangData().depositSuccess,null,plr,virtualCrate,null,null,keyCount)
    ));
    return CommandResult.success();
}
 
开发者ID:codeHusky,项目名称:HuskyCrates-Sponge,代码行数:26,代码来源:DepositKey.java

示例7: execute

import org.spongepowered.api.command.args.CommandContext; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    final Optional<User> optionalUser = args.getOne("player");

    if (!optionalUser.isPresent()) {
        throw new CommandException(Text.of(TextColors.RED, "You must specify an existing user."));
    }

    final Optional<InetAddress> optionalIP = args.getOne("ip");

    if (!optionalIP.isPresent()) {
        throw new CommandException(Text.of(TextColors.RED, "You must specify a proper IP address."));
    }

    final User user = optionalUser.get();
    final InetAddress ip = optionalIP.get();

    Sponge.getScheduler().createAsyncExecutor(IPLog.getPlugin()).execute(() -> IPLog.getPlugin().getStorage().purgeConnection(ip, user.getUniqueId()));

    src.sendMessage(Text.of(TextColors.YELLOW, "You have successfully removed the specified connection from the database."));

    return CommandResult.success();
}
 
开发者ID:ichorpowered,项目名称:iplog,代码行数:24,代码来源:PurgeCommand.java

示例8: execute

import org.spongepowered.api.command.args.CommandContext; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
	if (src.hasPermission("*") || src.hasPermission("listener.admin"))
	{
	Boolean clear = SwitchSQL.Clearqueue();
	if(clear){
		src.sendMessage(Text.of("Cleared successful"));
		return CommandResult.success();
	}
	else{
		src.sendMessage(Text.of("Cleared fail"));
		return CommandResult.empty();
	}
	}else{
		src.sendMessage(Text.of("You don't have permission"));
	return CommandResult.empty();
	}
}
 
开发者ID:Mineaurion,项目名称:AurionVoteListener,代码行数:19,代码来源:ClearqueueCmd.java

示例9: execute

import org.spongepowered.api.command.args.CommandContext; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
	if ((src.hasPermission("*")) || (src.hasPermission("listener.admin")))
	{
		String player = args.<String>getOne("player").get();
		int vote = args.<Integer>getOne("vote").get();	
		long CurrentMiliseconde = System.currentTimeMillis();
		boolean succes = SwitchSQL.Voted(player, vote, CurrentMiliseconde);
		if(succes){
			src.sendMessage(Text.of("Vote set for "+player+" : "+String.valueOf(vote)));
			return CommandResult.success();
		}else{
			src.sendMessage(Text.of("an error has occurred"));
			return CommandResult.success();
		}
	}else{
		src.sendMessage(Text.of("You don't have permission"));
	return CommandResult.empty();
	}
}
 
开发者ID:Mineaurion,项目名称:AurionVoteListener,代码行数:21,代码来源:SetVoteCmd.java

示例10: execute

import org.spongepowered.api.command.args.CommandContext; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
	if (src.hasPermission("*") || src.hasPermission("listener.admin"))
	{
	List<String> player = SwitchSQL.QueuePlayer();
	
	for(int i = 0; i < player.size(); i++)
	{
		String username = player.get(i);
		List<String> service = SwitchSQL.QueueReward(username);
		
		for(int x = 0; x < service.size(); x++)
	    {
			RewardsTask.Notonline(username, service.get(x));
			SwitchSQL.removeQueue(username, service.get(x));
	    }
	}
	
	
}
	return CommandResult.success();
}
 
开发者ID:Mineaurion,项目名称:AurionVoteListener,代码行数:23,代码来源:ForcequeueCmd.java

示例11: execute

import org.spongepowered.api.command.args.CommandContext; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
	if (src.hasPermission("*") || src.hasPermission("listener.admin"))
	{
	Boolean clear = SwitchSQL.Cleartotals();
	if(clear){
		src.sendMessage(Text.of("Cleared successful"));
		return CommandResult.success();
	}
	else{
		src.sendMessage(Text.of("Cleared fail"));
		return CommandResult.empty();
	}
	}else{
		src.sendMessage(Text.of("You don't have permission"));
	return CommandResult.empty();
	}
	
}
 
开发者ID:Mineaurion,项目名称:AurionVoteListener,代码行数:20,代码来源:CleartotalsCmd.java

示例12: execute

import org.spongepowered.api.command.args.CommandContext; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource sender, CommandContext arguments) throws CommandException {
    Optional<String> optionalArg1 = arguments.getOne("arg1");
    if (optionalArg1.isPresent()) {
        List<String> subCmdArgs = new ArrayList<>();
        arguments.<String>getOne("arg2").ifPresent(subCmdArgs::add);
        for (Cmd subCmd : subCmds) {
            if (subCmd.getCommand().equalsIgnoreCase(optionalArg1.get())) {
                subCmd.run(sender, subCmdArgs.toArray(new String[subCmdArgs.size()]));
                return CommandResult.success();
            }
        }
        sendHelp(sender);
    } else {
        sendHelp(sender);
    }

    return CommandResult.success();
}
 
开发者ID:MinecraftMarket,项目名称:MinecraftMarket-Plugin,代码行数:20,代码来源:MainCMD.java

示例13: execute

import org.spongepowered.api.command.args.CommandContext; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    List<Camera> cams = new ArrayList<>(plugin.getCameras().values());
    cams.removeIf((cam)-> !cam.canUseCamera(src));

    Iterable<Text> texts = cams.parallelStream().map((cam)->
            plugin.translations.CAMERA_LIST_ITEM.apply(cam.templateVariables())
            .onHover(TextActions.showText(
                    plugin.translations.CAMERA_LIST_ITEM_HOVER.apply(cam.templateVariables()).build()
            ))
            .onClick(TextActions.runCommand("/camera view " + cam.getId())).build()
    ).collect(Collectors.toList());

    PaginationList.builder()
            .title(plugin.translations.CAMERA_LIST_TITLE)
            .contents(texts)
            .sendTo(src);

    return CommandResult.success();
}
 
开发者ID:Lergin,项目名称:Vigilate,代码行数:21,代码来源:ListCamerasCommand.java

示例14: processReloadCommand

import org.spongepowered.api.command.args.CommandContext; //导入依赖的package包/类
private CommandResult processReloadCommand(CommandSource source, CommandContext args) throws CommandException
{
    if (!source.hasPermission("virtualchest.reload"))
    {
        return CommandResult.empty();
    }
    else
    {
        if (args.getOne("extract-examples").isPresent())
        {
            this.plugin.getDispatcher().releaseExample();
        }
        this.plugin.onReload(() -> SpongeUnimplemented.createCause(source));
        return CommandResult.success();
    }
}
 
开发者ID:ustc-zzzz,项目名称:VirtualChest,代码行数:17,代码来源:VirtualChestCommandManager.java

示例15: execute

import org.spongepowered.api.command.args.CommandContext; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource source, CommandContext context) throws CommandException {
    //https://docs.spongepowered.org/stable/zh-CN/plugin/commands/arguments.html?highlight=commandcontext
    if (context.hasAny("arg")) {
        String[] args = context.<String>getOne("arg").get().split(" ");
        for (CommandHandler handler : this.handlerList) {
            if (args[0].equalsIgnoreCase(handler.getName()) && handler.hasPermission(source)) {
                if (!handler.hasPermission(source)) {//如果命令已禁用后台执行并且执行者是后台
                    if (source instanceof Player) {
                        source.sendMessage(TextUtil.of("§c你没有执行该命令的权限."));
                    } else {
                        source.sendMessage(TextUtil.of("§c后台无法执行该命令."));
                    }

                } else {//否则
                    handler.execute(source, args.length == 1 ? new String[0] : Util.subArray(args, 1, args.length - 1));
                    return CommandResult.success();
                }

            }
        }
    }
    source.sendMessage(TextUtil.of("§2输入/" + McrmbPluginInfo.config.command + " help §2来查看帮助"));

    return CommandResult.success();
}
 
开发者ID:txgs888,项目名称:McrmbCore_Sponge,代码行数:27,代码来源:CommandProxy.java


注:本文中的org.spongepowered.api.command.args.CommandContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。