• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java CommandSource类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: commandMana

import org.spongepowered.api.util.command.CommandSource; //导入依赖的package包/类
@Directive(names = { "mana" }, description = "Displays your mana", inGameOnly = true)
public static CommandResult commandMana(CommandSource src, CommandContext context) {
	User user = Zephyr.getUserManager().getUser(((Player) src).getUniqueId());

	TextBuilder builder = Texts.builder("Mana " + user.getMana() + " / " + user.getMaximumMana() + ": [").color(
			TextColors.GRAY);
	int percent = (int) (((float) user.getMana() / (float) user.getMaximumMana()) * 10);
	TextBuilder tempBuilder = Texts.builder();
	tempBuilder.color(TextColors.AQUA);
	for (int i = 1; i <= 10; i++) {
		tempBuilder.append(Texts.of("="));
		if (i == percent) {
			builder.append(tempBuilder.build());
			tempBuilder = Texts.builder();
		}
	}
	tempBuilder.color(TextColors.DARK_GRAY);
	builder.append(tempBuilder.build());
	builder.append(Texts.of("]")).color(TextColors.GRAY);

	src.sendMessage(builder.build());
	return CommandResult.success();
}
 
开发者ID:mcardy,项目名称:Zephyr,代码行数:24,代码来源:UserCommand.java


示例2: commandProgress

import org.spongepowered.api.util.command.CommandSource; //导入依赖的package包/类
@Directive(names = { "progress" }, description = "Displays your progress", inGameOnly = true)
public static CommandResult commandProgress(CommandSource src, CommandContext context) {
	User user = Zephyr.getUserManager().getUser(((Player) src).getUniqueId());

	TextBuilder builder = Texts.builder(
			"Progress " + user.getUserData().getLevelProgress() + " / " + user.getRequiredLevelProgress() + ": [")
			.color(TextColors.GRAY);
	float percent = ((float) user.getUserData().getLevelProgress() / (float) user.getRequiredLevelProgress()) * 10;
	TextBuilder tempBuilder = Texts.builder();
	tempBuilder.color(TextColors.GREEN);
	for (int i = 0; i < 10; i++) {
		tempBuilder.append(Texts.of("="));
		if (i == (int)percent) {
			builder.append(tempBuilder.build());
			tempBuilder = Texts.builder();
		}
	}
	tempBuilder.color(TextColors.DARK_GRAY);
	builder.append(tempBuilder.build());
	builder.append(Texts.of("] Level " + user.getUserData().getLevel())).color(TextColors.GRAY);

	src.sendMessage(builder.build());
	return CommandResult.success();
}
 
开发者ID:mcardy,项目名称:Zephyr,代码行数:25,代码来源:UserCommand.java


示例3: commandManaRestore

import org.spongepowered.api.util.command.CommandSource; //导入依赖的package包/类
@Directive(names = { "mana.restore" }, description = "Restores your mana", inGameOnly = true, argumentLabels = { "target" }, arguments = { ArgumentType.OPTIONAL_STRING })
public static CommandResult commandManaRestore(CommandSource src, CommandContext context) {
	User target = null;
	if (!context.getOne("target").isPresent()) {
		target = Zephyr.getUserManager().getUser(((Player) src).getUniqueId());
	} else {
		Player player = null;
		if ((player = ZephyrPlugin.getGame().getServer().getPlayer(context.<String> getOne("target").get()).get()) != null) {
			target = Zephyr.getUserManager().getUser(player.getUniqueId());
		} else {
			target = Zephyr.getUserManager().getUser(((Player) src).getUniqueId());
		}
	}

	target.setMana(target.getMaximumMana());
	target.<Player> getPlayer().sendMessage(Texts.builder("Mana restored!").color(TextColors.AQUA).build());

	return CommandResult.success();
}
 
开发者ID:mcardy,项目名称:Zephyr,代码行数:20,代码来源:UserCommand.java


示例4: commandAliasCast

