Change Flag show and list commands.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user