Rework the /f invite command to be a parentcommand.
This commit is contained in:
		
				
					committed by
					
						
						Olof Larsson
					
				
			
			
				
	
			
			
			
						parent
						
							29a4feeff6
						
					
				
				
					commit
					486f8ac957
				
			
							
								
								
									
										14
									
								
								plugin.yml
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								plugin.yml
									
									
									
									
									
								
							@@ -29,7 +29,11 @@ permissions:
 | 
				
			|||||||
  factions.faction: {description: show faction information, default: false}
 | 
					  factions.faction: {description: show faction information, default: false}
 | 
				
			||||||
  factions.flag: {description: manage faction flags, default: false}
 | 
					  factions.flag: {description: manage faction flags, default: false}
 | 
				
			||||||
  factions.home: {description: teleport to faction home, default: false}
 | 
					  factions.home: {description: teleport to faction home, default: false}
 | 
				
			||||||
  factions.invite: {description: set if player is invited, default: false}
 | 
					  factions.invite: {description: manage invites, default: false}
 | 
				
			||||||
 | 
					  factions.invite.list: {description: list invited players, default: false}
 | 
				
			||||||
 | 
					  factions.invite.list.other: {description: list invited players of another factions, default: false}
 | 
				
			||||||
 | 
					  factions.invite.add: {description: invite player, default: false}
 | 
				
			||||||
 | 
					  factions.invite.remove: {description: revoke an invite, default: false}
 | 
				
			||||||
  factions.join: {description: join faction, default: false}
 | 
					  factions.join: {description: join faction, default: false}
 | 
				
			||||||
  factions.join.any: {description: join closed faction, default: false}
 | 
					  factions.join.any: {description: join closed faction, default: false}
 | 
				
			||||||
  factions.join.others: {description: have another player join faction, default: false}
 | 
					  factions.join.others: {description: have another player join faction, default: false}
 | 
				
			||||||
@@ -95,6 +99,10 @@ permissions:
 | 
				
			|||||||
      factions.flag: true
 | 
					      factions.flag: true
 | 
				
			||||||
      factions.home: true
 | 
					      factions.home: true
 | 
				
			||||||
      factions.invite: true
 | 
					      factions.invite: true
 | 
				
			||||||
 | 
					      factions.invite.list: true
 | 
				
			||||||
 | 
					      factions.invite.list.other: true
 | 
				
			||||||
 | 
					      factions.invite.add: true
 | 
				
			||||||
 | 
					      factions.invite.remove: true
 | 
				
			||||||
      factions.join: true
 | 
					      factions.join: true
 | 
				
			||||||
      factions.join.any: true
 | 
					      factions.join.any: true
 | 
				
			||||||
      factions.join.others: true
 | 
					      factions.join.others: true
 | 
				
			||||||
@@ -162,6 +170,7 @@ permissions:
 | 
				
			|||||||
    children:
 | 
					    children:
 | 
				
			||||||
      factions.kit.rank0: true
 | 
					      factions.kit.rank0: true
 | 
				
			||||||
      factions.admin: true
 | 
					      factions.admin: true
 | 
				
			||||||
 | 
					      factions.invite.list.other: true
 | 
				
			||||||
  factions.kit.rank0:
 | 
					  factions.kit.rank0:
 | 
				
			||||||
    default: false
 | 
					    default: false
 | 
				
			||||||
    children:
 | 
					    children:
 | 
				
			||||||
@@ -185,6 +194,9 @@ permissions:
 | 
				
			|||||||
      factions.flag: true
 | 
					      factions.flag: true
 | 
				
			||||||
      factions.home: true
 | 
					      factions.home: true
 | 
				
			||||||
      factions.invite: true
 | 
					      factions.invite: true
 | 
				
			||||||
 | 
					      factions.invite.list: true
 | 
				
			||||||
 | 
					      factions.invite.add: true
 | 
				
			||||||
 | 
					      factions.invite.remove: true
 | 
				
			||||||
      factions.join: true
 | 
					      factions.join: true
 | 
				
			||||||
      factions.kick: true
 | 
					      factions.kick: true
 | 
				
			||||||
      factions.leader: true
 | 
					      factions.leader: true
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -30,6 +30,10 @@ public enum Perm
 | 
				
			|||||||
	FLAG("flag"),
 | 
						FLAG("flag"),
 | 
				
			||||||
	HOME("home"),
 | 
						HOME("home"),
 | 
				
			||||||
	INVITE("invite"),
 | 
						INVITE("invite"),
 | 
				
			||||||
 | 
						INVITE_LIST("invite.list"),
 | 
				
			||||||
 | 
						INVITE_LIST_OTHER("invite.list.other"),
 | 
				
			||||||
 | 
						INVITE_ADD("invite.add"),
 | 
				
			||||||
 | 
						INVITE_REMOVE("invite.remove"),
 | 
				
			||||||
	JOIN("join"),
 | 
						JOIN("join"),
 | 
				
			||||||
	JOIN_ANY("join.any"),
 | 
						JOIN_ANY("join.any"),
 | 
				
			||||||
	JOIN_OTHERS("join.others"),
 | 
						JOIN_OTHERS("join.others"),
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,18 +1,18 @@
 | 
				
			|||||||
