org.spongepowered.api.command.CommandException Java Examples

The following examples show how to use org.spongepowered.api.command.CommandException. 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: SubCommand.java    From SubServers-2 with Apache License 2.0 6 votes vote down vote up
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    if (canRun(sender)) {
        Optional<String> subcommand = args.getOne(Text.of("subcommand"));
        if (subcommand.isPresent()) {
            sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Invalid-Subcommand").replace("$str$", subcommand.get())));
            return CommandResult.builder().successCount(0).build();
        } else {
            if (sender.hasPermission("subservers.interface") && sender instanceof Player && plugin.gui != null) {
                plugin.gui.getRenderer((Player) sender).newUI();
            } else {
                sender.sendMessages(printHelp());
            }
            return CommandResult.builder().successCount(1).build();
        }
    } else {
        sender.sendMessage(ChatColor.convertColor(plugin.api.getLang("SubServers","Command.Generic.Invalid-Permission").replace("$str$", "subservers.command")));
        return CommandResult.builder().successCount(0).build();
    }
}
 
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: NationListExecutor.java    From Nations with MIT License 6 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	List<Text> contents = new ArrayList<>();
	Iterator<Nation> iter = DataHandler.getNations().values().iterator();
	if (!iter.hasNext())
	{
		contents.add(Text.of(TextColors.YELLOW, LanguageHandler.ERROR_NONATIONYET));
	}
	else
	{
		while (iter.hasNext())
		{
			Nation nation = iter.next();
			if (!nation.isAdmin() || src.hasPermission("nations.admin.nation.listall"))
			{
				contents.add(Text.of(Utils.nationClickable(TextColors.YELLOW, nation.getRealName()), TextColors.GOLD, " [" + nation.getNumCitizens() + "]"));
			}
		}
	}
	PaginationList.builder()
	.title(Text.of(TextColors.GOLD, "{ ", TextColors.YELLOW, LanguageHandler.HEADER_NATIONLIST, TextColors.GOLD, " }"))
	.contents(contents)
	.padding(Text.of("-"))
	.sendTo(src);
	return CommandResult.success();
}
 
Example #4
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 #5
Source File: GeyserSpongeCommandExecutor.java    From Geyser with MIT License 6 votes vote down vote up
@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
    String[] args = arguments.split(" ");
    if (args.length > 0) {
        if (getCommand(args[0]) != null) {
            if (!source.hasPermission(getCommand(args[0]).getPermission())) {
                source.sendMessage(Text.of(ChatColor.RED + "You do not have permission to execute this command!"));
                return CommandResult.success();
            }
            getCommand(args[0]).execute(new SpongeCommandSender(source), args);
        }
    } else {
        getCommand("help").execute(new SpongeCommandSender(source), args);
    }
    return CommandResult.success();
}
 
Example #6
Source File: NationadminPermExecutor.java    From Nations with MIT License 6 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	if (!ctx.<String>getOne("nation").isPresent() || !ctx.<String>getOne("type").isPresent() || !ctx.<String>getOne("perm").isPresent())
	{
		src.sendMessage(Text.of(TextColors.YELLOW, "/na perm <nation> <type> <perm> [true|false]"));
		return CommandResult.success();
	}
	String nationName = ctx.<String>getOne("nation").get();
	Nation nation = DataHandler.getNation(nationName);
	if (nation == null)
	{
		src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_BADNATIONNAME));
		return CommandResult.success();
	}
	String type = ctx.<String>getOne("type").get();
	String perm = ctx.<String>getOne("perm").get();
	boolean bool = (ctx.<Boolean>getOne("bool").isPresent()) ? ctx.<Boolean>getOne("bool").get() : !nation.getPerm(type, perm);
	nation.setPerm(type, perm, bool);
	DataHandler.saveNation(nation.getUUID());
	src.sendMessage(Utils.formatNationDescription(nation, Utils.CLICKER_ADMIN));
	return CommandResult.success();
}
 
