Java Code Examples for org.spongepowered.api.command.CommandResult#empty()

The following examples show how to use org.spongepowered.api.command.CommandResult#empty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClaimCommand.java    From EagleFactions with MIT License 6 votes vote down vote up
private CommandResult preformAdminClaim(final Player player, final Faction faction, final Vector3i chunk) throws CommandException
{
    final World world = player.getWorld();
    final boolean safeZoneWorld = this.protectionConfig.getSafeZoneWorldNames().contains(world.getName());
    final boolean warZoneWorld = this.protectionConfig.getWarZoneWorldNames().contains(world.getName());

    //Even admin cannot claim territories in safezone nor warzone world.
    if (safeZoneWorld || warZoneWorld)
        throw new CommandException(PluginInfo.ERROR_PREFIX.concat(Text.of(TextColors.RED, Messages.YOU_CANNOT_CLAIM_TERRITORIES_IN_THIS_WORLD)));

    boolean isCancelled = EventRunner.runFactionClaimEvent(player, faction, player.getWorld(), chunk);
    if (isCancelled)
        return CommandResult.empty();

    super.getPlugin().getFactionLogic().addClaim(faction, new Claim(player.getWorld().getUniqueId(), chunk));
    player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, Messages.LAND + " ", TextColors.GOLD, chunk.toString(), TextColors.WHITE, " " + Messages.HAS_BEEN_SUCCESSFULLY + " ", TextColors.GOLD, Messages.CLAIMED, TextColors.WHITE, "!"));
    return CommandResult.success();
}
 
Example 2
Source File: CmdBlockUpdatesStop.java    From Web-API with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    Optional<BlockOperation> op = args.getOne("uuid");
    if (!op.isPresent()) {
        src.sendMessage(Text.builder("Invalid block operation uuid!")
                .color(TextColors.DARK_RED)
                .build());
        return CommandResult.empty();
    }

    op.get().stop(null);
    src.sendMessage(Text.builder("Successfully cancelled block operation")
            .color(TextColors.DARK_GREEN)
            .build());
    return CommandResult.success();
}
 
Example 3
Source File: CmdBlockUpdatesPause.java    From Web-API with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    Optional<BlockOperation> op = args.getOne("uuid");
    if (!op.isPresent()) {
        src.sendMessage(Text.builder("Invalid block operation uuid!")
                .color(TextColors.DARK_RED)
                .build());
        return CommandResult.empty();
    }

    if (op.get().getStatus() == BlockOperationStatus.RUNNING) {
        op.get().pause();
    } else {
        op.get().start();
    }

    return CommandResult.success();
}
 
Example 4
Source File: SelectCommand.java    From ChangeSkin with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext args) {
    if (!(src instanceof Player)) {
        plugin.sendMessage(src, "no-console");
        return CommandResult.empty();
    }

    String skinName = args.<String>getOne("skinName").get().toLowerCase().replace("skin-", "");

    try {
        int targetId = Integer.parseInt(skinName);
        Player receiver = (Player) src;
        Task.builder().async().execute(new SkinSelector(plugin, receiver, targetId)).submit(plugin);
    } catch (NumberFormatException numberFormatException) {
        plugin.sendMessage(src, "invalid-skin-name");
    }

    return CommandResult.success();
}
 
Example 5
Source File: PardonExecutor.java    From EssentialCmds with MIT License 6 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	Game game = EssentialCmds.getEssentialCmds().getGame();
	User player = ctx.<User> getOne("player").get();

	BanService srv = game.getServiceManager().provide(BanService.class).get();
	if (!srv.isBanned(player.getProfile()))
	{
		src.sendMessage(Text.of(TextColors.RED, "That player is not currently banned."));
		return CommandResult.empty();
	}

	srv.removeBan(srv.getBanFor(player.getProfile()).get());
	src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, player.getName() + " has been unbanned."));
	return CommandResult.success();
}
 
Example 6
Source File: SpongeCommands.java    From BlueMap with MIT License 6 votes vote down vote up
@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
	String command = label;
	if (!arguments.isEmpty()) {
		command += " " + arguments;
	}
	
	try {
		return CommandResult.successCount(dispatcher.execute(command, source));
	} catch (CommandSyntaxException ex) {
		source.sendMessage(Text.of(TextColors.RED, ex.getRawMessage().getString()));
		
		String context = ex.getContext();
		if (context != null) source.sendMessage(Text.of(TextColors.GRAY, context));
		
		return CommandResult.empty();
	}
}
 