package com.massivecraft.factions.cmd;
 | 
					package com.massivecraft.factions.cmd;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.massivecraft.factions.Factions;
 | 
					 | 
				
			||||||
import com.massivecraft.factions.Perm;
 | 
					import com.massivecraft.factions.Perm;
 | 
				
			||||||
import com.massivecraft.factions.cmd.arg.ARMPlayer;
 | 
					 | 
				
			||||||
import com.massivecraft.factions.cmd.req.ReqHasFaction;
 | 
					 | 
				
			||||||
import com.massivecraft.factions.entity.MPerm;
 | 
					 | 
				
			||||||
import com.massivecraft.factions.entity.MPlayer;
 | 
					 | 
				
			||||||
import com.massivecraft.factions.event.EventFactionsInvitedChange;
 | 
					 | 
				
			||||||
import com.massivecraft.massivecore.cmd.arg.ARBoolean;
 | 
					 | 
				
			||||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
 | 
					import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
 | 
				
			||||||
import com.massivecraft.massivecore.cmd.req.ReqIsPlayer;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class CmdFactionsInvite extends FactionsCommand
 | 
					public class CmdFactionsInvite extends FactionsCommand
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						// -------------------------------------------- //
 | 
				
			||||||
 | 
						// FIELDS
 | 
				
			||||||
 | 
						// -------------------------------------------- //
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public CmdFactionsInviteList cmdFactionsInviteList = new CmdFactionsInviteList();
 | 
				
			||||||
 | 
						public CmdFactionsInviteAdd cmdFactionsInviteAdd = new CmdFactionsInviteAdd();
 | 
				
			||||||
 | 
						public CmdFactionsInviteRemove cmdFactionsInviteRemove = new CmdFactionsInviteRemove();
 | 
				
			||||||
 | 
						
 | 
				
			||||||
	// -------------------------------------------- //
 | 
						// -------------------------------------------- //
 | 
				
			||||||
	// CONSTRUCT
 | 
						// CONSTRUCT
 | 
				
			||||||
	// -------------------------------------------- //
 | 
						// -------------------------------------------- //
 | 
				
			||||||