Example #7
Source File: NationworldListExecutor.java    From Nations with MIT License 6 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	Builder builder = Text.builder();
	Iterator<World> iter = Sponge.getServer().getWorlds().iterator();
	builder.append(Text.of(TextColors.GOLD, "--------{ ", TextColors.YELLOW, LanguageHandler.HEADER_WORLDLIST, TextColors.GOLD, " }--------\n"));
	while (iter.hasNext())
	{
		World world = iter.next();
		builder.append(Utils.worldClickable(TextColors.YELLOW, world.getName()));
		if (iter.hasNext())
		{
			builder.append(Text.of(TextColors.YELLOW, ", "));
		}
	}
	if (src.hasPermission("nations.command.nationworld.info"))
	{
		builder.append(Text.of(TextColors.DARK_GRAY, " <- click"));
	}
	src.sendMessage(builder.build());
	return CommandResult.success();
}
 
Example #8
Source File: NationadminDeleteExecutor.java    From Nations with MIT License 6 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	if (!ctx.<String>getOne("nation").isPresent())
	{
		src.sendMessage(Text.of(TextColors.YELLOW, "/na delete <nation>"));
		return CommandResult.success();
	}
	String nationName = ctx.<String>getOne("nation").get();
	Nation nation = DataHandler.getNation(nationName);
	if (nation == null)
	{
		src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_BADNATIONNAME));
		return CommandResult.success();
	}
	DataHandler.removeNation(nation.getUUID());
	MessageChannel.TO_ALL.send(Text.of(TextColors.AQUA, LanguageHandler.INFO_NATIONFALL.replaceAll("\\{NATION\\}", nation.getName())));
	return CommandResult.success();
}
 
Example #9
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 #10
Source File: BackupCommand.java    From EagleFactions with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(final CommandSource source, final CommandContext context) throws CommandException
{
    //No extra checks needed. Only the player that has permission for this command should be able to use it.


    //We run it async so that It does not freeze the server.
    CompletableFuture.runAsync(() ->{
        source.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, "Creating a backup..."));
        final boolean result = super.getPlugin().getStorageManager().createBackup();
        if (result)
        {
            source.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.GREEN, "Backup has been successfully created!"));
        }
        else
        {
            source.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.RED, "Something went wrong during creation of backup. Check your server log file for more details."));
        }
    });

    return CommandResult.success();
}
 
Example #11
Source File: TagColorCommand.java    From EagleFactions with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(final CommandSource source, final CommandContext context) throws CommandException
{
    if (!getPlugin().getConfiguration().getChatConfig().canColorTags())
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.TAG_COLORING_IS_TURNED_OFF_ON_THIS_SERVER));

    if (!(source instanceof Player))
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.ONLY_IN_GAME_PLAYERS_CAN_USE_THIS_COMMAND));

    final TextColor color = context.requireOne("color");
    final Player player = (Player)source;
    final Optional<Faction> optionalPlayerFaction = getPlugin().getFactionLogic().getFactionByPlayerUUID(player.getUniqueId());
    if (!optionalPlayerFaction.isPresent())
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_MUST_BE_IN_FACTION_IN_ORDER_TO_USE_THIS_COMMAND));

    Faction playerFaction = optionalPlayerFaction.get();
    if (!playerFaction.getLeader().equals(player.getUniqueId()) && !playerFaction.getOfficers().contains(player.getUniqueId()) && !super.getPlugin().getPlayerManager().hasAdminMode(player))
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_MUST_BE_THE_FACTIONS_LEADER_OR_OFFICER_TO_DO_THIS));

    super.getPlugin().getFactionLogic().changeTagColor(playerFaction, color);
    player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.GREEN, Messages.TAG_COLOR_HAS_BEEN_CHANGED));
    return CommandResult.success();
}
 
Example #12
Source File: AutoMapCommand.java    From EagleFactions with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(final CommandSource source, final CommandContext context) throws CommandException
{
    if(!(source instanceof Player))
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.ONLY_IN_GAME_PLAYERS_CAN_USE_THIS_COMMAND));

    final Player player = (Player)source;
    if(EagleFactionsPlugin.AUTO_MAP_LIST.contains(player.getUniqueId()))
    {
        EagleFactionsPlugin.AUTO_MAP_LIST.remove(player.getUniqueId());
        player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.GREEN, Messages.AUTO_MAP_HAS_BEEN_TURNED_OFF));
    }
    else
    {
        EagleFactionsPlugin.AUTO_MAP_LIST.add(player.getUniqueId());
        player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.GREEN, Messages.AUTO_MAP_HAS_BEEN_TURNED_ON));
    }

    return CommandResult.success();
}
 
