Use Pager to list faction perms
This commit is contained in:
parent
19a1d7fab4
commit
31823f5311
@ -1,15 +1,32 @@
|
|||||||
package com.massivecraft.factions.cmd;
|
package com.massivecraft.factions.cmd;
|
||||||
|
|
||||||
|
import com.massivecraft.factions.Factions;
|
||||||
import com.massivecraft.factions.entity.MPerm;
|
import com.massivecraft.factions.entity.MPerm;
|
||||||
|
import com.massivecraft.factions.entity.MPermColl;
|
||||||
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;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CmdFactionsPermList extends FactionsCommand
|
public class CmdFactionsPermList extends FactionsCommand
|
||||||
{
|
{
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// REUSABLE PREDICATE
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
private static final Predicate<MPerm> PREDICATE_MPERM_VISIBLE = new Predicate<MPerm>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public boolean apply(MPerm mperm)
|
||||||
|
{
|
||||||
|
return mperm.isVisible();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
// CONSTRUCT
|
// CONSTRUCT
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
@ -27,20 +44,37 @@ public class CmdFactionsPermList extends FactionsCommand
|
|||||||
@Override
|
@Override
|
||||||
public void perform() throws MassiveException
|
public void perform() throws MassiveException
|
||||||
{
|
{
|
||||||
// Args
|
// Parameter
|
||||||
int page = this.readArg();
|
int page = this.readArg();
|
||||||
|
|
||||||
// Create messages
|
// Pager create
|
||||||
List<String> messages = new ArrayList<>();
|
String title = String.format("Perms for %s", msenderFaction.describeTo(msender));
|
||||||
|
final Pager<MPerm> pager = new Pager<>(this, title, page, new Stringifier<MPerm>()
|
||||||
for (MPerm perm : MPerm.getAll())
|
|
||||||
{
|
{
|
||||||
if ( ! perm.isVisible() && ! msender.isOverriding()) continue;
|
@Override
|
||||||
messages.add(perm.getDesc(true, true));
|
public String toString(MPerm mperm, int index)
|
||||||
|
{
|
||||||
|
return mperm.getDesc(true, true);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Send messages
|
final Predicate<MPerm> predicate = msender.isOverriding() ? null : PREDICATE_MPERM_VISIBLE;
|
||||||
message(Txt.getPage(messages, page, "Available Faction Perms", this));
|
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), new Runnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
// Get items
|
||||||
|
List<MPerm> items = MPermColl.get().getAll(predicate);
|
||||||
|
|
||||||
|
// Pager items
|
||||||
|
pager.setItems(items);
|
||||||
|
|
||||||
|
// Pager message
|
||||||
|
pager.message();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user