Example 7
Source File: InfoCommand.java    From ChangeSkin with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    if (!(src instanceof Player)) {
        plugin.sendMessage(src, "no-console");
        return CommandResult.empty();
    }

    UUID uniqueId = ((Player) src).getUniqueId();
    Task.builder().async()
            .execute(() -> {
                UserPreference preferences = plugin.getCore().getStorage().getPreferences(uniqueId);
                Task.builder().execute(() -> sendSkinDetails(uniqueId, preferences)).submit(plugin);
            })
            .submit(plugin);

    return null;
}
 
Example 8
Source File: CmdUserAdd.java    From Web-API with MIT License 5 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext args) {
    Optional<String> optUsername = args.getOne("username");
    if (!optUsername.isPresent()) {
        return CommandResult.empty();
    }
    String username = optUsername.get();

    Optional<String> optPassword = args.getOne("password");
    String password = optPassword.orElse(Util.generateUniqueId().substring(0, 8));

    Optional<UserPermissionStruct> optUser = WebAPI.getUserService().addUser(
            username, password, SecurityService.permitAllNode());

    if (!optUser.isPresent()) {
        src.sendMessage(Text.builder("A user with this name already exists").color(TextColors.RED).build());
        return CommandResult.empty();
    }

    if (!optPassword.isPresent()) {
        src.sendMessage(Text.builder("Created user ")
                .append(Text.builder(username).color(TextColors.GOLD).build())
                .append(Text.of(" with password "))
                .append(Text.builder(password).color(TextColors.GOLD).build())
                .build());
    } else {
        src.sendMessage(Text.builder("Created user ")
                .append(Text.builder(username).color(TextColors.GOLD).build())
                .build());
    }

    return CommandResult.success();
}
 
Example 9
Source File: TempBanExecutor.java    From EssentialCmds with MIT License 5 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	Game game = EssentialCmds.getEssentialCmds().getGame();
	User player = ctx.<User> getOne("player").get();
	String time = ctx.<String> getOne("time").get();
	String reason = ctx.<String> getOne("reason").orElse("The BanHammer has spoken!");

	BanService srv = game.getServiceManager().provide(BanService.class).get();

	if (srv.isBanned(player.getProfile()))
	{
		src.sendMessage(Text.of(TextColors.RED, "That player has already been banned."));
		return CommandResult.empty();
	}

	srv.addBan(Ban.builder()
		.type(BanTypes.PROFILE)
		.source(src).profile(player.getProfile())
		.expirationDate(getInstantFromString(time))
		.reason(TextSerializers.formattingCode('&').deserialize(reason))
		.build());

	if (player.isOnline())
	{
		player.getPlayer().get().kick(Text.builder()
			.append(Text.of(TextColors.DARK_RED, "You have been tempbanned!\n", TextColors.RED, "Reason: "))
			.append(TextSerializers.formattingCode('&').deserialize(reason), Text.of("\n"))
			.append(Text.of(TextColors.GOLD, "Time: ", TextColors.GRAY, getFormattedString(time)))
			.build());
	}

	src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, player.getName() + " has been banned."));
	return CommandResult.success();
}
 
Example 10
Source File: SetCommand.java    From ChangeSkin with MIT License 5 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext args) {
    if (!(src instanceof Player)) {
        plugin.sendMessage(src, "no-console");
        return CommandResult.empty();
    }

    UUID uniqueId = ((Player) src).getUniqueId();
    if (core.getCooldownService().isTracked(uniqueId)) {
        plugin.sendMessage(src, "cooldown");
        return CommandResult.empty();
    }

    Player receiver = (Player) src;
    String targetSkin = args.<String>getOne("skin").get();
    boolean keepSkin = args.hasAny("keep");

    if ("reset".equals(targetSkin)) {
        targetSkin = receiver.getUniqueId().toString();
    }

    if (targetSkin.length() > 16) {
        UUID targetUUID = UUID.fromString(targetSkin);

        if (core.getConfig().getBoolean("skinPermission") && !plugin.hasSkinPermission(src, targetUUID, true)) {
            return CommandResult.empty();
        }

        plugin.sendMessage(src, "skin-change-queue");
        Runnable skinDownloader = new SkinDownloader(plugin, src, receiver, targetUUID, keepSkin);
        Task.builder().async().execute(skinDownloader).submit(plugin);
        return CommandResult.success();
    }

    Runnable nameResolver = new NameResolver(plugin, src, targetSkin, receiver, keepSkin);
    Task.builder().async().execute(nameResolver).submit(plugin);
    return CommandResult.success();
}
 