Example #13
Source File: AdminCommand.java    From EagleFactions with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(final CommandSource source, final CommandContext context) throws CommandException
{
    if (!(source instanceof Player))
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.ONLY_IN_GAME_PLAYERS_CAN_USE_THIS_COMMAND));

    final Player player = (Player)source;
    if(super.getPlugin().getPlayerManager().hasAdminMode(player))
    {
        super.getPlugin().getPlayerManager().deactivateAdminMode(player);
        player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.GOLD, Messages.ADMIN_MODE_HAS_BEEN_TURNED_OFF));
    }
    else
    {
        super.getPlugin().getPlayerManager().activateAdminMode(player);
        player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.GOLD, Messages.ADMIN_MODE_HAS_BEEN_TURNED_ON));
    }
    return CommandResult.success();
}
 
Example #14
Source File: NotAccessibleByFactionCommand.java    From EagleFactions with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(final CommandSource source, final CommandContext args) throws CommandException
{
    if(!(source instanceof Player))
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.ONLY_IN_GAME_PLAYERS_CAN_USE_THIS_COMMAND));

    final Player player = (Player)source;

    final Optional<Faction> optionalPlayerFaction = super.getPlugin().getFactionLogic().getFactionByPlayerUUID(player.getUniqueId());
    if (!optionalPlayerFaction.isPresent())
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_MUST_BE_IN_FACTION_IN_ORDER_TO_USE_THIS_COMMAND));

    final Faction playerFaction = optionalPlayerFaction.get();

    // Access can be run only by leader and officers
    if (!playerFaction.getLeader().equals(player.getUniqueId()) && !playerFaction.getOfficers().contains(player.getUniqueId()) && !super.getPlugin().getPlayerManager().hasAdminMode(player))
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_MUST_BE_THE_FACTIONS_LEADER_OR_OFFICER_TO_DO_THIS));

    // Get claim at player's location
    return showNotAccessibleByFaction(player, playerFaction);
}
 
Example #15
Source File: NationadminFlagExecutor.java    From Nations with MIT License 6 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	if (!ctx.<String>getOne("nation").isPresent() || !ctx.<String>getOne("flag").isPresent())
	{
		src.sendMessage(Text.of(TextColors.YELLOW, "/na flag <nation> <flag> [true|false]"));
		return CommandResult.success();
	}
	String nationName = ctx.<String>getOne("nation").get();
	Nation nation = DataHandler.getNation(nationName);
	if (nation == null)
	{
		src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_BADNATIONNAME));
		return CommandResult.success();
	}
	String flag = ctx.<String>getOne("flag").get();
	boolean bool = (ctx.<Boolean>getOne("bool").isPresent()) ? ctx.<Boolean>getOne("bool").get() : !nation.getFlag(flag);
	nation.setFlag(flag, bool);
	DataHandler.saveNation(nation.getUUID());
	src.sendMessage(Utils.formatNationDescription(nation, Utils.CLICKER_ADMIN));
	return CommandResult.success();
}
 
Example #16
Source File: DebugCommand.java    From EagleFactions with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource source, CommandContext context) throws CommandException
{
    if (!(source instanceof Player))
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.ONLY_IN_GAME_PLAYERS_CAN_USE_THIS_COMMAND));

    final Player player = (Player)source;
    if(EagleFactionsPlugin.DEBUG_MODE_PLAYERS.contains(player.getUniqueId()))
    {
        EagleFactionsPlugin.DEBUG_MODE_PLAYERS.remove(player.getUniqueId());
        player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, Messages.DEBUG_MODE_HAS_BEEN_TURNED_OFF));
    }
    else
    {
        EagleFactionsPlugin.DEBUG_MODE_PLAYERS.add(player.getUniqueId());
        player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, Messages.DEBUG_MODE_HAS_BEEN_TURNED_ON));
    }
    return CommandResult.success();
}
 
