Change Flag show and list commands.

This commit is contained in:
ulumulu1510 2017-03-17 10:09:57 +01:00
parent ad6dc57fa8
commit 91fc5a2404
3 changed files with 109 additions and 82 deletions

View File

@ -1,12 +1,17 @@
package com.massivecraft.factions.cmd;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.entity.MFlag;
import com.massivecraft.factions.entity.MFlagColl;
import com.massivecraft.massivecore.MassiveException;
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
{
@ -27,20 +32,42 @@ public class CmdFactionsFlagList extends FactionsCommand
@Override
public void perform() throws MassiveException
{
// Args
int page = this.readArg();
// Parameter
final int page = this.readArg();
//Create messages
List<String> messages = new ArrayList<String>();
for (MFlag flag : MFlag.getAll())
// Pager create
String title = "Flag List for " + msenderFaction.describeTo(msender);
final Pager<MFlag> pager = new Pager<>(this, title, page, new Stringifier<MFlag>()
{
if ( ! flag.isVisible() && ! msender.isOverriding()) continue;
messages.add(flag.getStateDesc(false, false, true, true, true, false));
}
@Override
public String toString(MFlag mflag, int index)
{
return mflag.getStateDesc(false, false, true, true, true, false);
}
});
//Send messages
message(Txt.getPage(messages, page, "Available Faction Flags", this));
Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), new Runnable()
{
@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();
}
});
}
}

View File

@ -1,16 +1,15 @@
package com.massivecraft.factions.cmd;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
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.MFlag;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.command.type.container.TypeSet;
import com.massivecraft.massivecore.util.Txt;
import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.command.Parameter;
import com.massivecraft.massivecore.pager.Pager;
import com.massivecraft.massivecore.pager.Stringifier;
public class CmdFactionsFlagShow extends FactionsCommand
{
@ -22,7 +21,7 @@ public class CmdFactionsFlagShow extends FactionsCommand
{
// Parameters
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
public void perform() throws MassiveException
{
// Arg: Faction
Faction faction = this.readArg(msenderFaction);
Collection<MFlag> mflags = this.readArg(MFlag.getAll());
// Parameters
final Faction faction = this.readArg(msenderFaction);
int page = this.readArg();
// Create messages
List<Object> messages = new ArrayList<>();
messages.add(Txt.titleize("Flag for " + faction.describeTo(msender, true)));
for (MFlag mflag : mflags)
// Pager create
String title = "Flags for " + faction.describeTo(msender);
Pager<MFlag> pager = new Pager<>(this, title, page, MFlag.getAll(), new Stringifier<MFlag>()
{
messages.add(mflag.getStateDesc(faction.getFlag(mflag), true, true, true, true, true));
}
// Send messages
message(messages);
@Override
public String toString(MFlag mflag, int index)
{
return mflag.getStateDesc(faction.getFlag(mflag), true, true, true, true, true);
}
});
// Pager args
List<String> pagerArgs = new MassiveList<>(
faction.getId(),
String.valueOf(page)
);
pager.setArgs(pagerArgs);
// Pager message
pager.messageAsync();
}
}

View File

@ -2,6 +2,8 @@ package com.massivecraft.factions.entity;
import java.util.List;
import org.bukkit.ChatColor;
import com.massivecraft.factions.event.EventFactionsCreateFlags;
import com.massivecraft.massivecore.Named;
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)
{
List<String> parts = new MassiveList<String>();
// Create
List<String> ret = new MassiveList<>();
if (withValue)
{
if (monospaceValue)
{
parts.add(Txt.parse(value ? "<g>YES" : "<b>NOO"));
}
else
{
parts.add(Txt.parse(value ? "<g>YES" : "<b>NO"));
}
}
// Fill
if (withValue) ret.add(getStateValue(value, monospaceValue));
if (withName) ret.add(this.getStateName());
if (withDesc) ret.add(this.getStateDescription(value, specificDesc));
if (withName)
{
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, " ");
// Return
return Txt.implode(ret, " ");
}
@Deprecated
public String getStateInfo(boolean value, boolean withDesc)
private static String getStateValue(boolean value, boolean monoSpace)
{
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);
}
}