@@ -20,63 +20,16 @@ public class CmdFactionsInvite extends FactionsCommand
 | 
				
			|||||||
	public CmdFactionsInvite()
 | 
						public CmdFactionsInvite()
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		// Aliases
 | 
							// Aliases
 | 
				
			||||||
		this.addAliases("inv", "invite");
 | 
							this.addAliases("i", "inv", "invite");
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// Add SubCommands
 | 
				
			||||||
 | 
							this.addSubCommand(this.cmdFactionsInviteAdd);
 | 
				
			||||||
 | 
							this.addSubCommand(this.cmdFactionsInviteRemove);
 | 
				
			||||||
 | 
							this.addSubCommand(this.cmdFactionsInviteList);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Args
 | 
					 | 
				
			||||||
		this.addRequiredArg("player");
 | 
					 | 
				
			||||||
		this.addOptionalArg("yes/no", "toggle");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Requirements
 | 
							// Requirements
 | 
				
			||||||
		this.addRequirements(ReqHasPerm.get(Perm.INVITE.node));
 | 
							this.addRequirements(ReqHasPerm.get(Perm.INVITE.node));
 | 
				
			||||||
		this.addRequirements(ReqHasFaction.get());
 | 
					 | 
				
			||||||
		this.addRequirements(ReqIsPlayer.get());
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// -------------------------------------------- //
 | 
					 | 
				
			||||||
	// OVERRIDE
 | 
					 | 
				
			||||||
	// -------------------------------------------- //
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	@Override
 | 
					 | 
				
			||||||
	public void perform()
 | 
					 | 
				
			||||||
	{
 | 
					 | 
				
			||||||
		// Args
 | 
					 | 
				
			||||||
		MPlayer mplayer = this.arg(0, ARMPlayer.getAny());
 | 
					 | 
				
			||||||
		if (mplayer == null) return;
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		Boolean newInvited = this.arg(1, ARBoolean.get(), !msenderFaction.isInvited(mplayer));
 | 
					 | 
				
			||||||
		if (newInvited == null) return;
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		// Allready member?
 | 
					 | 
				
			||||||
		if (mplayer.getFaction() == msenderFaction)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			msg("%s<i> is already a member of %s", mplayer.getName(), msenderFaction.getName());
 | 
					 | 
				
			||||||
			msg("<i>You might want to: " + Factions.get().getOuterCmdFactions().cmdFactionsKick.getUseageTemplate(false));
 | 
					 | 
				
			||||||
			return;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		// MPerm
 | 
					 | 
				
			||||||
		if ( ! MPerm.getPermInvite().has(msender, msenderFaction, true)) return;
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		// Event
 | 
					 | 
				
			||||||
		EventFactionsInvitedChange event = new EventFactionsInvitedChange(sender, mplayer, msenderFaction, newInvited);
 | 
					 | 
				
			||||||
		event.run();
 | 
					 | 
				
			||||||
		if (event.isCancelled()) return;
 | 
					 | 
				
			||||||
		newInvited = event.isNewInvited();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// Apply
 | 
					 | 
				
			||||||
		msenderFaction.setInvited(mplayer, newInvited);
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		// Inform
 | 
					 | 
				
			||||||
		if (newInvited)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			mplayer.msg("%s<i> invited you to %s", msender.describeTo(mplayer, true), msenderFaction.describeTo(mplayer));
 | 
					 | 
				
			||||||
			msenderFaction.msg("%s<i> invited %s<i> to your faction.", msender.describeTo(msenderFaction, true), mplayer.describeTo(msenderFaction));
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		else
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			mplayer.msg("%s<i> revoked your invitation to <h>%s<i>.", msender.describeTo(mplayer), msenderFaction.describeTo(mplayer));
 | 
					 | 
				
			||||||
			msenderFaction.msg("%s<i> revoked %s's<i> invitation.", msender.describeTo(msenderFaction), mplayer.describeTo(msenderFaction));
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										82
									
								
								src/com/massivecraft/factions/cmd/CmdFactionsInviteAdd.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										82
									
								
								src/com/massivecraft/factions/cmd/CmdFactionsInviteAdd.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,82 @@
 | 
				
			|||||||
 | 
					package com.massivecraft.factions.cmd;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.Set;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.massivecraft.factions.Factions;
 | 
				
			||||||
 | 
					import com.massivecraft.factions.Perm;
 | 
				
			||||||
 | 
					import com.massivecraft.factions.cmd.arg.ARMPlayer;
 | 
				
			||||||
 | 
					import com.massivecraft.factions.entity.MPerm;
 | 
				
			||||||
 | 
					import com.massivecraft.factions.entity.MPlayer;
 | 
				
			||||||
 | 
					import com.massivecraft.factions.event.EventFactionsInvitedChange;
 | 
				
			||||||
 | 
					import com.massivecraft.massivecore.cmd.arg.ARSet;
 | 
				
			||||||
 | 
					import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class CmdFactionsInviteAdd extends FactionsCommand
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						// -------------------------------------------- //
 | 
				
			||||||
 | 
						// CONSTRUCT
 | 
				
			||||||
 | 
						// -------------------------------------------- //
 | 
				
			||||||
 | 
						public CmdFactionsInviteAdd()
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							// Aliases
 | 
				
			||||||
 | 
							this.addAliases("a", "add");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Args
 | 
				
			||||||
 | 
							this.addRequiredArg("players");
 | 
				
			||||||
 | 
							this.setErrorOnToManyArgs(false);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// Requirements
 | 
				
			||||||
 | 
							this.addRequirements(ReqHasPerm.get(Perm.INVITE_ADD.node));
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// -------------------------------------------- //
 | 
				
			||||||
 | 
						// OVERRIDE
 | 
				
			||||||
 | 
						// -------------------------------------------- //	
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						@Override
 | 
				
			||||||
 | 
						public void perform()
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							// Args
 | 
				
			||||||
 | 
							Set<MPlayer> mplayers = this.argConcatFrom(0, ARSet.get(ARMPlayer.getAny(), true));
 | 
				
			||||||
 | 
							if (mplayers == null) return;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// MPerm
 | 
				
			||||||
 | 
							if ( ! MPerm.getPermInvite().has(msender, msenderFaction, true)) return;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							for (MPlayer mplayer : mplayers)
 | 
				
			||||||
 | 
							{	
 | 
				
			||||||
 | 
								// Already member?
 | 
				
			||||||
 | 
								if (mplayer.getFaction() == msenderFaction)
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									msg("%s<i> is already a member of %s<i>.", mplayer.getName(), msenderFaction.getName());
 | 
				
			||||||
 | 
									continue;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// Already invited?
 | 
				
			||||||
 | 
								boolean isInvited = msenderFaction.isInvited(mplayer);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if ( ! isInvited)
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									// Event
 | 
				
			||||||
 | 
									EventFactionsInvitedChange event = new EventFactionsInvitedChange(sender, mplayer, msenderFaction, isInvited);
 | 
				
			||||||
 | 
									event.run();
 | 
				
			||||||
 | 
									if (event.isCancelled()) continue;
 | 
				
			||||||
 | 
									isInvited = event.isNewInvited();
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									// Inform
 | 
				
			||||||
 | 
									mplayer.msg("%s<i> invited you to %s<i>.", msender.describeTo(mplayer, true), msenderFaction.describeTo(mplayer));
 | 
				
			||||||
 | 
									msenderFaction.msg("%s<i> invited %s<i> to your faction.", msender.describeTo(msenderFaction, true), mplayer.describeTo(msenderFaction));
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									// Apply
 | 
				
			||||||
 | 
									msenderFaction.setInvited(mplayer, true);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								else
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									// Inform
 | 
				
			||||||
 | 
									msg("%s <i>is already invited to %s<i>.", mplayer.getName(), msenderFaction.getName());
 | 
				
			||||||
 | 
									msg("<i>You might want to: " + Factions.get().getOuterCmdFactions().cmdFactionsInvite.cmdFactionsInviteRemove.getUseageTemplate(false));
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										85
									
								
								src/com/massivecraft/factions/cmd/CmdFactionsInviteList.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										85
									
								
								src/com/massivecraft/factions/cmd/CmdFactionsInviteList.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,85 @@
 | 
				
			|||||||
 | 
					package com.massivecraft.factions.cmd;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.massivecraft.factions.Perm;
 | 
				
			||||||
 | 
					import com.massivecraft.factions.Rel;
 | 
				
			||||||
 | 
					import com.massivecraft.factions.cmd.arg.ARFaction;
 | 
				
			||||||
 | 
					import com.massivecraft.factions.entity.Faction;
 | 
				
			||||||
 | 
					import com.massivecraft.factions.entity.MPerm;
 | 
				
			||||||
 | 
					import com.massivecraft.factions.entity.MPlayer;
 | 
				
			||||||
 | 
					import com.massivecraft.massivecore.cmd.arg.ARInteger;
 | 
				
			||||||
 | 
					import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
 | 
				
			||||||
 | 
					import com.massivecraft.massivecore.pager.PagerSimple;
 | 
				
			||||||
 | 
					import com.massivecraft.massivecore.pager.Stringifier;
 | 
				
			||||||
 | 
					import com.massivecraft.massivecore.util.Txt;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class CmdFactionsInviteList extends FactionsCommand
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						// -------------------------------------------- //
 | 
				
			||||||
 | 
						// CONSTRUCT
 | 
				
			||||||
 | 
						// -------------------------------------------- //
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						public CmdFactionsInviteList()
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							// Aliases
 | 
				
			||||||
 | 
							this.addAliases("l", "list");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Args
 | 
				
			||||||
 | 
							this.addOptionalArg("page", "1");
 | 
				
			||||||
 | 
							this.addOptionalArg("faction", "you");
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// Requirements
 | 
				
			||||||
 | 
							this.addRequirements(ReqHasPerm.get(Perm.INVITE_LIST.node));
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// -------------------------------------------- //
 | 
				
			||||||
 | 
						// OVERRIDE
 | 
				
			||||||
 | 
						// -------------------------------------------- //	
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						@Override
 | 
				
			||||||
 | 
						public void perform()
 | 
				
			||||||
 | 
						{		
 | 
				
			||||||
 | 
							// Args	
 | 
				
			||||||
 | 
							Integer pageHumanBased = this.arg(0, ARInteger.get(), 1);
 | 
				
			||||||
 | 
							if (pageHumanBased == null) return;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							Faction faction = this.arg(1, ARFaction.get(), msenderFaction);
 | 
				
			||||||
 | 
							if (faction == null) return;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if ( faction != msenderFaction && ! Perm.INVITE_LIST_OTHER.has(sender, true)) return;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// MPerm
 | 
				
			||||||
 | 
							if ( ! MPerm.getPermInvite().has(msender, msenderFaction, true)) return;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// Create Pager
 | 
				
			||||||
 | 
							final List<MPlayer> mplayers = faction.getInvitedMPlayers();
 | 
				
			||||||
 | 
							final PagerSimple<MPlayer> pager = new PagerSimple<MPlayer>(mplayers, sender);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// Use Pager
 | 
				
			||||||
 | 
							List<String> messages = pager.getPageTxt(pageHumanBased, "Invited Players List", new Stringifier<MPlayer>(){
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								public String toString(MPlayer target)
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									// TODO: Madus would like to implement this in MPlayer
 | 
				
			||||||
 | 
									String targetName = target.getDisplayName(msender);
 | 
				
			||||||
 | 
									String isAre = target == msender ? "are" : "is";
 | 
				
			||||||
 | 
									Rel targetRank = target.getRole();
 | 
				
			||||||
 | 
									Faction targetFaction = target.getFaction();
 | 
				
			||||||
 | 
									String theAan = targetRank == Rel.LEADER ? "the" : Txt.aan(targetRank.name());
 | 
				
			||||||
 | 
									String rankName = Txt.getNicedEnum(targetRank).toLowerCase();
 | 
				
			||||||
 | 
									String ofIn = targetRank == Rel.LEADER ? "of" : "in";
 | 
				
			||||||
 | 
									String factionName = targetFaction.describeTo(msender, true);
 | 
				
			||||||
 | 
									if (targetFaction == msenderFaction)
 | 
				
			||||||
 | 
									{
 | 
				
			||||||
 | 
										factionName = factionName.toLowerCase();
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									return Txt.parse("%s <i>%s %s <h>%s <i>%s %s<i>.", targetName, isAre, theAan, rankName, ofIn, factionName);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// Send message
 | 
				
			||||||
 | 
							sendMessage(messages);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										117
									
								
								src/com/massivecraft/factions/cmd/CmdFactionsInviteRemove.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										117
									
								
								src/com/massivecraft/factions/cmd/CmdFactionsInviteRemove.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,117 @@
 | 
				
			|||||||
 | 
					package com.massivecraft.factions.cmd;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.HashSet;
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					import java.util.Set;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.massivecraft.factions.Factions;
 | 
				
			||||||
 | 
					import com.massivecraft.factions.Perm;
 | 
				
			||||||
 | 
					import com.massivecraft.factions.cmd.arg.ARMPlayer;
 | 
				
			||||||
 | 
					import com.massivecraft.factions.entity.MPerm;
 | 
				
			||||||
 | 
					import com.massivecraft.factions.entity.MPlayer;
 | 
				
			||||||
 | 
					import com.massivecraft.factions.event.EventFactionsInvitedChange;
 | 
				
			||||||
 | 
					import com.massivecraft.massivecore.cmd.arg.ARSet;
 | 
				
			||||||
 | 
					import com.massivecraft.massivecore.cmd.arg.ARString;
 | 
				
			||||||
 | 
					import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class CmdFactionsInviteRemove extends FactionsCommand
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						// -------------------------------------------- //
 | 
				
			||||||
 | 
						// CONSTRUCT
 | 
				
			||||||
 | 
						// -------------------------------------------- //
 | 
				
			||||||
 | 
						public CmdFactionsInviteRemove()
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							// Aliases
 | 
				
			||||||
 | 
							this.addAliases("r", "remove");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Args
 | 
				
			||||||
 | 
							this.addRequiredArg("players/all");
 | 
				
			||||||
 | 
							this.setErrorOnToManyArgs(false);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// Requirements
 | 
				
			||||||
 | 
							this.addRequirements(ReqHasPerm.get(Perm.INVITE_REMOVE.node));
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						// -------------------------------------------- //
 | 
				
			||||||
 | 
						// OVERRIDE
 | 
				
			||||||
 | 
						// -------------------------------------------- //	
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						@Override
 | 
				
			||||||
 | 
						public void perform()
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							Set<MPlayer> mplayers = new HashSet<MPlayer>();
 | 
				
			||||||
 | 
							boolean all = false;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// Args
 | 
				
			||||||
 | 
							if (this.arg(0, ARString.get()).equalsIgnoreCase("all"))
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								List<MPlayer> invitedPlayers = msenderFaction.getInvitedMPlayers();
 | 
				
			||||||
 | 
								// Doesn't show up if list is empty. Test at home if it worked.
 | 
				
			||||||
 | 
								if (invitedPlayers == null || invitedPlayers.isEmpty())
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									msg("<b>Your faction has not invited anyone.");
 | 
				
			||||||
 | 
									return;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								all = true;
 | 
				
			||||||
 | 
								mplayers.addAll(invitedPlayers);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							else
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								Set<MPlayer> senderInput = this.argConcatFrom(0, ARSet.get(ARMPlayer.getAny(), true));
 | 
				
			||||||
 | 
								if (senderInput == null) return;
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								mplayers.addAll(senderInput);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// MPerm
 | 
				
			||||||
 | 
							if ( ! MPerm.getPermInvite().has(msender, msenderFaction, true)) return;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							for (MPlayer mplayer : mplayers)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								// Already member?
 | 
				
			||||||
 | 
								if (mplayer.getFaction() == msenderFaction)
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									msg("%s<i> is already a member of %s<i>.", mplayer.getName(), msenderFaction.getName());
 | 
				
			||||||
 | 
									msg("<i>You might want to: " + Factions.get().getOuterCmdFactions().cmdFactionsKick.getUseageTemplate(false));
 | 
				
			||||||
 | 
									continue;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								// Already invited?
 | 
				
			||||||
 | 
								boolean isInvited = msenderFaction.isInvited(mplayer);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
								if (isInvited)
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									// Event
 | 
				
			||||||
 | 
									EventFactionsInvitedChange event = new EventFactionsInvitedChange(sender, mplayer, msenderFaction, isInvited);
 | 
				
			||||||
 | 
									event.run();
 | 
				
			||||||
 | 
									if (event.isCancelled()) continue;
 | 
				
			||||||
 | 
									isInvited = event.isNewInvited();
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									// Inform Player
 | 
				
			||||||
 | 
									mplayer.msg("%s<i> revoked your invitation to <h>%s<i>.", msender.describeTo(mplayer, true), msenderFaction.describeTo(mplayer));
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									// Inform Faction
 | 
				
			||||||
 | 
									if ( ! all)
 | 
				
			||||||
 | 
									{
 | 
				
			||||||
 | 
										msenderFaction.msg("%s<i> revoked %s's<i> invitation.", msender.describeTo(msenderFaction), mplayer.describeTo(msenderFaction));
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									// Apply
 | 
				
			||||||
 | 
									msenderFaction.setInvited(mplayer, false);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								else
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									// Inform
 | 
				
			||||||
 | 
									msg("%s <i>is not invited to %s<i>.", mplayer.describeTo(msender, true), msenderFaction.describeTo(mplayer));
 | 
				
			||||||
 | 
									msg("<i>You might want to: " + Factions.get().getOuterCmdFactions().cmdFactionsInvite.cmdFactionsInviteAdd.getUseageTemplate(false));
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// Inform Faction if all
 | 
				
			||||||
 | 
							if (all)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								msenderFaction.msg("%s<i> revoked all <h>%s <i>pending invitations from your faction.", msender.describeTo(msenderFaction), mplayers.size());
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -482,6 +482,18 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
 | 
				
			|||||||
		this.setInvited(mplayer.getId(), invited);
 | 
							this.setInvited(mplayer.getId(), invited);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
 | 
						public List<MPlayer> getInvitedMPlayers()
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							List<MPlayer> mplayers = new ArrayList<MPlayer>();
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							for (String id : this.getInvitedPlayerIds())
 | 
				
			||||||
 | 
							{	
 | 
				
			||||||
 | 
								MPlayer mplayer = MPlayer.get(id);
 | 
				
			||||||
 | 
								mplayers.add(mplayer);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return mplayers;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
	// -------------------------------------------- //
 | 
						// -------------------------------------------- //
 | 
				
			||||||
	// FIELD: relationWish
 | 
						// FIELD: relationWish
 | 
				
			||||||
	// -------------------------------------------- //
 | 
						// -------------------------------------------- //
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user