Example 11
Source File: BanExecutor.java    From EssentialCmds with MIT License 5 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	Game game = EssentialCmds.getEssentialCmds().getGame();
	User player = ctx.<User> getOne("player").get();
	String reason = ctx.<String> getOne("reason").orElse("The BanHammer has spoken!");

	BanService srv = game.getServiceManager().provide(BanService.class).get();

	if (srv.isBanned(player.getProfile()))
	{
		src.sendMessage(Text.of(TextColors.RED, "That player has already been banned."));
		return CommandResult.empty();
	}
	
	srv.addBan(Ban.builder().type(BanTypes.PROFILE).source(src).profile(player.getProfile()).reason(TextSerializers.formattingCode('&').deserialize(reason)).build());

	if (player.isOnline())
	{
		player.getPlayer().get().kick(Text.builder()
			.append(Text.of(TextColors.DARK_RED, "You have been banned!\n ", TextColors.RED, "Reason: "))
			.append(TextSerializers.formattingCode('&').deserialize(reason))
			.build());
	}

	src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, player.getName() + " has been banned."));
	return CommandResult.success();
}
 
Example 12
Source File: TestVoteCmd.java    From NuVotifier with GNU General Public License v3.0 5 votes vote down vote up
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    Vote v;
    try {
        Collection<String> a = args.getAll("args");
        v = ArgsToVote.parse(a.toArray(new String[0]));
    } catch (IllegalArgumentException e) {
        sender.sendMessage(Text.builder("Error while parsing arguments to create test vote: " + e.getMessage()).color(TextColors.DARK_RED).build());
        sender.sendMessage(Text.builder("Usage hint: /testvote [username] [serviceName=?] [username=?] [address=?] [localTimestamp=?] [timestamp=?]").color(TextColors.GRAY).build());
        return CommandResult.empty();
    }

    plugin.onVoteReceived(v, VotifierSession.ProtocolVersion.TEST, "localhost.test");
    return CommandResult.success();
}
 
Example 13
Source File: InvalidateCommand.java    From ChangeSkin with MIT License 5 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext args) {
    if (!(src instanceof Player)) {
        plugin.sendMessage(src, "no-console");
        return CommandResult.empty();
    }

    Player receiver = (Player) src;
    Task.builder().async().execute(new SkinInvalidator(plugin, receiver)).submit(plugin);
    return CommandResult.success();
}
 
Example 14
Source File: CmdUserChangePassword.java    From Web-API with MIT License 5 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    Optional<String> optUsername = args.getOne("username");
    if (!optUsername.isPresent()) {
        return CommandResult.empty();
    }
    String username = optUsername.get();

    Optional<String> optPassword = args.getOne("password");
    if (!optPassword.isPresent()) {
        return CommandResult.empty();
    }
    String password = optPassword.get();

    UserService srv = WebAPI.getUserService();

    Optional<UserPermissionStruct> optUser = srv.getUser(username);
    if (!optUser.isPresent()) {
        src.sendMessage(Text.builder("Could not find user '" + username + "'").color(TextColors.RED).build());
        return CommandResult.empty();
    }

    UserPermissionStruct user = optUser.get();

    user.setPassword(srv.hashPassword(password));
    src.sendMessage(Text.builder("Changed password for ")
            .append(Text.builder(username).color(TextColors.GOLD).build())
            .build());

    srv.save();
    return CommandResult.success();
}
 
Example 15
Source File: ClaimCommand.java    From EagleFactions with MIT License 5 votes vote down vote up
private CommandResult preformNormalClaim(final Player player, final Faction faction, final Vector3i chunk) throws CommandException
{
    final World world = player.getWorld();
    final boolean isClaimableWorld = this.protectionConfig.getClaimableWorldNames().contains(world.getName());

    if(!isClaimableWorld)
        throw new CommandException(PluginInfo.ERROR_PREFIX.concat(Text.of(TextColors.RED, Messages.YOU_CANNOT_CLAIM_TERRITORIES_IN_THIS_WORLD)));

    //If not admin then check faction perms for player
    if (!this.getPlugin().getPermsManager().canClaim(player.getUniqueId(), faction))
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.PLAYERS_WITH_YOUR_RANK_CANT_CLAIM_LANDS));

    //Check if faction has enough power to claim territory
    if (super.getPlugin().getPowerManager().getFactionMaxClaims(faction) <= faction.getClaims().size())
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOUR_FACTION_DOES_NOT_HAVE_POWER_TO_CLAIM_MORE_LANDS));

    //If attacked then It should not be able to claim territories
    if (EagleFactionsPlugin.ATTACKED_FACTIONS.containsKey(faction.getName()))
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOUR_FACTION_IS_UNDER_ATTACK + " " + MessageLoader.parseMessage(Messages.YOU_NEED_TO_WAIT_NUMBER_MINUTES_TO_BE_ABLE_TO_CLAIM_AGAIN, TextColors.RED, Collections.singletonMap(Placeholders.NUMBER, Text.of(TextColors.GOLD, EagleFactionsPlugin.ATTACKED_FACTIONS.get(faction.getName()))))));

    if (this.factionsConfig.requireConnectedClaims() && !super.getPlugin().getFactionLogic().isClaimConnected(faction, new Claim(world.getUniqueId(), chunk)))
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.CLAIMS_NEED_TO_BE_CONNECTED));

    boolean isCancelled = EventRunner.runFactionClaimEvent(player, faction, world, chunk);
    if (isCancelled)
        return CommandResult.empty();

    super.getPlugin().getFactionLogic().startClaiming(player, faction, world.getUniqueId(), chunk);
    return CommandResult.success();
}
 