import org.spongepowered.api.util.command.CommandSource; //导入依赖的package包/类
@Directive(names = {"c"}, description = "Cast an alias", inGameOnly = true, argumentLabels = {"spell", "args"}, arguments = {ArgumentType.OPTIONAL_STRING, ArgumentType.OPTIONAL_REMAINING})
public static CommandResult commandAliasCast(CommandSource src, CommandContext context) {
	User user = Zephyr.getUserManager().getUser(((Player)src).getUniqueId());
	SpellManager manager = Zephyr.getSpellManager();
	String key = context.<String>getOne("spell").get();
	if (context.getOne("spell").isPresent()) {
		if (user.getAliases().containsKey(key)) {
			Spell spell = manager.getSpell(user.getAliases().get(key));
			Optional<String> options = context.<String>getOne("args");
			manager.cast(spell, new SpongeSpellContext(spell, user, options.isPresent() ? options.get().split(" ") : new String[0]));
		} else {
			user.sendMessage("That alias was not found. Set it with /alias <key> <spell>");
		}
		return CommandResult.success();
	} else {
		if (user.isCasting()) {
			user.setCasting(null, null);
		} else {
			user.sendMessage("Usage: /cast <spell> [args...]");
		}
		return CommandResult.success();
	}
}
 
开发者ID:mcardy,项目名称:Zephyr,代码行数:24,代码来源:UserCommand.java


示例5: onCast

import org.spongepowered.api.util.command.CommandSource; //导入依赖的package包/类
@Directive(names = { "cast" }, argumentLabels = {"spell", "args"}, arguments = {ArgumentType.OPTIONAL_SPELL, ArgumentType.OPTIONAL_REMAINING}, inGameOnly = true)
public static CommandResult onCast(CommandSource src, CommandContext context) {
	User user = Zephyr.getUserManager().getUser(((Player)src).getUniqueId());
	SpellManager manager = Zephyr.getSpellManager();
	if (context.getOne("spell").isPresent()) {
		Spell spell = manager.getSpell(context.<String>getOne("spell").get());
		Optional<String> options = context.<String>getOne("args");
		manager.cast(spell, new SpongeSpellContext(spell, user, options.isPresent() ? options.get().split(" ") : new String[0]));
		return CommandResult.success();
	} else {
		if (user.isCasting()) {
			user.setCasting(null, null);
		} else {
			user.sendMessage("Usage: /cast <spell> [args...]");
		}
		return CommandResult.success();
	}
}
 
开发者ID:mcardy,项目名称:Zephyr,代码行数:19,代码来源:SpellCommand.java


示例6: kick

import org.spongepowered.api.util.command.CommandSource; //导入依赖的package包/类
/**
 * Kick a player to join at this area
 *
 * @param sender who want to kick the player
 * @param target the player
 * @return the response.
 */
@Override
public ActionResponse kick( Object sender, UUID target )
{
    if ( sender instanceof CommandSource )
    {
        if ( sender instanceof Player )
        {
            if ( hasOwnerAccess( ( ( Player ) sender ).getUniqueId() ) )
            {
                return this.kick( target );
            }
            return ActionResponse.Failure.setMessage( "access" );
        }
        if ( ( ( CommandSource ) sender ).hasPermission( "oglofus.protection.bypass.kick" ) )
        {
            return this.kick( target );
        }
        return ActionResponse.Failure.setMessage( "access" );
    }
    return ActionResponse.Failure.setMessage( "object" );
}
 
开发者ID:nikosgram13,项目名称:OglofusProtection,代码行数:29,代码来源:OglofusProtectionStaff.java


示例7: invite

import org.spongepowered.api.util.command.CommandSource; //导入依赖的package包/类
@Override
public ActionResponse invite( Object sender, UUID target, ProtectionRegion region )
{
    if ( sender instanceof CommandSource )
    {
        if ( sender instanceof Player )
        {
            if ( region.getProtectionStaff().hasOwnerAccess( ( ( Player ) sender ).getUniqueId() ) )
            {
                //TODO: call the handler PlayerInviteHandler.
                return invite( target, region );
            }
            return ActionResponse.Failure.setMessage( "access" );
        }
        if ( ( ( CommandSource ) sender ).hasPermission( "oglofus.protection.bypass.invite" ) )
        {
            return invite( target, region );
        }
        return ActionResponse.Failure.setMessage( "access" );
    }
    return ActionResponse.Failure.setMessage( "object" );
}
 
开发者ID:nikosgram13,项目名称:OglofusProtection,代码行数:23,代码来源:OglofusInvitationManager.java


示例8: changeName

import org.spongepowered.api.util.command.CommandSource; //导入依赖的package包/类
/**
 * Change the region's name.
 *
 * @param sender who want to change the name.
 * @param name   the new name.
 * @return the response.
 */
@Override
public ActionResponse changeName( Object sender, String name )
{
    if ( sender instanceof CommandSource )
    {
        if ( sender instanceof Player )
        {
            if ( getProtectionStaff().hasOwnerAccess( ( ( Player ) sender ).getUniqueId() ) )
            {
                return this.changeName( name );
            }
            return ActionResponse.Failure.setMessage( "access" );
        }
        if ( ( ( CommandSource ) sender ).hasPermission( "oglofus.protection.bypass" ) )
        {
            return this.changeName( name );
        }
        return ActionResponse.Failure.setMessage( "access" );
    }
    return ActionResponse.Failure.setMessage( "object" );
}
 
