Change Flag show and list commands.
This commit is contained in:
		@@ -1,12 +1,17 @@
 | 
				
			|||||||
package com.massivecraft.factions.cmd;
 | 
					package com.massivecraft.factions.cmd;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.ArrayList;
 | 
					 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.bukkit.Bukkit;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.massivecraft.factions.Factions;
 | 
				
			||||||
import com.massivecraft.factions.entity.MFlag;
 | 
					import com.massivecraft.factions.entity.MFlag;
 | 
				
			||||||
 | 
					import com.massivecraft.factions.entity.MFlagColl;
 | 
				
			||||||
import com.massivecraft.massivecore.MassiveException;
 | 
					import com.massivecraft.massivecore.MassiveException;
 | 
				
			||||||
import com.massivecraft.massivecore.command.Parameter;
 | 
					import com.massivecraft.massivecore.command.Parameter;
 | 
				
			||||||
import com.massivecraft.massivecore.util.Txt;
 | 
					import com.massivecraft.massivecore.pager.Pager;
 | 
				
			||||||
 | 
					import com.massivecraft.massivecore.pager.Stringifier;
 | 
				
			||||||
 | 
					import com.massivecraft.massivecore.predicate.Predicate;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class CmdFactionsFlagList extends FactionsCommand
 | 
					public class CmdFactionsFlagList extends FactionsCommand
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -27,20 +32,42 @@ public class CmdFactionsFlagList extends FactionsCommand
 | 
				
			|||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	public void perform() throws MassiveException
 | 
						public void perform() throws MassiveException
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		// Args
 | 
							// Parameter
 | 
				
			||||||
		int page = this.readArg();
 | 
							final int page = this.readArg();
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		//Create messages
 | 
							// Pager create
 | 
				
			||||||
		List<String> messages = new ArrayList<String>();
 | 
							String title = "Flag List for " + msenderFaction.describeTo(msender);
 | 
				
			||||||
		
 | 
							final Pager<MFlag> pager = new Pager<>(this, title, page, new Stringifier<MFlag>()
 | 
				
			||||||
		for (MFlag flag : MFlag.getAll())
 | 
					 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			if ( ! flag.isVisible() && ! msender.isOverriding()) continue;
 | 
								@Override
 | 
				
			||||||
			messages.add(flag.getStateDesc(false, false, true, true, true, false));
 | 
								public String toString(MFlag mflag, int index)
 | 
				
			||||||
		}
 | 
								{
 | 
				
			||||||
 | 
									return mflag.getStateDesc(false, false, true, true, true, false);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		//Send messages
 | 
							Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), new Runnable()
 | 
				
			||||||
		message(Txt.getPage(messages, page, "Available Faction Flags", this));
 | 
							{
 | 
				
			||||||
 | 
								@Override
 | 
				
			||||||
 | 
								public void run()
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									// Get items
 | 
				
			||||||
 | 
									List<MFlag> items = MFlagColl.get().getAll(msender.isOverriding() ? null : new Predicate<MFlag>()
 | 
				
			||||||
 | 
									{
 | 
				
			||||||
 | 
										@Override
 | 
				
			||||||
 | 
										public boolean apply(MFlag mflag)
 | 
				
			||||||
 | 
										{
 | 
				
			||||||
 | 
											return mflag.isVisible();
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									});
 | 
				
			||||||
 | 
									
 | 
				
			||||||
 | 
									// Pager items
 | 
				
			||||||
 | 
									pager.setItems(items);
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
									// Pager message
 | 
				
			||||||
 | 
									pager.message();
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,16 +1,15 @@
 | 
				
			|||||||
package com.massivecraft.factions.cmd;
 | 
					package com.massivecraft.factions.cmd;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.ArrayList;
 | 
					 | 
				
			||||||
import java.util.Collection;
 | 
					 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.massivecraft.factions.cmd.type.TypeFaction;
 | 
					import com.massivecraft.factions.cmd.type.TypeFaction;
 | 
				
			||||||
import com.massivecraft.factions.cmd.type.TypeMFlag;
 | 
					 | 
				
			||||||
import com.massivecraft.factions.entity.Faction;
 | 
					import com.massivecraft.factions.entity.Faction;
 | 
				
			||||||
import com.massivecraft.factions.entity.MFlag;
 | 
					import com.massivecraft.factions.entity.MFlag;
 | 
				
			||||||
import com.massivecraft.massivecore.MassiveException;
 | 
					import com.massivecraft.massivecore.MassiveException;
 | 
				
			||||||
import com.massivecraft.massivecore.command.type.container.TypeSet;
 | 
					import com.massivecraft.massivecore.collections.MassiveList;
 | 
				
			||||||
import com.massivecraft.massivecore.util.Txt;
 | 
					import com.massivecraft.massivecore.command.Parameter;
 | 
				
			||||||
 | 
					import com.massivecraft.massivecore.pager.Pager;
 | 
				
			||||||
 | 
					import com.massivecraft.massivecore.pager.Stringifier;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class CmdFactionsFlagShow extends FactionsCommand
 | 
					public class CmdFactionsFlagShow extends FactionsCommand
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -22,7 +21,7 @@ public class CmdFactionsFlagShow extends FactionsCommand
 | 
				
			|||||||
	{
 | 
						{
 | 
				
			||||||
		// Parameters
 | 
							// Parameters
 | 
				
			||||||
		this.addParameter(TypeFaction.get(), "faction", "you");
 | 
							this.addParameter(TypeFaction.get(), "faction", "you");
 | 
				
			||||||
		this.addParameter(TypeSet.get(TypeMFlag.get()), "flags", "all", true);
 | 
							this.addParameter(Parameter.getPage());
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	// -------------------------------------------- //
 | 
						// -------------------------------------------- //
 | 
				
			||||||
@@ -32,20 +31,30 @@ public class CmdFactionsFlagShow extends FactionsCommand
 | 
				
			|||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	public void perform() throws MassiveException
 | 
						public void perform() throws MassiveException
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		// Arg: Faction
 | 
							// Parameters
 | 
				
			||||||
		Faction faction = this.readArg(msenderFaction);
 | 
							final Faction faction = this.readArg(msenderFaction);
 | 
				
			||||||
		Collection<MFlag> mflags = this.readArg(MFlag.getAll());
 | 
							int page = this.readArg();
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		// Create messages
 | 
							// Pager create
 | 
				
			||||||
		List<Object> messages = new ArrayList<>();
 | 
							String title = "Flags for " + faction.describeTo(msender);
 | 
				
			||||||
		messages.add(Txt.titleize("Flag for " + faction.describeTo(msender, true)));
 | 
							Pager<MFlag> pager = new Pager<>(this, title, page, MFlag.getAll(), new Stringifier<MFlag>()
 | 
				
			||||||
		for (MFlag mflag : mflags)
 | 
					 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			messages.add(mflag.getStateDesc(faction.getFlag(mflag), true, true, true, true, true));
 | 
								@Override
 | 
				
			||||||
		}
 | 
								public String toString(MFlag mflag, int index)
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									return mflag.getStateDesc(faction.getFlag(mflag), true, true, true, true, true);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							});
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		// Send messages
 | 
							// Pager args
 | 
				
			||||||
		message(messages);
 | 
							List<String> pagerArgs = new MassiveList<>(
 | 
				
			||||||
 | 
								faction.getId(),
 | 
				
			||||||
 | 
								String.valueOf(page)
 | 
				
			||||||
 | 
							);
 | 
				
			||||||
 | 
							pager.setArgs(pagerArgs);
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// Pager message
 | 
				
			||||||
 | 
							pager.messageAsync();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,6 +2,8 @@ package com.massivecraft.factions.entity;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import org.bukkit.ChatColor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.massivecraft.factions.event.EventFactionsCreateFlags;
 | 
					import com.massivecraft.factions.event.EventFactionsCreateFlags;
 | 
				
			||||||
import com.massivecraft.massivecore.Named;
 | 
					import com.massivecraft.massivecore.Named;
 | 
				
			||||||
import com.massivecraft.massivecore.Prioritized;
 | 
					import com.massivecraft.massivecore.Prioritized;
 | 
				
			||||||
@@ -249,62 +251,51 @@ public class MFlag extends Entity<MFlag> implements Prioritized, Registerable, N
 | 
				
			|||||||
	
 | 
						
 | 
				
			||||||
	public String getStateDesc(boolean value, boolean withValue, boolean monospaceValue, boolean withName, boolean withDesc, boolean specificDesc)
 | 
						public String getStateDesc(boolean value, boolean withValue, boolean monospaceValue, boolean withName, boolean withDesc, boolean specificDesc)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		List<String> parts = new MassiveList<String>();
 | 
							// Create
 | 
				
			||||||
 | 
							List<String> ret = new MassiveList<>();
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		if (withValue)
 | 
							// Fill
 | 
				
			||||||
		{
 | 
							if (withValue) ret.add(getStateValue(value, monospaceValue));
 | 
				
			||||||
			if (monospaceValue)
 | 
							if (withName) ret.add(this.getStateName());
 | 
				
			||||||
			{
 | 
							if (withDesc) ret.add(this.getStateDescription(value, specificDesc));
 | 
				
			||||||
				parts.add(Txt.parse(value ? "<g>YES" : "<b>NOO"));
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			else
 | 
					 | 
				
			||||||
			{
 | 
					 | 
				
			||||||
				parts.add(Txt.parse(value ? "<g>YES" : "<b>NO"));
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		if (withName)
 | 
							// Return
 | 
				
			||||||
		{
 | 
							return Txt.implode(ret, " ");
 | 
				
			||||||
			String nameFormat;
 | 
					 | 
				
			||||||
			if ( ! this.isVisible())
 | 
					 | 
				
			||||||
			{
 | 
					 | 
				
			||||||
				nameFormat = "<silver>%s";
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			else if (this.isEditable())
 | 
					 | 
				
			||||||
			{
 | 
					 | 
				
			||||||
				nameFormat = "<pink>%s";
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			else
 | 
					 | 
				
			||||||
			{
 | 
					 | 
				
			||||||
				nameFormat = "<aqua>%s";
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			String name = this.getName();
 | 
					 | 
				
			||||||
			String nameDesc = Txt.parse(nameFormat, name);
 | 
					 | 
				
			||||||
			parts.add(nameDesc);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		if (withDesc)
 | 
					 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			String desc;
 | 
					 | 
				
			||||||
			if (specificDesc)
 | 
					 | 
				
			||||||
			{
 | 
					 | 
				
			||||||
				desc = value ? this.getDescYes() : this.getDescNo();
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			else
 | 
					 | 
				
			||||||
			{
 | 
					 | 
				
			||||||
				desc = this.getDesc();
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			String descDesc = Txt.parse("<i>%s", desc);
 | 
					 | 
				
			||||||
			parts.add(descDesc);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		return Txt.implode(parts, " ");
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	@Deprecated
 | 
						private static String getStateValue(boolean value, boolean monoSpace)
 | 
				
			||||||
	public String getStateInfo(boolean value, boolean withDesc)
 | 
					 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		return this.getStateDesc(value, true, true, true, true, false);
 | 
							String yes = "<g>YES";
 | 
				
			||||||
 | 
							String no = monoSpace ? "<b>NOO" : "<b>NO";
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							return Txt.parse(value ? yes : no);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private String getStateName()
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							return this.getStateColor().toString() + this.getName();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private ChatColor getStateColor()
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							// Is special?
 | 
				
			||||||
 | 
							if (!this.isVisible()) return ChatColor.GRAY;
 | 
				
			||||||
 | 
							if (this.isEditable()) return ChatColor.LIGHT_PURPLE;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// Return normal
 | 
				
			||||||
 | 
							return ChatColor.AQUA;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						private String getStateDescription(boolean value, boolean specific)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							// Create
 | 
				
			||||||
 | 
							String desc = this.getDesc();
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// Is specific?
 | 
				
			||||||
 | 
							if (specific) desc = value ? this.getDescYes() : this.getDescNo();
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							// Return
 | 
				
			||||||
 | 
							return Txt.parse("<i>%s", desc);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user