本文整理汇总了Java中org.spongepowered.api.command.CommandResult类的典型用法代码示例。如果您正苦于以下问题:Java CommandResult类的具体用法?Java CommandResult怎么用?Java CommandResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CommandResult类属于org.spongepowered.api.command包,在下文中一共展示了CommandResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.spongepowered.api.command.CommandResult; //导入依赖的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();
}
示例2: execute
import org.spongepowered.api.command.CommandResult; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource source, CommandContext context) throws CommandException
{
HashSet<Faction> factionsList = new HashSet<>(FactionLogic.getFactions());
List<Text> helpList = new ArrayList<>();
for(Faction faction: factionsList)
{
String tag = "";
if(faction.Tag != null && !faction.Tag.equals("")) tag = "[" + faction.Tag + "] ";
Text factionHelp = Text.builder()
.append(Text.builder()
.append(Text.of(TextColors.AQUA, "- " + tag + faction.Name + " (" + faction.Power + "/" + PowerService.getFactionMaxPower(faction) + ")"))
.build())
.build();
helpList.add(factionHelp);
}
PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get();
PaginationList.Builder paginationBuilder = paginationService.builder().title(Text.of(TextColors.GREEN, "Factions List")).padding(Text.of("-")).contents(helpList);
paginationBuilder.sendTo(source);
return CommandResult.success();
}
示例3: execute
import org.spongepowered.api.command.CommandResult; //导入依赖的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();
}
示例4: execServer
import org.spongepowered.api.command.CommandResult; //导入依赖的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();
}
示例5: execute
import org.spongepowered.api.command.CommandResult; //导入依赖的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();
}
示例6: execute
import org.spongepowered.api.command.CommandResult; //导入依赖的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();
}
示例7: execute
import org.spongepowered.api.command.CommandResult; //导入依赖的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();
}
示例8: execute
import org.spongepowered.api.command.CommandResult; //导入依赖的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();
}
}
示例9: execute
import org.spongepowered.api.command.CommandResult; //导入依赖的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();
}
}
示例10: execute
import org.spongepowered.api.command.CommandResult; //导入依赖的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();
}
示例11: execute
import org.spongepowered.api.command.CommandResult; //导入依赖的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();
}
}
示例12: execute
import org.spongepowered.api.command.CommandResult; //导入依赖的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();
}
示例13: accept
import org.spongepowered.api.command.CommandResult; //导入依赖的package包/类
@Override
public void accept(CommandResult commandResult)
{
Player player = playerReference.get();
if (!Objects.isNull(player))
{
Tuple<String, String> t = commandList.poll();
if (Objects.isNull(t))
{
permissionMap.removeAll(this);
permissionManager.setIgnored(player, permissionMap.values());
}
else
{
activatedPlayers.add(player.getUniqueId());
String prefix = t.getFirst(), suffix = t.getSecond();
String command = prefix.isEmpty() ? suffix : prefix + ": " + suffix;
String escapedCommand = '\'' + SpongeUnimplemented.escapeString(command) + '\'';
logger.debug("Player {} is now executing {}", player.getName(), escapedCommand);
executors.get(prefix).doAction(player, suffix, this);
}
}
}
示例14: execute
import org.spongepowered.api.command.CommandResult; //导入依赖的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();
}
示例15: execute
import org.spongepowered.api.command.CommandResult; //导入依赖的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();
}