Example #17
Source File: ReloadCommand.java    From EagleFactions with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource source, CommandContext context) throws CommandException
{
    try
    {
        super.getPlugin().getConfiguration().reloadConfiguration();
        super.getPlugin().getStorageManager().reloadStorage();

        source.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.GREEN, Messages.CONFIG_HAS_BEEN_RELOADED));
    }
    catch (Exception exception)
    {
        exception.printStackTrace();
    }

    return CommandResult.success();
}
 
Example #18
Source File: TruceCommand.java    From EagleFactions with MIT License 6 votes vote down vote up
private void sendInvite(final Player player, final Faction playerFaction, final Faction targetFaction) throws CommandException
{
	final AllyRequest invite = new AllyRequest(playerFaction.getName(), targetFaction.getName());
	if(EagleFactionsPlugin.TRUCE_INVITE_LIST.contains(invite))
		throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, Messages.YOU_HAVE_ALREADY_INVITED_THIS_FACTION_TO_THE_TRUCE));

	EagleFactionsPlugin.TRUCE_INVITE_LIST.add(invite);

	final Optional<Player> optionalInvitedFactionLeader = super.getPlugin().getPlayerManager().getPlayer(targetFaction.getLeader());

	optionalInvitedFactionLeader.ifPresent(x-> optionalInvitedFactionLeader.get().sendMessage(getInviteGetMessage(playerFaction)));
	targetFaction.getOfficers().forEach(x-> super.getPlugin().getPlayerManager().getPlayer(x).ifPresent(y-> getInviteGetMessage(playerFaction)));

	player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, MessageLoader.parseMessage(Messages.YOU_HAVE_INVITED_FACTION_TO_THE_TRUCE, TextColors.GREEN, ImmutableMap.of(Placeholders.FACTION_NAME, Text.of(TextColors.GOLD, targetFaction.getName())))));

	final Task.Builder taskBuilder = Sponge.getScheduler().createTaskBuilder();
	taskBuilder.execute(() -> EagleFactionsPlugin.TRUCE_INVITE_LIST.remove(invite)).delay(2, TimeUnit.MINUTES).name("EagleFaction - Remove Invite").submit(super.getPlugin());
}
 
Example #19
Source File: AllyCommand.java    From EagleFactions with MIT License 6 votes vote down vote up
private void sendInvite(final Player player, final Faction playerFaction, final Faction targetFaction) throws CommandException
{
	final AllyRequest invite = new AllyRequest(playerFaction.getName(), targetFaction.getName());
	if(EagleFactionsPlugin.ALLY_INVITE_LIST.contains(invite))
		throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, Messages.YOU_HAVE_ALREADY_INVITED_THIS_FACTION_TO_THE_ALLIANCE));

	EagleFactionsPlugin.ALLY_INVITE_LIST.add(invite);

	final Optional<Player> optionalInvitedFactionLeader = super.getPlugin().getPlayerManager().getPlayer(targetFaction.getLeader());

	optionalInvitedFactionLeader.ifPresent(x-> optionalInvitedFactionLeader.get().sendMessage(getInviteGetMessage(playerFaction)));
	targetFaction.getOfficers().forEach(x-> super.getPlugin().getPlayerManager().getPlayer(x).ifPresent(y-> getInviteGetMessage(playerFaction)));

	player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, MessageLoader.parseMessage(Messages.YOU_HAVE_INVITED_FACTION_TO_THE_ALLIANCE, TextColors.GREEN, ImmutableMap.of(Placeholders.FACTION_NAME, Text.of(TextColors.GOLD, targetFaction.getName())))));

	final Task.Builder taskBuilder = Sponge.getScheduler().createTaskBuilder();
	taskBuilder.execute(() -> EagleFactionsPlugin.ALLY_INVITE_LIST.remove(invite)).delay(2, TimeUnit.MINUTES).name("EagleFaction - Remove Invite").submit(super.getPlugin());
}
 
