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

Java CommandResult类代码示例

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

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



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

示例1: commandMana

import org.spongepowered.api.util.command.CommandResult; //导入依赖的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.CommandResult; //导入依赖的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.CommandResult; //导入依赖的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.CommandResult; //导入依赖的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.CommandResult; //导入依赖的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: execute

import org.spongepowered.api.util.command.CommandResult; //导入依赖的package包/类
@Override
public CommandResult execute(Optional<Claim> claimOptional, Tenant tenant, CommandContext args, Player player) throws CommandException {
    if (claimOptional.isPresent()){
        Claim claim = claimOptional.get();
        try {
            if (claim.getOwner().getId().equals(player.getUniqueId()) || player.hasPermission(Permissions.ADMINUNCLAIM))
            {
                plugin.getClaimManager().removeClaim(player.getLocation());
                plugin.getLanguageManager().sendMessage(player, Messages.LAND_UNCLAIMED, TextColors.GREEN);
            }
            else
                plugin.getLanguageManager().sendMessage(player, Messages.NO_ACCES_TO_UNCLAIM, TextColors.RED);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }else {
        plugin.getLanguageManager().sendMessage(player, Messages.NO_CLAIM_TO_UNCLAIM, TextColors.YELLOW);
    }
    return CommandResult.success();
}
 
开发者ID:thomas15v,项目名称:ChunkLord,代码行数:22,代码来源:UnclaimCommand.java


示例7: execute

import org.spongepowered.api.util.command.CommandResult; //导入依赖的package包/类
@Override
public CommandResult execute(Optional<Claim> claimOptional, Tenant tenant, CommandContext args, Player player) throws CommandException {
    if (claimOptional.isPresent()){
        Claim claim = claimOptional.get();
        languageManager.sendMessage(player, Messages.CLAIM_INFO, TextColors.AQUA,
                player.getWorld().getName(),
                String.valueOf(claim.getX()),
                String.valueOf(claim.getZ()),
                claim.getOwner().getName(),
                "",
                "");
    }else {
        languageManager.sendMessage(player, Messages.NO_CLAIM_FOUND, TextColors.YELLOW);
    }
    return CommandResult.success();
}
 
开发者ID:thomas15v,项目名称:ChunkLord,代码行数:17,代码来源:ClaimInfoCommand.java


示例8: onCommand

import org.spongepowered.api.util.command.CommandResult; //导入依赖的package包/类
@Subscribe(order = Order.LATE)
public void onCommand(CommandEvent event)
{
    boolean confirm = event.getCommand().equalsIgnoreCase(confirmAlias);
    boolean deny = event.getCommand().equalsIgnoreCase(denyAlias);

    if (confirm || deny)
    {
        Request request = requestCache.getIfPresent(event.getSource());
        if (request != null)
        {
            event.setCancelled(true);
            event.setResult(CommandResult.empty());
            
            if (confirm) request.confirm(event.getSource());
            else request.deny(event.getSource());
            
            // Remove the request from cache
            requestCache.invalidate(event.getSource());
        }
    }
}
 
开发者ID:boformer,项目名称:DoubleCheck,代码行数:23,代码来源:DoubleCheckService.java


示例9: commandAliasSet

import org.spongepowered.api.util.command.CommandResult; //导入依赖的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


示例10: process

import org.spongepowered.api.util.command.CommandResult; //导入依赖的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


示例11: assertSuccessCount

import org.spongepowered.api.util.command.CommandResult; //导入依赖的package包/类
public void assertSuccessCount(CommandResult result) throws AssertionError {
	if (!result.getSuccessCount().isPresent())
		throw new AssertionError("CommandResult has no (empty) successCount");
	int successCount = result.getSuccessCount().get().intValue();
	if (successCount < 1)
		throw new AssertionError("CommandResult had successCount != 1: " + successCount);
}
 
开发者ID:vorburger,项目名称:SwissKnightMinecraft,代码行数:8,代码来源:CommandTestHelper.java


示例12: onGameInitialization

import org.spongepowered.api.util.command.CommandResult; //导入依赖的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.CommandResult; //导入依赖的package包/类
@Override
public CommandResult execute(Optional<Claim> claimOptional, Tenant tenant, CommandContext args, Player player) throws CommandException {;
    if (claimOptional.isPresent()){
        languageManager.sendMessage(player, Messages.ALREADY_CLAIMED_BY, TextColors.RED,
                claimOptional.get().getOwner().getName());
    }else {
        plugin.getClaimManager().addClaim(player.getWorld(), new Claim(tenant, player.getLocation().getBlockPosition().div(16)));
        languageManager.sendMessage(player, Messages.LAND_CLAIMED, TextColors.GREEN);
    }
    return CommandResult.success();
}
 
开发者ID:thomas15v,项目名称:ChunkLord,代码行数:12,代码来源:ClaimCommand.java


示例14: execute

import org.spongepowered.api.util.command.CommandResult; //导入依赖的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


示例15: exampleCommand

import org.spongepowered.api.util.command.CommandResult; //导入依赖的package包/类
@Directive(names = { "example", "test" }, description = "An example command", permission = "demo.command")
// Method is static, returns CommandResult and has CommandSource and CommandContext as arguments
public static CommandResult exampleCommand(CommandSource src, CommandContext args) {
	src.sendMessage(Texts.of("Hello world! This is an example command"));
	return CommandResult.success();
}
 
开发者ID:mcardy,项目名称:Directive,代码行数:7,代码来源:DemoPlugin.java


示例16: exampleSubCommand

import org.spongepowered.api.util.command.CommandResult; //导入依赖的package包/类
@Directive(names = {"example.sub"})
public static CommandResult exampleSubCommand(CommandSource src, CommandContext args) {
	src.sendMessage(Texts.of("Hello world! This is an example sub command"));
	return CommandResult.success();
}
 
开发者ID:mcardy,项目名称:Directive,代码行数:6,代码来源:DemoPlugin.java


示例17: exampleArgumentCommand

import org.spongepowered.api.util.command.CommandResult; //导入依赖的package包/类
@Directive(names = {"exargs"}, argumentLabels = {"msg"}, arguments = {ArgumentType.OPTIONAL_STRING})
public static CommandResult exampleArgumentCommand(CommandSource src, CommandContext args) {
	// Get the msg from args
	src.sendMessage(Texts.of(args.<String>getOne("msg").get()));
	return CommandResult.success();
}
 
开发者ID:mcardy,项目名称:Directive,代码行数:7,代码来源:DemoPlugin.java


示例18: addDirective

import org.spongepowered.api.util.command.CommandResult; //导入依赖的package包/类
/**
 * Adds a directive method
 * @param executor The executor method
 * @throws Exception Thrown if method has an issue
 */
public void addDirective(Method executor) throws Exception {
	Directive directive = executor.getAnnotation(Directive.class);
	if (directive == null) {
		throw new Exception("Error registering directive method " + executor.getName() + ": No directive");
	}
	if (!Modifier.isStatic(executor.getModifiers())) {
		throw new Exception("Error registering directive method " + executor.getName() + ": Method not static!");
	}
	if (executor.getParameterTypes()[0] != CommandSource.class ||
			executor.getParameterTypes()[1] != CommandContext.class) {
		throw new Exception("Error registering directive method " + executor.getName() + ": Incorrect arguments. " +
			"Must have CommandSource as first argument and CommandContext as second.");
	}
	if (executor.getReturnType() != CommandResult.class) {
		throw new Exception("Error registering directive method " + executor.getName() + ": Incorrect return type. " +
			"Directive must return type of CommandResult.");
	}
	if (directive.arguments().length != directive.argumentLabels().length) {
		throw new Exception("Error registering directive method " + executor.getName() + ": Mismatched arguments. " +
				"arguments and argumentLabels lengths must match.");
	}
	String[] labels = directive.names();
	for (String label : labels) {
		String[] cmd = label.split("\\.");
		DirectiveTree current = null;
		DirectiveTree next = null;
		for (int i = 0; i < cmd.length; i++) {
			// Set the next directive
			if (current == null) {
				next = this.getDirective(cmd[i]);
			} else {
				next = current.getSubDirective(cmd[i]);
			}
			// Check the next directive, create if necessary
			if (next == null && current == null) {
				next = new DirectiveTree(cmd[i], null);
				this.commands.add(next);
			} else if (next == null) {
				next = new DirectiveTree(cmd[i], null);
				current.addSubDirective(next);
			}
			// Set current to next
			current = next;
			// Set executor if not set yet
			if (i+1==cmd.length) {
				current.setExecutor(executor);
			}
		}
	}
}
 
开发者ID:mcardy,项目名称:Directive,代码行数:56,代码来源:DirectiveHandler.java


示例19: execute

import org.spongepowered.api.util.command.CommandResult; //导入依赖的package包/类
@Override
public final CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    try {
        if (args.hasAny("username")) {
            String username = args.<String>getOne("username").get();
            Profile profile = profileResolver.findByName(username);
            if (profile == null) {
                src.sendMessage(Texts.of(TextColors.RED,"Sorry failed to find a profile for that username."));
                return CommandResult.empty();
            }
            src.sendMessage(Texts.of(TextColors.GREEN, "Found a profile for the provided username."));
            ClickAction.SuggestCommand clickAction = new ClickAction.SuggestCommand(profile.getUniqueId().toString());
            Text clickableUUID = Texts.builder()
                    .append(Texts.of(TextColors.GREEN, profile.getUniqueId().toString()))
                    .onClick(clickAction).build();
            src.sendMessage(Texts.of(TextColors.BLUE, profile.getName(), TextColors.GRAY, ": ", clickableUUID));

            MinecraftSkin skin = game.getServiceManager().provideUnchecked(SkinResolverService.class).getSkin(profile.getUniqueId());
            if (skin == null) {
                src.sendMessage(Texts.of(TextColors.RED, "Failed to resolve skin for the profile."));
            } else {
                src.sendMessage(Texts.of(TextColors.GREEN, "Skin type: ", skin.type));
                ColorMapping mapping = ColorMapping.matchColor(new Color(skin.texture.getRGB(12, 12)));
                String message = String.format("The matching block was %s and the color was %s", mapping.equivalentBlock.toString(), mapping.dyeColor.orNull() == null ? "null" : mapping.dyeColor.toString());

                if (src instanceof Player) {
                    Player player = (Player) src;
                    Vector3d rot = player.getRotation();
                    int value = floor_double((double)(rot.getX() * 4.0F / 360.0F) + 0.5D) & 3;
                    System.out.println(value);
                    player.sendMessage(Texts.of((rot.getX() * 4.0F / 360.0F) + 0.5D));
                    player.sendMessage(Texts.of(rot.getX() * 4.0F / 360.0F));
                    player.sendMessage(Texts.of(value));
                    int pos = ((value < 0 ? -value : value) % 4);
                    Direction buildDirection = null;
                    switch (pos) {
                        case 0:
                            // South
                            System.out.println("SOUTH");
                            player.sendMessage(Texts.of("SOUTH"));
                            buildDirection = Direction.SOUTH;
                            break;
                        case 1:
                            // WEST
                            System.out.println("WEST");
                            player.sendMessage(Texts.of("WEST"));
                            buildDirection = Direction.WEST;
                            break;
                        case 2:
                            // NORTH
                            System.out.println("NORTH");
                            player.sendMessage(Texts.of("NORTH"));
                            buildDirection = Direction.NORTH;
                            break;
                        case 3:
                            // EAST
                            System.out.println("EAST");
                            player.sendMessage(Texts.of("EAST"));
                            buildDirection = Direction.EAST;
                            break;
                    }

                }
            }
            return CommandResult.success();
        }
        return CommandResult.empty();
    } catch (Throwable th) {
        th.printStackTrace();
        return CommandResult.empty();
    }
}
 
开发者ID:modwizcode,项目名称:Statue,代码行数:73,代码来源:TestResolveCommand.java


示例20: CommandResultWithChat

import org.spongepowered.api.util.command.CommandResult; //导入依赖的package包/类
protected CommandResultWithChat(CommandResult result, Chat chat) {
	this.result = result;
	this.chat = chat;
}
 
开发者ID:vorburger,项目名称:SwissKnightMinecraft,代码行数:5,代码来源:CommandTestHelper.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java Level类代码示例发布时间:2022-05-22
下一篇:
Java XMLElementDecl类代码示例发布时间: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