开发者ID:nikosgram13,项目名称:OglofusProtection,代码行数:29,代码来源:OglofusProtectionRegion.java


示例9: complete

import org.spongepowered.api.util.command.CommandSource; //导入依赖的package包/类
@Override
public List<String> complete(CommandSource src, CommandArgs args, CommandContext context) {
	if (src instanceof Player) {
		return Zephyr.getUserManager().getUser(((Player)src).getUniqueId()).getUserData().getKnownSpells();
	}
	return null;
}
 
开发者ID:mcardy,项目名称:Zephyr,代码行数:8,代码来源:ArgumentType.java


示例10: commandAliasSet

import org.spongepowered.api.util.command.CommandSource; //导入依赖的package包/类
@Directive(names = {"c.set", "alias"}, description = "Sets an alias", inGameOnly = true, argumentLabels = {"key", "spell"}, arguments = {ArgumentType.STRING, ArgumentType.STRING})
public static CommandResult commandAliasSet(CommandSource src, CommandContext context) {
	User user = Zephyr.getUserManager().getUser(((Player)src).getUniqueId());
	String key = context.<String>getOne("key").get();
	String spellName = context.<String>getOne("spell").get();
	if (Zephyr.getSpellManager().getSpell(spellName) == null
			|| !user.getUserData().getKnownSpells().contains(spellName)) {
		user.sendMessage("You do not know a spell by that name");
		return CommandResult.success();
	}
	user.addAlias(key, Zephyr.getSpellManager().getSpell(spellName));
	user.sendMessage("Alias added: '/c " + key + "' will now cast " + spellName);
	return CommandResult.success();
}
 
开发者ID:mcardy,项目名称:Zephyr,代码行数:15,代码来源:UserCommand.java


示例11: process

import org.spongepowered.api.util.command.CommandSource; //导入依赖的package包/类
public CommandResultWithChat process(CommandSource source, String command) {
	ChatKeepingCommandSource wrappedSource = wrap(source);
	CommandService commandService = game.getCommandDispatcher();
	CommandResult result = commandService.process(wrappedSource, command);
	// TODO Ideally make this more robust.. would require changes to core Sponge
	assertDoesNotContainIgnoreCase(wrappedSource, "commands.generic.notFound"); // "Unknown command"
	assertDoesNotContainIgnoreCase(wrappedSource, "Error occurred while executing command"); // as in SimpleCommandService
	Chat thisChat = new Chat() {
		@Override
		public List<Text> getMessages() {
			return pluginCapturedMessages;
		}
	};
	return new CommandResultWithChat(result, thisChat);
}
 
开发者ID:vorburger,项目名称:SwissKnightMinecraft,代码行数:16,代码来源:CommandTestHelper.java


示例12: onGameInitialization

import org.spongepowered.api.util.command.CommandSource; //导入依赖的package包/类
@Listener
public final void onGameInitialization(GameInitializationEvent event) {
	CommandSpec commandSpec = CommandSpec.builder()
			.description(Texts.of("Hello World Command"))
			.permission("myplugin.command.helloworld")
			.executor(new CommandExecutor() {
				@Override
				public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
					throw new InvocationCommandException(Texts.of("bad boy command failure"), new IllegalStateException("root cause IllegalStateException"));
				}
			})
			.build();

	commandMapping = game.getCommandDispatcher().register(plugin, commandSpec, TEST_BAD_COMMAND).get();
}
 
开发者ID:vorburger,项目名称:SwissKnightMinecraft,代码行数:16,代码来源:TestPlugin.java


示例13: execute

import org.spongepowered.api.util.command.CommandSource; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    if (src instanceof Player) {
        Player player = (Player) src;
        return execute(plugin.getClaimManager().getClaimFor(player.getLocation()),
                plugin.getTenantManager().getTentant(player).get(), args, player);
    }
    src.sendMessage(Texts.of("Only a player can execute this command!"));
    return CommandResult.empty();
}
 
开发者ID:thomas15v,项目名称:ChunkLord,代码行数:11,代码来源:AbstractClaimCommand.java


示例14: sendMessage

