5h- Rework relation commands.
This commit is contained in:
		
				
					committed by
					
						
						Olof Larsson
					
				
			
			
				
	
			
			
			
						parent
						
							1f5e591ce6
						
					
				
				
					commit
					47332f96d5
				
			@@ -52,10 +52,11 @@ public class CmdFactions extends FactionsCommand
 | 
			
		||||
	public CmdFactionsClaim cmdFactionsClaim = new CmdFactionsClaim();
 | 
			
		||||
	public CmdFactionsUnclaim cmdFactionsUnclaim = new CmdFactionsUnclaim();
 | 
			
		||||
	public CmdFactionsAccess cmdFactionsAccess = new CmdFactionsAccess();
 | 
			
		||||
	public CmdFactionsRelationAlly cmdFactionsRelationAlly = new CmdFactionsRelationAlly();
 | 
			
		||||
	public CmdFactionsRelationTruce cmdFactionsRelationTruce = new CmdFactionsRelationTruce();
 | 
			
		||||
	public CmdFactionsRelationNeutral cmdFactionsRelationNeutral = new CmdFactionsRelationNeutral();
 | 
			
		||||
	public CmdFactionsRelationEnemy cmdFactionsRelationEnemy = new CmdFactionsRelationEnemy();
 | 
			
		||||
	public CmdFactionsRelation cmdFactionsRelation = new CmdFactionsRelation();
 | 
			
		||||
	public CmdFactionsRelationOld cmdFactionsRelationOldAlly = new CmdFactionsRelationOld("ally");
 | 
			
		||||
	public CmdFactionsRelationOld cmdFactionsRelationOldTruce = new CmdFactionsRelationOld("truce");
 | 
			
		||||
	public CmdFactionsRelationOld cmdFactionsRelationOldNeutral = new CmdFactionsRelationOld("neutral");
 | 
			
		||||
	public CmdFactionsRelationOld cmdFactionsRelationOldEnemy = new CmdFactionsRelationOld("enemy");
 | 
			
		||||
	public CmdFactionsPerm cmdFactionsPerm = new CmdFactionsPerm();
 | 
			
		||||
	public CmdFactionsFlag cmdFactionsFlag = new CmdFactionsFlag();
 | 
			
		||||
	public CmdFactionsUnstuck cmdFactionsUnstuck = new CmdFactionsUnstuck();
 | 
			
		||||
@@ -106,10 +107,11 @@ public class CmdFactions extends FactionsCommand
 | 
			
		||||
		this.addChild(this.cmdFactionsClaim);
 | 
			
		||||
		this.addChild(this.cmdFactionsUnclaim);
 | 
			
		||||
		this.addChild(this.cmdFactionsAccess);
 | 
			
		||||
		this.addChild(this.cmdFactionsRelationAlly);
 | 
			
		||||
		this.addChild(this.cmdFactionsRelationTruce);
 | 
			
		||||
		this.addChild(this.cmdFactionsRelationNeutral);
 | 
			
		||||
		this.addChild(this.cmdFactionsRelationEnemy);
 | 
			
		||||
		this.addChild(this.cmdFactionsRelation);
 | 
			
		||||
		this.addChild(this.cmdFactionsRelationOldAlly);
 | 
			
		||||
		this.addChild(this.cmdFactionsRelationOldTruce);
 | 
			
		||||
		this.addChild(this.cmdFactionsRelationOldNeutral);
 | 
			
		||||
		this.addChild(this.cmdFactionsRelationOldEnemy);
 | 
			
		||||
		this.addChild(this.cmdFactionsPerm);
 | 
			
		||||
		this.addChild(this.cmdFactionsFlag);
 | 
			
		||||
		this.addChild(this.cmdFactionsUnstuck);
 | 
			
		||||
 
 | 
			
		||||
@@ -43,7 +43,6 @@ public class CmdFactionsFaction extends FactionsCommand
 | 
			
		||||
	{
 | 
			
		||||
		// Args
 | 
			
		||||
		final Faction faction = this.readArg(msenderFaction);
 | 
			
		||||
		
 | 
			
		||||
		final CommandSender sender = this.sender;
 | 
			
		||||
		
 | 
			
		||||
		Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), new Runnable()
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										37
									
								
								src/com/massivecraft/factions/cmd/CmdFactionsRelation.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								src/com/massivecraft/factions/cmd/CmdFactionsRelation.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,37 @@
 | 
			
		||||