Example #20
Source File: PermsCommand.java    From EagleFactions with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(final CommandSource source, final CommandContext context) throws CommandException
{
    if(!(source instanceof Player))
        throw new CommandException(Text.of (PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.ONLY_IN_GAME_PLAYERS_CAN_USE_THIS_COMMAND));

    final Player player = (Player)source;
    final Optional<Faction> optionalPlayerFaction = getPlugin().getFactionLogic().getFactionByPlayerUUID(player.getUniqueId());

    if(!optionalPlayerFaction.isPresent())
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_MUST_BE_IN_FACTION_IN_ORDER_TO_USE_THIS_COMMAND));

    final Faction faction = optionalPlayerFaction.get();
    if(!faction.getLeader().equals(player.getUniqueId()) && !super.getPlugin().getPlayerManager().hasAdminMode(player))
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_MUST_BE_THE_FACTIONS_LEADER_TO_DO_THIS));

    showPerms(player, faction);
    return CommandResult.success();
}
 
Example #21
Source File: NationDelspawnExecutor.java    From Nations with MIT License 5 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	if (src instanceof Player)
	{
		Player player = (Player) src;
		Nation nation = DataHandler.getNationOfPlayer(player.getUniqueId());
		if (nation == null)
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NONATION));
			return CommandResult.success();
		}
		if (!ctx.<String>getOne("name").isPresent())
		{
			src.sendMessage(Text.builder()
					.append(Text.of(TextColors.AQUA, LanguageHandler.INFO_CLICK_DELSPAWN.split("\\{SPAWNLIST\\}")[0]))
					.append(Utils.formatNationSpawns(nation, TextColors.YELLOW, "delhome"))
					.append(Text.of(TextColors.AQUA, LanguageHandler.INFO_CLICK_DELSPAWN.split("\\{SPAWNLIST\\}")[1])).build());
			return CommandResult.success();
		}
		String spawnName = ctx.<String>getOne("name").get();
		if (!nation.isStaff(player.getUniqueId()))
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PERM_NATIONSTAFF));
			return CommandResult.success();
		}
		if (nation.getSpawn(spawnName) == null)
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_BADSPAWNNAME));
			return CommandResult.success();
		}
		nation.removeSpawn(spawnName);
		DataHandler.saveNation(nation.getUUID());
		src.sendMessage(Text.of(TextColors.AQUA, LanguageHandler.SUCCESS_DELNATION));
	}
	else
	{
		src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NOPLAYER));
	}
	return CommandResult.success();
}
 
Example #22
Source File: NationadminExtraspawnExecutor.java    From Nations with MIT License 5 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	if (!ctx.<String>getOne("nation").isPresent() || !ctx.<String>getOne("give|take|set").isPresent() || !ctx.<String>getOne("amount").isPresent())
	{
		src.sendMessage(Text.of(TextColors.YELLOW, "/na extraspawn <give|take|set> <nation> <amount>"));
		return CommandResult.success();
	}
	String nationName = ctx.<String>getOne("nation").get();
	Integer amount = Integer.valueOf(ctx.<Integer>getOne("amount").get());
	String operation = ctx.<String>getOne("give|take|set").get();
	
	Nation nation = DataHandler.getNation(nationName);
	if (nation == null)
	{
		src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_BADNATIONNAME));
		return CommandResult.success();
	}
	if (operation.equalsIgnoreCase("give"))
	{
		nation.addExtraSpawns(amount);
	}
	else if (operation.equalsIgnoreCase("take"))
	{
		nation.addExtraSpawns(amount);
	}
	else if (operation.equalsIgnoreCase("set"))
	{
		nation.addExtraSpawns(amount);
	}
	else
	{
		src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_BADARG_GTS));
		return CommandResult.success();
	}
	DataHandler.saveNation(nation.getUUID());
	src.sendMessage(Text.of(TextColors.GREEN, LanguageHandler.SUCCESS_GENERAL));
	return CommandResult.success();
}
 