import org.spongepowered.api.util.command.CommandSource; //导入依赖的package包/类
public void sendMessage(CommandSource src, Messages message, TextColor color, String... strings ){
    if (!message.isRepeat() && lastmessages.get(src.getName()) == message)
            return;
    lastmessages.put(src.getName(), message);
    src.sendMessage(Texts.builder().color(color).
            append(get(message, strings)).
            build());
}
 
开发者ID:thomas15v,项目名称:ChunkLord,代码行数:9,代码来源:LanguageManager.java


示例15: send

import org.spongepowered.api.util.command.CommandSource; //导入依赖的package包/类
@Override
public void send(CommandSource recipient, Request request)
{
    requestCache.put(recipient, request);
    recipient.sendMessage(request.getMessage(), requestMessage);

    // Occupy the commands (Other DoubleCheck instances will listen for the event)
    game.getEventManager().post(new CommandOccupationEvent(this, recipient, confirmAlias));
    game.getEventManager().post(new CommandOccupationEvent(this, recipient, denyAlias));
}
 
开发者ID:boformer,项目名称:DoubleCheck,代码行数:11,代码来源:DoubleCheckService.java


示例16: respond

import org.spongepowered.api.util.command.CommandSource; //导入依赖的package包/类
public void respond(CommandSource sender, Message.Text message, ResponseLevel level) {
    Message.Text response = message;
    if (!getResponsePrefix().isEmpty()) {
        response = Messages.builder(getResponsePrefix() + " ").append(format(message)).build();
    }
    respondAnonymously(sender, response, level);
}
 
开发者ID:DSH105,项目名称:Influx,代码行数:8,代码来源:SpongeResponder.java


示例17: SpongeCommandManager

import org.spongepowered.api.util.command.CommandSource; //导入依赖的package包/类
public SpongeCommandManager(SpongeRegistry registry, Object plugin, Game game) {
    super("/");
    Affirm.notNull(game);
    this.pluginContainer = game.getPluginManager().fromInstance(plugin).orNull();
    if (this.pluginContainer == null) {
        throw new IllegalArgumentException("Provided plugin instance must be annotated with @Plugin.");
    }
    this.game = game;
    this.dispatcher = new SpongeDispatcher(this);
    this.setHelpTitle(pluginContainer.getName());
    this.setResponseHandler(new SpongeResponder(""));
    this.setHelpProvision(HelpProvision.SPONGE);
    this.setAuthorization(new Authorization<CommandSource>() {
        @Override
        public boolean authorize(CommandSource sender, Controller toExecute, String permission) {
            if (sender instanceof Player) {
                return getGame().getServiceManager().provideUnchecked(PermissionService.class).login((Player) sender).isPermitted(permission);
            }
            // console, command block, etc.
            return true;
        }
    });
    if (registry != null) {
        this.setRegistrationStrategy(registry);
    }
    this.setMessage(MessagePurpose.RESTRICTED_SENDER, "Please log in to perform that command.");
}
 
开发者ID:DSH105,项目名称:Influx,代码行数:28,代码来源:SpongeCommandManager.java


示例18: getHelp

import org.spongepowered.api.util.command.CommandSource; //导入依赖的package包/类
@Override
public SpongeHelpProvider<CommandSource> getHelp() {
    try {
        return (SpongeHelpProvider<CommandSource>) super.getHelp();
    } catch (ClassCastException e) {
        throw new IllegalStateException("Help provider must be a SpongeHelpProvider");
    }
}
 
开发者ID:DSH105,项目名称:Influx,代码行数:9,代码来源:SpongeCommandManager.java


示例19: InfluxSpongeCallable

import org.spongepowered.api.util.command.CommandSource; //导入依赖的package包/类
public InfluxSpongeCallable(InfluxManager<?> manager, Object plugin, Game game, SpongeCommandDispatcher dispatcher, Authorization<CommandSource> authorization, Controller controller) {
    this.manager = manager;
    this.controller = controller;
    this.plugin = plugin;
    this.game = game;
    this.dispatcher = dispatcher;
    this.authorization = authorization;
}
 
开发者ID:DSH105,项目名称:Influx,代码行数:9,代码来源:InfluxSpongeCallable.java


示例20: testPermission

import org.spongepowered.api.util.command.CommandSource; //导入依赖的package包/类
@Override
public boolean testPermission(CommandSource source) {
    for (String permission : controller.getCommand().getPermissions()) {
        if (!authorization.authorize(source, controller, permission)) {
            return false;
        }
    }
    return true;
}
 
开发者ID:DSH105,项目名称:Influx,代码行数:10,代码来源:InfluxSpongeCallable.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Transaction类代码示例发布时间:2022-05-22
下一篇:
Java StackTraceElementMessage类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap