Java Code Examples for org.spongepowered.api.command.args.CommandContext#requireOne()

The following examples show how to use org.spongepowered.api.command.args.CommandContext#requireOne() . 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: SetPowerCommand.java    From EagleFactions with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(final CommandSource source, final CommandContext context) throws CommandException
{
    final Player selectedPlayer = context.requireOne("player");
    final double power = context.requireOne("power");
    if (!(source instanceof Player))
        setPower(source, selectedPlayer, (float)power);
    else
    {
        final Player player = (Player) source;
        if (!super.getPlugin().getPlayerManager().hasAdminMode(player))
            throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_NEED_TO_TOGGLE_FACTION_ADMIN_MODE_TO_DO_THIS));
        setPower(source, selectedPlayer, (float)power);
    }
    return CommandResult.success();
}
 
Example 2
Source File: MaxPowerCommand.java    From EagleFactions with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(CommandSource source, CommandContext context) throws CommandException
{
    final Player selectedPlayer = context.requireOne(Text.of("player"));
    final double power = context.requireOne(Text.of("power"));

    if (source instanceof Player)
    {
        final Player player = (Player) source;
        if (!super.getPlugin().getPlayerManager().hasAdminMode(player))
            throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_NEED_TO_TOGGLE_FACTION_ADMIN_MODE_TO_DO_THIS));
        setMaxPower(source, selectedPlayer, (float) power);
    }
    else
    {
        setMaxPower(source, selectedPlayer, (float)power);
    }

    return CommandResult.success();
}
 
Example 3
Source File: OwnedByCommand.java    From EagleFactions with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(final CommandSource source, final CommandContext args) throws CommandException
{
    final FactionPlayer factionPlayer = args.requireOne(Text.of("player"));

    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 showOwnedBy(player, factionPlayer, playerFaction);
}
 
Example 4
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 5
Source File: RestoreBackupCommand.java    From EagleFactions with MIT License 6 votes vote down vote up
@Override
public CommandResult execute(final CommandSource source, final CommandContext context) throws CommandException
{
    final String filename = context.requireOne(Text.of("filename"));
    //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, "Restoring backup ", TextColors.GOLD, filename));
        final boolean result = super.getPlugin().getStorageManager().restoreBackup(filename);
        if (result)
        {
            source.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.GREEN, "Backup has been successfully restored!"));
        }
        else
        {
            source.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.RED, "Could not restore the backup. Check your server log file for more details."));
        }
    });

    return CommandResult.success();
}
 
Example 6
Source File: RenameCommand.java    From EagleFactions with MIT License 5 votes vote down vote up
@Override
public CommandResult execute(final CommandSource source, final CommandContext context) throws CommandException
{
    final String newFactionName = context.requireOne("name");

    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 (newFactionName.equalsIgnoreCase("SafeZone") || newFactionName.equalsIgnoreCase("WarZone"))
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_CANT_USE_THIS_FACTION_NAME));

    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));

    if (!optionalPlayerFaction.get().getLeader().equals(player.getUniqueId()))
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_MUST_BE_THE_FACTIONS_LEADER_TO_DO_THIS));

    if (super.getPlugin().getFactionLogic().getFactionsNames().contains(newFactionName.toLowerCase()))
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.FACTION_WITH_THE_SAME_NAME_ALREADY_EXISTS));

    if(newFactionName.length() > this.factionsConfig.getMaxNameLength())
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.PROVIDED_FACTION_NAME_IS_TOO_LONG + " (" + Messages.MAX + " " + this.factionsConfig.getMaxNameLength() + " " + Messages.CHARS + ")"));
    if(newFactionName.length() < this.factionsConfig.getMinNameLength())
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.PROVIDED_FACTION_NAME_IS_TOO_SHORT + " (" + Messages.MIN + " " + this.factionsConfig.getMinNameLength() + " " + Messages.CHARS + ")"));

    super.getPlugin().getFactionLogic().renameFaction(optionalPlayerFaction.get(), newFactionName);
    player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, MessageLoader.parseMessage(Messages.SUCCESSFULLY_RENAMED_FACTION_TO_FACTION_NAME, TextColors.GREEN, Collections.singletonMap(Placeholders.FACTION_NAME, Text.of(TextColors.GOLD, newFactionName)))));

    return CommandResult.success();
}
 
Example 7
Source File: MotdCommand.java    From EagleFactions with MIT License 5 votes vote down vote up
@Override
public CommandResult execute(final CommandSource source, final CommandContext context) throws CommandException
{
    final String motd = context.requireOne("motd");

    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));

    //Check if player is leader
    if (!optionalPlayerFaction.get().getLeader().equals(player.getUniqueId()) && !optionalPlayerFaction.get().getOfficers().contains(player.getUniqueId()))
    {
        source.sendMessage(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_MUST_BE_THE_FACTIONS_LEADER_OR_OFFICER_TO_DO_THIS));
        return CommandResult.success();
    }

    //Check motd length
    if(motd.length() > 255)
    {
        player.sendMessage(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, "Motd is too long " + " (" + Messages.MAX + " " + 255 + " " + Messages.CHARS + ")"));
        return CommandResult.success();
    }

    super.getPlugin().getFactionLogic().setMessageOfTheDay(optionalPlayerFaction.get(), motd);
    player.sendMessage(PluginInfo.PLUGIN_PREFIX.concat(Text.of(TextColors.GREEN, Messages.FACTION_MESSAGE_OF_THE_DAY_HAS_BEEN_UPDATED)));
    return CommandResult.success();
}
 
Example 8
Source File: TagCommand.java    From EagleFactions with MIT License 5 votes vote down vote up
@Override
public CommandResult execute(final CommandSource source, final CommandContext context) throws CommandException
{
    final String newFactionTag = context.requireOne("tag");

    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));

    //Check if player is leader
    if (!optionalPlayerFaction.get().getLeader().equals(player.getUniqueId()))
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_MUST_BE_THE_FACTIONS_LEADER_TO_DO_THIS));

    //Check if faction with such tag already exists
    if(super.getPlugin().getFactionLogic().getFactionsTags().stream().anyMatch(x -> x.equalsIgnoreCase(newFactionTag)))
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.PROVIDED_FACTION_TAG_IS_ALREADY_TAKEN));

    //Check tag length
    if(newFactionTag.length() > this.factionsConfig.getMaxTagLength())
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.PROVIDED_FACTION_TAG_IS_TOO_LONG + " (" + Messages.MAX + " " + this.factionsConfig.getMaxTagLength() + " " + Messages.CHARS + ")"));
    else if(newFactionTag.length() < this.factionsConfig.getMinTagLength())
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.PROVIDED_FACTION_TAG_IS_TOO_SHORT + " (" + Messages.MIN + " " + this.factionsConfig.getMinTagLength() + " " + Messages.CHARS + ")"));

    //Change tag function
    super.getPlugin().getFactionLogic().changeTag(optionalPlayerFaction.get(), newFactionTag);
    player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, MessageLoader.parseMessage(Messages.FACTION_TAG_HAS_BEEN_SUCCESSFULLY_CHANGED_TO, TextColors.GREEN, Collections.singletonMap(Placeholders.FACTION_TAG, Text.of(TextColors.GOLD, newFactionTag)))));
    return CommandResult.success();
}
 
Example 9
Source File: JoinCommand.java    From EagleFactions with MIT License 4 votes vote down vote up
@Override
public CommandResult execute(final CommandSource source, final CommandContext context) throws CommandException
{
    final Faction faction = context.requireOne("faction");

    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().getFactionLogic().getFactionByPlayerUUID(player.getUniqueId()).isPresent())
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_ARE_ALREADY_IN_A_FACTION));

    //If player has admin mode then force join.
    if(super.getPlugin().getPlayerManager().hasAdminMode(player))
    {
        return joinFactionAndNotify(player, faction);
    }

    if(!faction.isPublic())
    {
        boolean hasInvite = false;
        for (final Invite invite: EagleFactionsPlugin.INVITE_LIST)
        {
            if(invite.getPlayerUUID().equals(player.getUniqueId()) && invite.getFactionName().equals(faction.getName()))
            {
                hasInvite = true;
            }
        }
        if(!hasInvite)
            throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_HAVENT_BEEN_INVITED_TO_THIS_FACTION));
    }

    //TODO: Should public factions bypass this restriction?
    if(this.factionsConfig.isPlayerLimit())
    {
        int playerCount = 0;
        playerCount += faction.getLeader().toString().equals("") ? 0 : 1;
        playerCount += faction.getOfficers().isEmpty() ? 0 : faction.getOfficers().size();
        playerCount += faction.getMembers().isEmpty() ? 0 : faction.getMembers().size();
        playerCount += faction.getRecruits().isEmpty() ? 0 : faction.getRecruits().size();

        if(playerCount >= this.factionsConfig.getPlayerLimit())
            throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_CANT_JOIN_THIS_FACTION_BECAUSE_IT_REACHED_ITS_PLAYER_LIMIT));
    }

    return joinFactionAndNotify(player, faction);
}
 
Example 10
Source File: InviteCommand.java    From EagleFactions with MIT License 4 votes vote down vote up
@Override
public CommandResult execute(final CommandSource source, final CommandContext context) throws CommandException
{
    final Player invitedPlayer = context.requireOne("player");

    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 senderPlayer = (Player)source;
    final Optional<Faction> optionalSenderFaction = getPlugin().getFactionLogic().getFactionByPlayerUUID(senderPlayer.getUniqueId());

    if(!optionalSenderFaction.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 senderFaction = optionalSenderFaction.get();

    if (!super.getPlugin().getPermsManager().canInvite(senderPlayer.getUniqueId(), senderFaction))
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.PLAYERS_WITH_YOUR_RANK_CANT_INVITE_PLAYERS_TO_FACTION));

    if(this.factionsConfig.isPlayerLimit())
    {
        int playerCount = 0;
        playerCount += senderFaction.getLeader().toString().equals("") ? 0 : 1;
        playerCount += senderFaction.getOfficers().isEmpty() ? 0 : senderFaction.getOfficers().size();
        playerCount += senderFaction.getMembers().isEmpty() ? 0 : senderFaction.getMembers().size();
        playerCount += senderFaction.getRecruits().isEmpty() ? 0 : senderFaction.getRecruits().size();

        if(playerCount >= this.factionsConfig.getPlayerLimit())
        {
            senderPlayer.sendMessage(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_CANT_INVITE_MORE_PLAYERS_TO_YOUR_FACTION + " " + Messages.FACTIONS_PLAYER_LIMIT_HAS_BEEN_REACHED));
            return CommandResult.success();
        }
    }

    if(super.getPlugin().getFactionLogic().getFactionByPlayerUUID(invitedPlayer.getUniqueId()).isPresent())
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.PLAYER_IS_ALREADY_IN_A_FACTION));

    final Invite invite = new Invite(senderFaction.getName(), invitedPlayer.getUniqueId());
    EagleFactionsPlugin.INVITE_LIST.add(invite);

    invitedPlayer.sendMessage(getInviteGetMessage(senderFaction));
    senderPlayer.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX,TextColors.GREEN, Messages.YOU_INVITED + " ", TextColors.GOLD, invitedPlayer.getName(), TextColors.GREEN, " " + Messages.TO_YOUR_FACTION));

    final Task.Builder taskBuilder = Sponge.getScheduler().createTaskBuilder();

    taskBuilder.execute(() -> EagleFactionsPlugin.INVITE_LIST.remove(invite)).delay(2, TimeUnit.MINUTES).name("EagleFaction - Remove Invite").submit(EagleFactionsPlugin.getPlugin());
    return CommandResult.success();
}
 
Example 11
Source File: KickCommand.java    From EagleFactions with MIT License 4 votes vote down vote up
@Override
public CommandResult execute(final CommandSource source, final CommandContext context) throws CommandException
{
    final FactionPlayer selectedPlayer = context.<FactionPlayer>requireOne(Text.of("player"));

    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();
    if(!playerFaction.getLeader().equals(player.getUniqueId()) && !playerFaction.getOfficers().contains(player.getUniqueId()))
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_MUST_BE_THE_FACTIONS_LEADER_OR_OFFICER_TO_DO_THIS));

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

    if(!optionalSelectedPlayerFaction.get().getName().equals(playerFaction.getName()))
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.THIS_PLAYER_IS_NOT_IN_YOUR_FACTION));

    if(playerFaction.getLeader().equals(selectedPlayer.getUniqueId()) || (playerFaction.getOfficers().contains(player.getUniqueId()) && playerFaction.getOfficers().contains(selectedPlayer.getUniqueId())))
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_CANT_KICK_THIS_PLAYER));

    final boolean isCancelled = EventRunner.runFactionKickEvent(selectedPlayer, player, playerFaction);
    if(!isCancelled)
    {
        super.getPlugin().getFactionLogic().kickPlayer(selectedPlayer.getUniqueId(), playerFaction.getName());
        source.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, MessageLoader.parseMessage(Messages.YOU_KICKED_PLAYER_FROM_THE_FACTION, TextColors.GREEN, Collections.singletonMap(Placeholders.PLAYER, Text.of(TextColors.GOLD, selectedPlayer.getName())))));

        if(super.getPlugin().getPlayerManager().isPlayerOnline(selectedPlayer.getUniqueId()))
        {
            super.getPlugin().getPlayerManager().getPlayer(selectedPlayer.getUniqueId()).get().sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, Messages.YOU_WERE_KICKED_FROM_THE_FACTION));
        }

        EagleFactionsPlugin.AUTO_CLAIM_LIST.remove(selectedPlayer.getUniqueId());
        EagleFactionsPlugin.CHAT_LIST.remove(selectedPlayer.getUniqueId());
    }
    return CommandResult.success();
}
 
Example 12
Source File: AllyCommand.java    From EagleFactions with MIT License 4 votes vote down vote up
@Override
  public CommandResult execute(final CommandSource source, final CommandContext context) throws CommandException
  {
      final Faction selectedFaction = context.requireOne(Text.of("faction"));

      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 playerFaction = optionalPlayerFaction.get();

      if(playerFaction.getName().equals(selectedFaction.getName()))
      	throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_CANNOT_INVITE_YOURSELF_TO_THE_ALLIANCE));

      if(super.getPlugin().getPlayerManager().hasAdminMode(player))
      {
          if(playerFaction.getEnemies().contains(selectedFaction.getName()))
              throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_ARE_IN_WAR_WITH_THIS_FACTION + " " + Messages.SEND_THIS_FACTION_A_PEACE_REQUEST_FIRST_BEFORE_INVITING_THEM_TO_ALLIES));

          if(playerFaction.getTruces().contains(selectedFaction.getName()))
	{
		super.getPlugin().getFactionLogic().removeTruce(playerFaction.getName(), selectedFaction.getName());
		//Add ally
		super.getPlugin().getFactionLogic().addAlly(playerFaction.getName(), selectedFaction.getName());
		player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.GREEN, Messages.FACTION_HAS_BEEN_ADDED_TO_THE_ALLIANCE));
	}

	if(playerFaction.getAlliances().contains(selectedFaction.getName()))
	{
		//Remove ally
		super.getPlugin().getFactionLogic().removeAlly(playerFaction.getName(), selectedFaction.getName());
		player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, MessageLoader.parseMessage(Messages.YOU_DISBANDED_YOUR_ALLIANCE_WITH_FACTION, TextColors.GREEN, Collections.singletonMap(Placeholders.FACTION_NAME, Text.of(TextColors.GOLD, selectedFaction.getName())))));
	}
	else
	{
		//Add ally
		super.getPlugin().getFactionLogic().addAlly(playerFaction.getName(), selectedFaction.getName());
		player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.GREEN, Messages.FACTION_HAS_BEEN_ADDED_TO_THE_ALLIANCE));
	}
	return CommandResult.success();
      }

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

      if(playerFaction.getEnemies().contains(selectedFaction.getName()))
          throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_ARE_IN_WAR_WITH_THIS_FACTION + " " + Messages.SEND_THIS_FACTION_A_PEACE_REQUEST_FIRST_BEFORE_INVITING_THEM_TO_ALLIES));

if(playerFaction.getTruces().contains(selectedFaction.getName()))
	throw new CommandException(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.RED, Messages.DISBAND_TRUCE_FIRST_TO_INVITE_FACTION_TO_THE_ALLIANCE));

      if(playerFaction.getAlliances().contains(selectedFaction.getName()))
      {
          //Remove ally
          super.getPlugin().getFactionLogic().removeAlly(playerFaction.getName(), selectedFaction.getName());
          player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, MessageLoader.parseMessage(Messages.YOU_DISBANDED_YOUR_ALLIANCE_WITH_FACTION, TextColors.GREEN, Collections.singletonMap(Placeholders.FACTION_NAME, Text.of(TextColors.GOLD, selectedFaction.getName())))));
      }
      else
      {
          AllyRequest checkInvite = new AllyRequest(selectedFaction.getName(), playerFaction.getName());

          if(EagleFactionsPlugin.ALLY_INVITE_LIST.contains(checkInvite))
          {
          	acceptInvite(player, playerFaction, selectedFaction);
              EagleFactionsPlugin.ALLY_INVITE_LIST.remove(checkInvite);
          }
          else if(!EagleFactionsPlugin.ALLY_INVITE_LIST.contains(checkInvite))
          {
		sendInvite(player, playerFaction, selectedFaction);
          }
      }
      return CommandResult.success();
  }
 
Example 13
Source File: TruceCommand.java    From EagleFactions with MIT License 4 votes vote down vote up
@Override
public CommandResult execute(final CommandSource source, final CommandContext context) throws CommandException
{
	final Faction selectedFaction = context.requireOne(Text.of("faction"));

	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 playerFaction = optionalPlayerFaction.get();
	if(playerFaction.getName().equals(selectedFaction.getName()))
		throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_CANNOT_INVITE_YOURSELF_TO_THE_TRUCE));

	if(super.getPlugin().getPlayerManager().hasAdminMode(player))
	{
		if(playerFaction.getEnemies().contains(selectedFaction.getName()))
			throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_ARE_IN_WAR_WITH_THIS_FACTION + " " + Messages.SEND_THIS_FACTION_A_PEACE_REQUEST_FIRST_BEFORE_INVITING_THEM_TO_ALLIES));

		if(playerFaction.getAlliances().contains(selectedFaction.getName()))
		{
			super.getPlugin().getFactionLogic().removeAlly(playerFaction.getName(), selectedFaction.getName());
			//Add truce
			super.getPlugin().getFactionLogic().addTruce(playerFaction.getName(), selectedFaction.getName());
			player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.GREEN, Messages.FACTION_HAS_BEEN_ADDED_TO_THE_TRUCE));
		}

		if(playerFaction.getTruces().contains(selectedFaction.getName()))
		{
			//Remove truce
			super.getPlugin().getFactionLogic().removeTruce(playerFaction.getName(), selectedFaction.getName());
			player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, MessageLoader.parseMessage(Messages.YOU_DISBANDED_YOUR_TRUCE_WITH_FACTION, TextColors.GREEN, ImmutableMap.of(Placeholders.FACTION_NAME, Text.of(TextColors.GOLD, selectedFaction.getName())))));
		}
		else
		{
			//Add truce
			super.getPlugin().getFactionLogic().addTruce(playerFaction.getName(), selectedFaction.getName());
			player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.GREEN, Messages.FACTION_HAS_BEEN_ADDED_TO_THE_TRUCE));
		}
		return CommandResult.success();
	}

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

	if(playerFaction.getEnemies().contains(selectedFaction.getName()))
		throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_ARE_IN_WAR_WITH_THIS_FACTION + " " + Messages.SEND_THIS_FACTION_A_PEACE_REQUEST_FIRST_BEFORE_INVITING_THEM_TO_ALLIES));

	if(playerFaction.getAlliances().contains(selectedFaction.getName()))
		throw new CommandException(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.GREEN, Messages.DISBAND_ALLIANCE_FIRST_TO_INVITE_FACTION_TO_THE_TRUCE));

	if(playerFaction.getTruces().contains(selectedFaction.getName()))
	{
		//Remove truce
		super.getPlugin().getFactionLogic().removeTruce(playerFaction.getName(), selectedFaction.getName());
		player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, MessageLoader.parseMessage(Messages.YOU_DISBANDED_YOUR_TRUCE_WITH_FACTION, TextColors.GREEN, ImmutableMap.of(Placeholders.FACTION_NAME, Text.of(TextColors.GOLD, selectedFaction.getName())))));
	}
	else
	{
		AllyRequest checkInvite = new AllyRequest(selectedFaction.getName(), playerFaction.getName());

		if(EagleFactionsPlugin.TRUCE_INVITE_LIST.contains(checkInvite))
		{
			acceptInvite(player, playerFaction, selectedFaction);
			EagleFactionsPlugin.TRUCE_INVITE_LIST.remove(checkInvite);
		}
		else if(!EagleFactionsPlugin.TRUCE_INVITE_LIST.contains(checkInvite))
		{
			sendInvite(player, playerFaction, selectedFaction);
		}
	}
	return CommandResult.success();
}
 
Example 14
Source File: RegenCommand.java    From EagleFactions with MIT License 4 votes vote down vote up
@Override
public CommandResult execute(CommandSource source, CommandContext context) throws CommandException
{
    final Faction factionToRegen = context.requireOne("faction");

    if (factionToRegen.isSafeZone() || factionToRegen.isWarZone())
    {
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.THIS_FACTION_CANNOT_BE_DISBANDED));
    }

    /*
    Update: 29.04.2020
    Checking for a confirmation here. Since every command source can run this command, if the source is not a player,
    a UUID from its name is being generated.
     */

    UUID uuid = source instanceof Player ? ((Player) source).getUniqueId() : UUID.fromString(source.getName());

    if (!EagleFactionsPlugin.REGEN_CONFIRMATION_MAP.containsKey(uuid) || !EagleFactionsPlugin.REGEN_CONFIRMATION_MAP.get(uuid).equals(factionToRegen.getName()))
    {
        source.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.YELLOW, Messages.REGEN_WARNING_CONFIRMATION_REQUIRED));

        EagleFactionsPlugin.REGEN_CONFIRMATION_MAP.put(uuid, factionToRegen.getName());

        return CommandResult.success();
    }

    EagleFactionsPlugin.REGEN_CONFIRMATION_MAP.remove(uuid);

    /* Firstly, we're simply disbanding the faction. */

    boolean didSucceed = super.getPlugin().getFactionLogic().disbandFaction(factionToRegen.getName());
    if(didSucceed)
    {
        if (source instanceof Player)
        {
            Player player = (Player) source;

            EagleFactionsPlugin.AUTO_CLAIM_LIST.remove(player.getUniqueId());
            EagleFactionsPlugin.CHAT_LIST.remove(player.getUniqueId());
        }
    }
    else
    {
        throw new CommandException((Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.RED, Messages.SOMETHING_WENT_WRONG)));
    }

    /* After a successful disband we can regenerate faction claims. */

    for (Claim claim : factionToRegen.getClaims())
    {
        Optional<World> world = Sponge.getServer().getWorld(claim.getWorldUUID());

        if (!world.isPresent())
        {
            throw new CommandException((Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.RED, Messages.SOMETHING_WENT_WRONG)));
        }

        world.get().regenerateChunk(claim.getChunkPosition());
    }

    source.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.WHITE, Messages.FACTION_HAS_BEEN_REGENERATED));

    return CommandResult.success();
}
 
Example 15
Source File: AccessPlayerCommand.java    From EagleFactions with MIT License 4 votes vote down vote up
@Override
public CommandResult execute(CommandSource source, CommandContext context) throws CommandException
{
    final FactionPlayer factionPlayer = context.requireOne(Text.of("player"));

    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();

    if (claim.getOwners().contains(factionPlayer.getUniqueId()))
    {
        super.getPlugin().getFactionLogic().removeClaimOwner(chunkFaction, claim, factionPlayer.getUniqueId());
        ParticlesUtil.spawnRemoveAccessParticles(claim);
        source.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.GOLD, factionPlayer.getName(), TextColors.GREEN, " has been removed from the claim ", TextColors.GOLD, claim.getChunkPosition()));
    }
    else
    {
        super.getPlugin().getFactionLogic().addClaimOwner(chunkFaction, claim, factionPlayer.getUniqueId());
        ParticlesUtil.spawnAddAccessParticles(claim);
        source.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.GOLD, factionPlayer.getName(), TextColors.GREEN, " has been added to the claim ", TextColors.GOLD, claim.getChunkPosition()));
    }

    return CommandResult.success();
}
 
Example 16
Source File: SetLeaderCommand.java    From EagleFactions with MIT License 4 votes vote down vote up
@Override
public CommandResult execute(final CommandSource source, final CommandContext context) throws CommandException
{
    final FactionPlayer newLeaderPlayer = context.requireOne("player");

    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());
    final Optional<Faction> optionalNewLeaderPlayerFaction = getPlugin().getFactionLogic().getFactionByPlayerUUID(newLeaderPlayer.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();

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

    if(!optionalNewLeaderPlayerFaction.get().getName().equals(playerFaction.getName()))
        throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.THIS_PLAYER_IS_NOT_IN_YOUR_FACTION));

    if (super.getPlugin().getPlayerManager().hasAdminMode(player))
    {
        if(playerFaction.getLeader().equals(newLeaderPlayer.getUniqueId()))
            throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_ALREADY_ARE_THE_LEADER_OF_THIS_FACTION));

        super.getPlugin().getFactionLogic().setLeader(newLeaderPlayer.getUniqueId(), playerFaction.getName());
        source.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, MessageLoader.parseMessage(Messages.YOU_SET_PLAYER_AS_YOUR_NEW_LEADER, TextColors.GREEN, ImmutableMap.of(Placeholders.PLAYER, Text.of(TextColors.GOLD, newLeaderPlayer.getName())))));
        return CommandResult.success();
    }
    else if (playerFaction.getLeader().equals(player.getUniqueId()))
    {
        if(playerFaction.getLeader().equals(newLeaderPlayer.getUniqueId()))
            throw new CommandException(Text.of(PluginInfo.ERROR_PREFIX, TextColors.RED, Messages.YOU_ALREADY_ARE_THE_LEADER_OF_THIS_FACTION));

        super.getPlugin().getFactionLogic().setLeader(newLeaderPlayer.getUniqueId(), playerFaction.getName());
        source.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, MessageLoader.parseMessage(Messages.YOU_SET_PLAYER_AS_YOUR_NEW_LEADER, TextColors.GREEN, ImmutableMap.of(Placeholders.PLAYER, Text.of(TextColors.GOLD, newLeaderPlayer.getName())))));
    }
    return CommandResult.success();
}