Example #23
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 #24
Source File: NationFlagExecutor.java    From Nations with MIT License 5 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	if (src instanceof Player)
	{
		Player player = (Player) src;
		Nation nation = DataHandler.getNationOfPlayer(player.getUniqueId());
		if (nation == null)
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NONATION));
			return CommandResult.success();
		}
		if (!nation.isStaff(player.getUniqueId()))
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PERM_NATIONSTAFF));
			return CommandResult.success();
		}
		String flag = ctx.<String>getOne("flag").get();
		if (!player.hasPermission("nations.command.nation.flag." + flag))
		{
			player.sendMessage(t("You do not have permission to use this command!"));
			return CommandResult.success();
		}
		boolean bool = (ctx.<Boolean>getOne("bool").isPresent()) ? ctx.<Boolean>getOne("bool").get() : !nation.getFlag(flag);
		nation.setFlag(flag, bool);
		DataHandler.saveNation(nation.getUUID());
		int clicker = Utils.CLICKER_DEFAULT;
		if (src.hasPermission("nations.command.nationadmin"))
		{
			clicker = Utils.CLICKER_ADMIN;
		}
		src.sendMessage(Utils.formatNationDescription(nation, clicker));
	}
	else
	{
		src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NOPLAYER));
	}
	return CommandResult.success();
}
 
Example #25
Source File: AccessCommand.java    From EagleFactions with MIT License 5 votes vote down vote up
@Override
public CommandResult execute(final CommandSource source, final CommandContext args) throws CommandException
{
    if(!(source instanceof Player))
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.ONLY_IN_GAME_PLAYERS_CAN_USE_THIS_COMMAND));

    final Player player = (Player)source;

    final Optional<Faction> optionalPlayerFaction = super.getPlugin().getFactionLogic().getFactionByPlayerUUID(player.getUniqueId());
    if (!optionalPlayerFaction.isPresent())
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_MUST_BE_IN_FACTION_IN_ORDER_TO_USE_THIS_COMMAND));

    final Faction playerFaction = optionalPlayerFaction.get();

    // Access can be run only by leader and officers
    final Optional<Faction> optionalChunkFaction = super.getPlugin().getFactionLogic().getFactionByChunk(player.getWorld().getUniqueId(), player.getLocation().getChunkPosition());
    if (!optionalChunkFaction.isPresent())
        throw new CommandException(PluginInfo.ERROR_PREFIX.concat(Text.of(Messages.THIS_PLACE_DOES_NOT_BELONG_TO_ANYONE)));

    final Faction chunkFaction = optionalChunkFaction.get();
    if (!playerFaction.getName().equals(chunkFaction.getName()))
        throw new CommandException(PluginInfo.ERROR_PREFIX.concat(Text.of(Messages.THIS_PLACE_DOES_NOT_BELONG_TO_YOUR_FACTION)));

    if (!playerFaction.getLeader().equals(player.getUniqueId()) && !playerFaction.getOfficers().contains(player.getUniqueId()) && !super.getPlugin().getPlayerManager().hasAdminMode(player))
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_MUST_BE_THE_FACTIONS_LEADER_OR_OFFICER_TO_DO_THIS));

    // Get claim at player's location
    final Optional<Claim> optionalClaim = chunkFaction.getClaimAt(player.getWorld().getUniqueId(), player.getLocation().getChunkPosition());
    final Claim claim = optionalClaim.get();
    return showAccess(player, claim);
}
 
Example #26
Source File: NationPermExecutor.java    From Nations with MIT License 5 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	if (src instanceof Player)
	{
		Player player = (Player) src;
		Nation nation = DataHandler.getNationOfPlayer(player.getUniqueId());
		if (nation == null)
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NONATION));
			return CommandResult.success();
		}
		if (!nation.isStaff(player.getUniqueId()))
		{
			src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PERM_NATIONSTAFF));
			return CommandResult.success();
		}
		String type = ctx.<String>getOne("type").get();
		String perm = ctx.<String>getOne("perm").get();
		if (!player.hasPermission("nations.command.nation.perm." + type + "." + perm))
		{
			player.sendMessage(t("You do not have permission to use this command!"));
			return CommandResult.success();
		}
		boolean bool = (ctx.<Boolean>getOne("bool").isPresent()) ? ctx.<Boolean>getOne("bool").get() : !nation.getPerm(type, perm);
		nation.setPerm(type, perm, bool);
		DataHandler.saveNation(nation.getUUID());
		int clicker = Utils.CLICKER_DEFAULT;
		if (src.hasPermission("nations.command.nationadmin"))
		{
			clicker = Utils.CLICKER_ADMIN;
		}
		src.sendMessage(Utils.formatNationDescription(nation, clicker));
	}
	else
	{
		src.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_NOPLAYER));
	}
	return CommandResult.success();
}
 
Example #27
Source File: NationCostExecutor.java    From Nations with MIT License 5 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	src.sendMessage(Text.of(
			TextColors.GOLD, ((src instanceof Player) ? "" : "\n") + "--------{ ",
			TextColors.YELLOW, LanguageHandler.HEADER_NATIONCOST,
			TextColors.GOLD, " }--------",
			TextColors.GOLD, "\n", LanguageHandler.COST_MSG_NATIONCREATE, TextColors.GRAY, " - ", TextColors.YELLOW, ConfigHandler.getNode("prices", "nationCreationPrice").getDouble(),
			TextColors.GOLD, "\n", LanguageHandler.COST_MSG_OUTPOSTCREATE, TextColors.GRAY, " - ", TextColors.YELLOW, ConfigHandler.getNode("prices", "outpostCreationPrice").getDouble(),
			TextColors.GOLD, "\n", LanguageHandler.COST_MSG_UPKEEP, TextColors.GRAY, " - ", TextColors.YELLOW, ConfigHandler.getNode("prices", "upkeepPerCitizen").getDouble(),
			TextColors.GOLD, "\n", LanguageHandler.COST_MSG_CLAIMPRICE, TextColors.GRAY, " - ", TextColors.YELLOW, ConfigHandler.getNode("prices", "blockClaimPrice").getDouble(),
			TextColors.GOLD, "\n", LanguageHandler.COST_MSG_EXTRAPRICE, TextColors.GRAY, " - ", TextColors.YELLOW, ConfigHandler.getNode("prices", "extraPrice").getDouble()));
	return CommandResult.success();
}
 