package com.massivecraft.factions.cmd;
 | 
			
		||||
 | 
			
		||||
import com.massivecraft.factions.Perm;
 | 
			
		||||
import com.massivecraft.factions.cmd.req.ReqHasFaction;
 | 
			
		||||
 | 
			
		||||
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
 | 
			
		||||
 | 
			
		||||
public class CmdFactionsRelation extends FactionsCommand
 | 
			
		||||
{
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// FIELDS
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
 | 
			
		||||
	public CmdFactionsRelationSet cmdFactionsRelationSet = new CmdFactionsRelationSet();
 | 
			
		||||
	public CmdFactionsRelationList cmdFactionsRelationList = new CmdFactionsRelationList();
 | 
			
		||||
	public CmdFactionsRelationWishes cmdFactionsRelationWishes = new CmdFactionsRelationWishes();
 | 
			
		||||
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// CONSTRUCT
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
 | 
			
		||||
	public CmdFactionsRelation()
 | 
			
		||||
	{
 | 
			
		||||
		// Children
 | 
			
		||||
		this.addChild(this.cmdFactionsRelationSet);
 | 
			
		||||
		this.addChild(this.cmdFactionsRelationList);
 | 
			
		||||
		this.addChild(this.cmdFactionsRelationWishes);
 | 
			
		||||
 | 
			
		||||
		// Aliases
 | 
			
		||||
		this.addAliases("relation");
 | 
			
		||||
 | 
			
		||||
		// Requirements
 | 
			
		||||
		this.addRequirements(RequirementHasPerm.get(Perm.RELATION.node));
 | 
			
		||||
		this.addRequirements(ReqHasFaction.get());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,20 +0,0 @@
 | 
			
		||||
package com.massivecraft.factions.cmd;
 | 
			
		||||
 | 
			
		||||
import com.massivecraft.factions.Rel;
 | 
			
		||||
 | 
			
		||||
public class CmdFactionsRelationAlly extends CmdFactionsRelationAbstract
 | 
			
		||||
{
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// CONSTRUCT
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	
 | 
			
		||||
	public CmdFactionsRelationAlly()
 | 
			
		||||
	{
 | 
			
		||||
		// Aliases
 | 
			
		||||
		this.addAliases("ally");
 | 
			
		||||
		
 | 
			
		||||
		// Misc
 | 
			
		||||
		this.targetRelation = Rel.ALLY;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
@@ -1,20 +0,0 @@
 | 
			
		||||
package com.massivecraft.factions.cmd;
 | 
			
		||||
 | 
			
		||||
import com.massivecraft.factions.Rel;
 | 
			
		||||
 | 
			
		||||
public class CmdFactionsRelationEnemy extends CmdFactionsRelationAbstract
 | 
			
		||||
{
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// CONSTRUCT
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	
 | 
			
		||||
	public CmdFactionsRelationEnemy()
 | 
			
		||||
	{
 | 
			
		||||
		// Aliases
 | 
			
		||||
		this.addAliases("enemy");
 | 
			
		||||
		
 | 
			
		||||
		// Misc
 | 
			
		||||
		this.targetRelation = Rel.ENEMY;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										110
									
								
								src/com/massivecraft/factions/cmd/CmdFactionsRelationList.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										110
									
								
								src/com/massivecraft/factions/cmd/CmdFactionsRelationList.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,110 @@
 | 
			
		||||
package com.massivecraft.factions.cmd;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map.Entry;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
 | 
			
		||||
import com.massivecraft.factions.Factions;
 | 
			
		||||
import com.massivecraft.factions.Perm;
 | 
			
		||||
import com.massivecraft.factions.Rel;
 | 
			
		||||
import com.massivecraft.factions.cmd.req.ReqHasFaction;
 | 
			
		||||
import com.massivecraft.factions.cmd.type.TypeFaction;
 | 
			
		||||
import com.massivecraft.factions.cmd.type.TypeRelation;
 | 
			
		||||
import com.massivecraft.factions.entity.Faction;
 | 
			
		||||
import com.massivecraft.factions.entity.FactionColl;
 | 
			
		||||
 | 
			
		||||
import com.massivecraft.massivecore.MassiveException;
 | 
			
		||||
import com.massivecraft.massivecore.collections.MassiveList;
 | 
			
		||||
import com.massivecraft.massivecore.collections.MassiveSet;
 | 
			
		||||
import com.massivecraft.massivecore.command.Parameter;
 | 
			
		||||
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
 | 
			
		||||
import com.massivecraft.massivecore.command.type.TypeNullable;
 | 
			
		||||
import com.massivecraft.massivecore.command.type.container.TypeSet;
 | 
			
		||||
import com.massivecraft.massivecore.pager.Pager;
 | 
			
		||||
import com.massivecraft.massivecore.pager.Stringifier;
 | 
			
		||||
import com.massivecraft.massivecore.util.Txt;
 | 
			
		||||
 | 
			
		||||
public class CmdFactionsRelationList extends FactionsCommand
 | 
			
		||||
{
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// COSTANTS
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
 | 
			
		||||
	public static final Set<Rel> RELEVANT_RELATIONS = new MassiveSet<Rel>(Rel.ENEMY, Rel.TRUCE, Rel.ALLY);
 | 
			
		||||
	public static final String SEPERATOR = Txt.parse("<silver>: ");
 | 
			
		||||
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// CONSTRUCT
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
 | 
			
		||||
	public CmdFactionsRelationList()
 | 
			
		||||
	{
 | 
			
		||||
		// Aliases
 | 
			
		||||
		this.addAliases("list");
 | 
			
		||||
 | 
			
		||||
		// Parameter
 | 
			
		||||
		this.addParameter(Parameter.getPage());
 | 
			
		||||
		this.addParameter(TypeFaction.get(), "faction", "you");
 | 
			
		||||
		this.addParameter(TypeNullable.get(TypeSet.get(TypeRelation.get()), "all"), "relation|all", "all");
 | 
			
		||||
 | 
			
		||||
		// Requirements
 | 
			
		||||
		this.addRequirements(RequirementHasPerm.get(Perm.RELATION_LIST.node));
 | 
			
		||||
		this.addRequirements(ReqHasFaction.get());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// OVERRIDE
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public void perform() throws MassiveException
 | 
			
		||||
	{
 | 
			
		||||
		// Args
 | 
			
		||||
		int page = this.readArg();
 | 
			
		||||
		final Faction faction = this.readArg(msenderFaction);
 | 
			
		||||
		final Set<Rel> rel = this.readArg();
 | 
			
		||||
		final Set<Rel> relations = rel == null ? RELEVANT_RELATIONS : rel;
 | 
			
		||||
 | 
			
		||||
		// Pager Create
 | 
			
		||||
		final Pager<String> pager = new Pager<String>(this, "", page, new Stringifier<String>()
 | 
			
		||||
		{
 | 
			
		||||
			@Override
 | 
			
		||||
			public String toString(String item, int index)
 | 
			
		||||
			{
 | 
			
		||||
				return item;
 | 
			
		||||
			}
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), new Runnable()
 | 
			
		||||
		{
 | 
			
		||||
			@Override
 | 
			
		||||
			public void run()
 | 
			
		||||
			{
 | 
			
		||||
				// Prepare Items
 | 
			
		||||
				List<String> relNames = new MassiveList<>();
 | 
			
		||||
				for (Entry<Rel, List<String>> entry : FactionColl.get().getRelationNames(faction, relations).entrySet())
 | 
			
		||||
				{
 | 
			
		||||
					Rel relation = entry.getKey();
 | 
			
		||||
					String coloredName = relation.getColor().toString() + relation.getName();
 | 
			
		||||
 | 
			
		||||
					for (String name : entry.getValue())
 | 
			
		||||
					{
 | 
			
		||||
						relNames.add(coloredName + SEPERATOR + name);
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				// Pager Title
 | 
			
		||||
				pager.setTitle(Txt.parse("<white>%s's <green>Relations <a>(%d)", faction.getName(), relNames.size()));
 | 
			
		||||
 | 
			
		||||
				// Pager Items
 | 
			
		||||
				pager.setItems(relNames);
 | 
			
		||||
 | 
			
		||||
				// Pager Message
 | 
			
		||||
				pager.message();
 | 
			
		||||
			}
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
@@ -1,20 +0,0 @@
 | 
			
		||||
package com.massivecraft.factions.cmd;
 | 
			
		||||
 | 
			
		||||
import com.massivecraft.factions.Rel;
 | 
			
		||||
 | 
			
		||||
public class CmdFactionsRelationNeutral extends CmdFactionsRelationAbstract
 | 
			
		||||
{
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// CONSTRUCT
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	
 | 
			
		||||
	public CmdFactionsRelationNeutral()
 | 
			
		||||
	{
 | 
			
		||||
		// Aliases
 | 
			
		||||
		this.addAliases("neutral");
 | 
			
		||||
		
 | 
			
		||||
		// Misc
 | 
			
		||||
		this.targetRelation = Rel.NEUTRAL;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,45 @@
 | 
			
		||||
package com.massivecraft.factions.cmd;
 | 
			
		||||
 | 
			
		||||
import com.massivecraft.factions.cmd.type.TypeFaction;
 | 
			
		||||
 | 
			
		||||
import com.massivecraft.massivecore.command.Visibility;
 | 
			
		||||
import com.massivecraft.massivecore.util.MUtil;
 | 
			
		||||
 | 
			
		||||
public class CmdFactionsRelationOld extends FactionsCommand
 | 
			
		||||
{
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// FIELDS
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
 | 
			
		||||
	public final String relName;
 | 
			
		||||
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// CONSTRUCT
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
 | 
			
		||||
	public CmdFactionsRelationOld(String rel)
 | 
			
		||||
	{
 | 
			
		||||
		// Fields
 | 
			
		||||
		this.relName = rel.toLowerCase();
 | 
			
		||||
 | 
			
		||||
		// Aliases
 | 
			
		||||
		this.addAliases(relName);
 | 
			
		||||
 | 
			
		||||
		// Parameters
 | 
			
		||||
		this.addParameter(TypeFaction.get(), "faction");
 | 
			
		||||
 | 
			
		||||
		// Visibility
 | 
			
		||||
		this.setVisibility(Visibility.INVISIBLE);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// OVERRIDE
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public void perform()
 | 
			
		||||
	{
 | 
			
		||||
		CmdFactions.get().cmdFactionsRelation.cmdFactionsRelationSet.execute(sender, MUtil.list(this.relName, this.argAt(0)));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,34 +1,40 @@
 | 
			
		||||
package com.massivecraft.factions.cmd;
 | 
			
		||||
 | 
			
		||||
import com.massivecraft.massivecore.command.MassiveCommand;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
 | 
			
		||||
import com.massivecraft.factions.Perm;
 | 
			
		||||
import com.massivecraft.factions.Rel;
 | 
			
		||||
import com.massivecraft.factions.cmd.req.ReqHasFaction;
 | 
			
		||||
import com.massivecraft.factions.cmd.type.TypeFaction;
 | 
			
		||||
import com.massivecraft.factions.cmd.type.TypeRelation;
 | 
			
		||||
import com.massivecraft.factions.entity.Faction;
 | 
			
		||||
import com.massivecraft.factions.entity.MFlag;
 | 
			
		||||
import com.massivecraft.factions.entity.MPerm;
 | 
			
		||||
import com.massivecraft.factions.event.EventFactionsRelationChange;
 | 
			
		||||
 | 
			
		||||
import com.massivecraft.massivecore.MassiveException;
 | 
			
		||||
import com.massivecraft.massivecore.command.MassiveCommand;
 | 
			
		||||
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
 | 
			
		||||
import com.massivecraft.massivecore.mson.Mson;
 | 
			
		||||
import com.massivecraft.massivecore.util.Txt;
 | 
			
		||||
 | 
			
		||||
public abstract class CmdFactionsRelationAbstract extends FactionsCommand
 | 
			
		||||
public class CmdFactionsRelationSet extends FactionsCommand
 | 
			
		||||
{
 | 
			
		||||
	public Rel targetRelation;
 | 
			
		||||
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// CONSTRUCT
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	
 | 
			
		||||
	public CmdFactionsRelationAbstract()
 | 
			
		||||
	public CmdFactionsRelationSet()
 | 
			
		||||
	{
 | 
			
		||||
		// Aliases
 | 
			
		||||
		this.addAliases("set");
 | 
			
		||||
 | 
			
		||||
		// Parameter
 | 
			
		||||
		this.addParameter(TypeFaction.get(), "faction");
 | 
			
		||||
		this.addParameter(TypeRelation.get(), "relation");
 | 
			
		||||
 | 
			
		||||
		// Requirements
 | 
			
		||||
		this.addRequirements(RequirementHasPerm.get(Perm.RELATION.node));
 | 
			
		||||
		this.addRequirements(RequirementHasPerm.get(Perm.RELATION_SET.node));
 | 
			
		||||
		this.addRequirements(ReqHasFaction.get());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -41,30 +47,19 @@ public abstract class CmdFactionsRelationAbstract extends FactionsCommand
 | 
			
		||||
	{
 | 
			
		||||
		// Args
 | 
			
		||||
		Faction otherFaction = this.readArg();
 | 
			
		||||
		
 | 
			
		||||
		Rel newRelation = targetRelation;
 | 
			
		||||
		
 | 
			
		||||
		/*if ( ! them.isNormal())
 | 
			
		||||
		{
 | 
			
		||||
			msg("<b>Nope! You can't.");
 | 
			
		||||
			return;
 | 
			
		||||
		}*/
 | 
			
		||||
		Rel newRelation = this.readArg();
 | 
			
		||||
		
 | 
			
		||||
		// MPerm
 | 
			
		||||
		if ( ! MPerm.getPermRel().has(msender, msenderFaction, true)) return;
 | 
			
		||||
		
 | 
			
		||||
		// Verify
 | 
			
		||||
		
 | 
			
		||||
		if (otherFaction == msenderFaction)
 | 
			
		||||
		{
 | 
			
		||||
			msg("<b>Nope! You can't declare a relation to yourself :)");
 | 
			
		||||
			return;
 | 
			
		||||
			throw new MassiveException().setMsg("<b>Nope! You can't declare a relation to yourself :)");
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (msenderFaction.getRelationWish(otherFaction) == newRelation)
 | 
			
		||||
		{
 | 
			
		||||
			msg("<b>You already have that relation wish set with %s.", otherFaction.getName());
 | 
			
		||||
			return;
 | 
			
		||||
			throw new MassiveException().setMsg("<b>You already have that relation wish set with %s.", otherFaction.getName());
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		// Event
 | 
			
		||||
@@ -86,34 +81,29 @@ public abstract class CmdFactionsRelationAbstract extends FactionsCommand
 | 
			
		||||
		// inform the other faction of your request
 | 
			
		||||
		else
 | 
			
		||||
		{
 | 
			
		||||
			MassiveCommand relationshipCommand = null;
 | 
			
		||||
			if (newRelation.equals(Rel.NEUTRAL)) relationshipCommand = CmdFactions.get().cmdFactionsRelationNeutral;
 | 
			
		||||
			else if (newRelation.equals(Rel.TRUCE)) relationshipCommand = CmdFactions.get().cmdFactionsRelationTruce;
 | 
			
		||||
			else if (newRelation.equals(Rel.ALLY)) relationshipCommand = CmdFactions.get().cmdFactionsRelationAlly;
 | 
			
		||||
			else if (newRelation.equals(Rel.ENEMY)) relationshipCommand = CmdFactions.get().cmdFactionsRelationEnemy;
 | 
			
		||||
			
 | 
			
		||||
			String command = relationshipCommand.getCommandLine(msenderFaction.getName());
 | 
			
		||||
			String tooltip = Txt.parse("<g>Click to <c>%s<i>.", command);
 | 
			
		||||
			
 | 
			
		||||
			MassiveCommand command = CmdFactions.get().cmdFactionsRelation.cmdFactionsRelationSet;
 | 
			
		||||
			String colorOne = newRelation.getColor() + newRelation.getDescFactionOne();
 | 
			
		||||
 | 
			
		||||
			// Mson creation
 | 
			
		||||
			Mson factionsRelationshipChange = mson(
 | 
			
		||||
				Mson.parse("%s<i> wishes to be %s. ", msenderFaction.describeTo(otherFaction, true), newRelation.getColor()+newRelation.getDescFactionOne()),
 | 
			
		||||
				mson(tooltip).tooltipParse(tooltip).command(command)
 | 
			
		||||
				Mson.parse("%s<i> wishes to be %s.", msenderFaction.describeTo(otherFaction, true), colorOne),
 | 
			
		||||
				Mson.SPACE,
 | 
			
		||||
				mson("[Accept]").color(ChatColor.AQUA).command(command, msenderFaction.getName(), newRelation.name())
 | 
			
		||||
			);
 | 
			
		||||
			
 | 
			
		||||
			otherFaction.sendMessage(factionsRelationshipChange);
 | 
			
		||||
			msenderFaction.msg("%s<i> were informed that you wish to be %s<i>.", otherFaction.describeTo(msenderFaction, true), newRelation.getColor()+newRelation.getDescFactionOne());
 | 
			
		||||
			msenderFaction.msg("%s<i> were informed that you wish to be %s<i>.", otherFaction.describeTo(msenderFaction, true), colorOne);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		// TODO: The ally case should work!!
 | 
			
		||||
		//   * this might have to be bumped up to make that happen, & allow ALLY,NEUTRAL only
 | 
			
		||||
		if ( newRelation != Rel.TRUCE && otherFaction.getFlag(MFlag.getFlagPeaceful()))
 | 
			
		||||
		if (newRelation != Rel.TRUCE && otherFaction.getFlag(MFlag.getFlagPeaceful()))
 | 
			
		||||
		{
 | 
			
		||||
			otherFaction.msg("<i>This will have no effect while your faction is peaceful.");
 | 
			
		||||
			msenderFaction.msg("<i>This will have no effect while their faction is peaceful.");
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		if ( newRelation != Rel.TRUCE && msenderFaction.getFlag(MFlag.getFlagPeaceful()))
 | 
			
		||||
		if (newRelation != Rel.TRUCE && msenderFaction.getFlag(MFlag.getFlagPeaceful()))
 | 
			
		||||
		{
 | 
			
		||||
			otherFaction.msg("<i>This will have no effect while their faction is peaceful.");
 | 
			
		||||
			msenderFaction.msg("<i>This will have no effect while your faction is peaceful.");
 | 
			
		||||
@@ -1,20 +0,0 @@
 | 
			
		||||
package com.massivecraft.factions.cmd;
 | 
			
		||||
 | 
			
		||||
import com.massivecraft.factions.Rel;
 | 
			
		||||
 | 
			
		||||
public class CmdFactionsRelationTruce extends CmdFactionsRelationAbstract
 | 
			
		||||
{
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// CONSTRUCT
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	
 | 
			
		||||
	public CmdFactionsRelationTruce()
 | 
			
		||||
	{
 | 
			
		||||
		// Aliases
 | 
			
		||||
		this.addAliases("truce");
 | 
			
		||||
		
 | 
			
		||||
		// Misc
 | 
			
		||||
		this.targetRelation = Rel.TRUCE;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,96 @@
 | 
			
		||||
package com.massivecraft.factions.cmd;
 | 
			
		||||
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.Map.Entry;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
 | 
			
		||||
import com.massivecraft.factions.Factions;
 | 
			
		||||
import com.massivecraft.factions.Perm;
 | 
			
		||||
import com.massivecraft.factions.Rel;
 | 
			
		||||
import com.massivecraft.factions.cmd.req.ReqHasFaction;
 | 
			
		||||
import com.massivecraft.factions.cmd.type.TypeFaction;
 | 
			
		||||
import com.massivecraft.factions.entity.Faction;
 | 
			
		||||
import com.massivecraft.factions.entity.FactionColl;
 | 
			
		||||
 | 
			
		||||
import com.massivecraft.massivecore.MassiveException;
 | 
			
		||||
import com.massivecraft.massivecore.collections.MassiveMap;
 | 
			
		||||
import com.massivecraft.massivecore.command.Parameter;
 | 
			
		||||
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
 | 
			
		||||
import com.massivecraft.massivecore.pager.Pager;
 | 
			
		||||
import com.massivecraft.massivecore.pager.Stringifier;
 | 
			
		||||
import com.massivecraft.massivecore.util.MUtil;
 | 
			
		||||
import com.massivecraft.massivecore.util.Txt;
 | 
			
		||||
 | 
			
		||||
public class CmdFactionsRelationWishes extends FactionsCommand
 | 
			
		||||
{
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// CONSTRUCT
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
 | 
			
		||||
	public CmdFactionsRelationWishes()
 | 
			
		||||
	{
 | 
			
		||||
		// Aliases
 | 
			
		||||
		this.addAliases("wishes");
 | 
			
		||||
 | 
			
		||||
		// Parameter
 | 
			
		||||
		this.addParameter(Parameter.getPage());
 | 
			
		||||
		this.addParameter(TypeFaction.get(), "faction", "you");
 | 
			
		||||
 | 
			
		||||
		// Requirements
 | 
			
		||||
		this.addRequirements(RequirementHasPerm.get(Perm.RELATION_LIST.node));
 | 
			
		||||
		this.addRequirements(ReqHasFaction.get());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// OVERRIDE
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public void perform() throws MassiveException
 | 
			
		||||
	{
 | 
			
		||||
		// Args
 | 
			
		||||
		int page = this.readArg();
 | 
			
		||||
		final Faction faction = this.readArg(msenderFaction);
 | 
			
		||||
 | 
			
		||||
		// Pager Create
 | 
			
		||||
		final Pager<Entry<Faction, Rel>> pager = new Pager<>(this, "", page, new Stringifier<Entry<Faction, Rel>>()
 | 
			
		||||
		{
 | 
			
		||||
			@Override
 | 
			
		||||
			public String toString(Entry<Faction, Rel> item, int index)
 | 
			
		||||
			{
 | 
			
		||||
				Rel rel = item.getValue();
 | 
			
		||||
				Faction fac = item.getKey();
 | 
			
		||||
				return rel.getColor().toString() + rel.getName() + CmdFactionsRelationList.SEPERATOR + fac.describeTo(faction, true);
 | 
			
		||||
			}
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), new Runnable()
 | 
			
		||||
		{
 | 
			
		||||
			@Override
 | 
			
		||||
			public void run()
 | 
			
		||||
			{
 | 
			
		||||
				Map<Faction, Rel> realWishes = new MassiveMap<>();
 | 
			
		||||
 | 
			
		||||
				for (Entry<String, Rel> entry : faction.getRelationWishes().entrySet())
 | 
			
		||||
				{
 | 
			
		||||
					Rel rel = entry.getValue();
 | 
			
		||||
					Faction fac = FactionColl.get().getFixed(entry.getKey());
 | 
			
		||||
 | 
			
		||||
					// A wish is not a wish anymore if both factions have atleast equal "wishes"
 | 
			
		||||
					if (fac.getRelationTo(faction).isAtLeast(rel)) continue;
 | 
			
		||||
					realWishes.put(fac, rel);
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				// Pager Title
 | 
			
		||||
				pager.setTitle(Txt.parse("<white>%s's <green>Relation wishes <a>(%d)", faction.getName(), realWishes.size()));
 | 
			
		||||
 | 
			
		||||
				// Pager Items
 | 
			
		||||
				pager.setItems(MUtil.entriesSortedByValues(realWishes));
 | 
			
		||||
 | 
			
		||||
				// Pager Message
 | 
			
		||||
				pager.message();
 | 
			
		||||
			}
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										25
									
								
								src/com/massivecraft/factions/cmd/type/TypeRelation.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								src/com/massivecraft/factions/cmd/type/TypeRelation.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,25 @@
 | 
			
		||||
package com.massivecraft.factions.cmd.type;
 | 
			
		||||
 | 
			
		||||
import com.massivecraft.factions.Rel;
 | 
			
		||||
 | 
			
		||||
public class TypeRelation extends TypeRel
 | 
			
		||||
{
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// INSTANCE & CONSTRUCT
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
 | 
			
		||||
	private static TypeRelation i = new TypeRelation();
 | 
			
		||||
	public static TypeRelation get() { return i; }
 | 
			
		||||
	public TypeRelation() { this.setAll(Rel.NEUTRAL, Rel.TRUCE, Rel.ALLY, Rel.ENEMY); }
 | 
			
		||||
	
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// OVERRIDE
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public String getTypeName()
 | 
			
		||||
	{
 | 
			
		||||
		return "relation";
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user