Example 16
Source File: RTPExecutor.java    From EssentialCmds with MIT License 4 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	int tryTimes = 10;

	if (src instanceof Player)
	{
		Player player = (Player) src;
		//Why 3999? why hard code it?
		Optional<Location<World>> optionalLocation = randomLocation(player, 3999);
		if (optionalLocation.isPresent())
		{
			//Why check danger? shouldn't safe teleport have already checked this?
			if (isDangerous(optionalLocation))
			{
				//restrict the number of times we check, as every time we do this we are loading chunks...
				for(int i = 0; i < tryTimes; i++)
				{
					//Why 10000? are we supposed to be "less fussy" or something?
					// we only checked a width of 9 by default with safe teleport
					optionalLocation = randomLocation(player, 10000);
					//repeated isDanger check, when we have already checked it in safeTeleport
					if (optionalLocation.isPresent() && !isDangerous(optionalLocation))
					{
						teleportPlayer(player, optionalLocation);
						return CommandResult.success();
					}
				}
				player.sendMessage(Text.of(TextColors.DARK_RED, "A safe random location was not found, please try again"));
				return CommandResult.empty();
			} else {
				teleportPlayer(player, optionalLocation);
				return CommandResult.success();
			}
		}
		else
		{
			for(int i = 0; i < tryTimes; i++)
			{
				optionalLocation = randomLocation(player, 10000);
				//swapping to isWet? but the danger check is already done in safe teleport
				if (optionalLocation.isPresent() && !isWet(optionalLocation))
				{
					teleportPlayer(player, optionalLocation);
					return CommandResult.success();
				}
			}
			player.sendMessage(Text.of(TextColors.DARK_RED, "A safe random location was not found, please try again"));
			return CommandResult.empty();
		}
	}
	else if (src instanceof ConsoleSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /rtp!"));
		return CommandResult.empty();
	}
	else if (src instanceof CommandBlockSource)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /rtp!"));
		return CommandResult.empty();
	}

	return CommandResult.success();
}
 
Example 17
Source File: LoreBase.java    From EssentialCmds with MIT License 4 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException
{
	return CommandResult.empty();
}
 
Example 18
Source File: WorldsBase.java    From EssentialCmds with MIT License 4 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	Optional<String> worldName = ctx.<String> getOne("world");
	World world;

	if (worldName.isPresent())
	{
		if (Sponge.getServer().getWorld(worldName.get()).isPresent())
		{
			world = Sponge.getServer().getWorld(worldName.get()).get();
		}
		else
		{
			src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "World not found!"));
			return CommandResult.empty();
		}
	}
	else
	{
		if (src instanceof Player)
		{
			Player player = (Player) src;
			world = player.getWorld();
		}
		else
		{
			src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must be an in-game player to use /world difficulty!"));
			return CommandResult.empty();
		}
	}

	PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get();
	ArrayList<Text> gameruleText = Lists.newArrayList();

	for (Entry<String, String> gamerule : world.getGameRules().entrySet())
	{
		Text item = Text.builder(gamerule.getKey())
			.onHover(TextActions.showText(Text.of(TextColors.WHITE, "Value ", TextColors.GOLD, gamerule.getValue())))
			.color(TextColors.DARK_AQUA)
			.style(TextStyles.UNDERLINE)
			.build();

		gameruleText.add(item);
	}

	PaginationList.Builder paginationBuilder = paginationService.builder().contents(gameruleText).title(Text.of(TextColors.GREEN, "Showing Gamerules")).padding(Text.of("-"));
	paginationBuilder.sendTo(src);
	return CommandResult.success();
}
 
Example 19
Source File: WorldsBase.java    From EssentialCmds with MIT License 4 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException
{
	return CommandResult.empty();
}
 
Example 20
Source File: SpongeSparkPlugin.java    From spark with GNU General Public License v3.0 4 votes vote down vote up
@Override
public CommandResult process(CommandSource source, String arguments) {
    this.plugin.platform.executeCommand(new SpongeCommandSender(source), arguments.split(" "));
    return CommandResult.empty();
}