Example #28
Source File: NationadminExecutor.java    From Nations with MIT License 5 votes vote down vote up
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	List<Text> contents = new ArrayList<>();

	contents.add(Text.of(TextColors.GOLD, "/na reload", TextColors.GRAY, " - ", TextColors.YELLOW, LanguageHandler.HELP_DESC_CMD_NA_RELOAD));
	contents.add(Text.of(TextColors.GOLD, "/na forceupkeep", TextColors.GRAY, " - ", TextColors.YELLOW, LanguageHandler.HELP_DESC_CMD_NA_FORCEKEEPUP));
	contents.add(Text.of(TextColors.GOLD, "/na create <name>", TextColors.GRAY, " - ", TextColors.YELLOW, LanguageHandler.HELP_DESC_CMD_NA_CREATE));
	contents.add(Text.of(TextColors.GOLD, "/na claim <nation>", TextColors.GRAY, " - ", TextColors.YELLOW, LanguageHandler.HELP_DESC_CMD_NA_CLAIM));
	contents.add(Text.of(TextColors.GOLD, "/na unclaim <nation>", TextColors.GRAY, " - ", TextColors.YELLOW, LanguageHandler.HELP_DESC_CMD_NA_UNCLAIM));
	contents.add(Text.of(TextColors.GOLD, "/na delete <nation>", TextColors.GRAY, " - ", TextColors.YELLOW, LanguageHandler.HELP_DESC_CMD_NA_DELETE));
	contents.add(Text.of(TextColors.GOLD, "/na setname <nation> <name>", TextColors.GRAY, " - ", TextColors.YELLOW, LanguageHandler.HELP_DESC_CMD_SETNAME));
	contents.add(Text.of(TextColors.GOLD, "/na settag <nation> <tag>", TextColors.GRAY, " - ", TextColors.YELLOW, LanguageHandler.HELP_DESC_CMD_SETTAG));
	contents.add(Text.of(TextColors.GOLD, "/na setpres <nation> <player>", TextColors.GRAY, " - ", TextColors.YELLOW, LanguageHandler.HELP_DESC_CMD_NA_SETPRES));
	contents.add(Text.of(TextColors.GOLD, "/na setspawn <nation> <name>", TextColors.GRAY, " - ", TextColors.YELLOW, LanguageHandler.HELP_DESC_CMD_SETSPAWN));
	contents.add(Text.of(TextColors.GOLD, "/na delspawn <nation> <name>", TextColors.GRAY, " - ", TextColors.YELLOW, LanguageHandler.HELP_DESC_CMD_DELSPAWN));
	contents.add(Text.of(TextColors.GOLD, "/na forcejoin <nation> <player>", TextColors.GRAY, " - ", TextColors.YELLOW, LanguageHandler.HELP_DESC_CMD_NA_FORCEJOIN));
	contents.add(Text.of(TextColors.GOLD, "/na forceleave <nation> <player>", TextColors.GRAY, " - ", TextColors.YELLOW, LanguageHandler.HELP_DESC_CMD_NA_FORCELEAVE));
	contents.add(Text.of(TextColors.GOLD, "/na eco <give|take|set> <nation> <amount>", TextColors.GRAY, " - ", TextColors.YELLOW, LanguageHandler.HELP_DESC_CMD_NA_ECO));
	contents.add(Text.of(TextColors.GOLD, "/na perm <nation> <type> <perm> [true|false]", TextColors.GRAY, " - ", TextColors.YELLOW, LanguageHandler.HELP_DESC_CMD_NA_PERM));
	contents.add(Text.of(TextColors.GOLD, "/na flag <nation> <flag> [true|false]", TextColors.GRAY, " - ", TextColors.YELLOW, LanguageHandler.HELP_DESC_CMD_NA_FLAG));
	contents.add(Text.of(TextColors.GOLD, "/na spy", TextColors.GRAY, " - ", TextColors.YELLOW, LanguageHandler.HELP_DESC_CMD_NA_SPY));
	contents.add(Text.of(TextColors.GOLD, "/na extra <give|take|set> <nation> <amount>", TextColors.GRAY, " - ", TextColors.YELLOW, LanguageHandler.HELP_DESC_CMD_NA_EXTRA));
	contents.add(Text.of(TextColors.GOLD, "/na extraplayer <give|take|set> <player> <amount>", TextColors.GRAY, " - ", TextColors.YELLOW, LanguageHandler.HELP_DESC_CMD_NA_EXTRAPLAYER));
	contents.add(Text.of(TextColors.GOLD, "/na extraspawn <give|take|set> <nation> <amount>", TextColors.GRAY, " - ", TextColors.YELLOW, LanguageHandler.HELP_DESC_CMD_NA_EXTRASPAWN));
	contents.add(Text.of(TextColors.GOLD, "/na extraspawnplayer <give|take|set> <player> <amount>", TextColors.GRAY, " - ", TextColors.YELLOW, LanguageHandler.HELP_DESC_CMD_NA_EXTRASPAWNPLAYER));

	PaginationList.builder()
	.title(Text.of(TextColors.GOLD, "{ ", TextColors.YELLOW, "/nationadmin", TextColors.GOLD, " }"))
	.contents(contents)
	.padding(Text.of("-"))
	.sendTo(src);
	return CommandResult.success();
}
 
Example #29
Source File: CmdAuthListEnable.java    From Web-API with MIT License 5 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    if (whitelist) {
        WebAPI.getSecurityService().toggleWhitelist(true);
        src.sendMessage(Text.of("Enabled whitelist"));
    } else {
        WebAPI.getSecurityService().toggleBlacklist(true);
        src.sendMessage(Text.of("Enabled blacklist"));
    }

    return CommandResult.success();
}
 
Example #30
Source File: CmdAuthListRemove.java    From Web-API with MIT License 5 votes vote down vote up
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    String ip = args.getOne("ip").get().toString();

    if (whitelist) {
        WebAPI.getSecurityService().removeFromWhitelist(ip);
        src.sendMessage(Text.of("Removed " + ip + " from whitelist"));
    } else {
        WebAPI.getSecurityService().removeFromBlacklist(ip);
        src.sendMessage(Text.of("Removed " + ip + " from blacklist"));
    }

    return CommandResult.success();
}