MassiveCore - Pager Improvement
This commit is contained in:
parent
841a2da73d
commit
658905c4e8
@ -48,7 +48,7 @@ public class CmdFactionsFlagList extends FactionsCommand
|
||||
}
|
||||
|
||||
//Send messages
|
||||
message(Txt.getPage(messages, page, "Available Faction Flags", sender));
|
||||
message(Txt.getPage(messages, page, "Available Faction Flags", this));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,7 +11,8 @@ import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.cmd.ArgSetting;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.massivecore.pager.PagerSimple;
|
||||
import com.massivecraft.massivecore.mson.Mson;
|
||||
import com.massivecraft.massivecore.pager.Pager;
|
||||
import com.massivecraft.massivecore.pager.Stringifier;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
@ -51,13 +52,9 @@ public class CmdFactionsInviteList extends FactionsCommand
|
||||
// MPerm
|
||||
if ( ! MPerm.getPermInvite().has(msender, msenderFaction, true)) return;
|
||||
|
||||
// Create Pager
|
||||
// Pager Create
|
||||
final List<MPlayer> mplayers = faction.getInvitedMPlayers();
|
||||
final PagerSimple<MPlayer> pager = new PagerSimple<MPlayer>(mplayers, sender);
|
||||
|
||||
// Use Pager
|
||||
List<String> messages = pager.getPageTxt(page, "Invited Players List", new Stringifier<MPlayer>(){
|
||||
|
||||
final Pager<MPlayer> pager = new Pager<MPlayer>(this, "Invited Players List", page, mplayers, new Stringifier<MPlayer>(){
|
||||
public String toString(MPlayer target, int index)
|
||||
{
|
||||
// TODO: Madus would like to implement this in MPlayer
|
||||
@ -77,8 +74,8 @@ public class CmdFactionsInviteList extends FactionsCommand
|
||||
}
|
||||
});
|
||||
|
||||
// Send message
|
||||
message(messages);
|
||||
// Pager Message
|
||||
pager.message();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package com.massivecraft.factions.cmd;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.factions.FactionListComparator;
|
||||
import com.massivecraft.factions.Factions;
|
||||
@ -14,7 +13,8 @@ import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.cmd.ArgSetting;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.massivecore.mixin.Mixin;
|
||||
import com.massivecraft.massivecore.pager.PagerSimple;
|
||||
import com.massivecraft.massivecore.mson.Mson;
|
||||
import com.massivecraft.massivecore.pager.Pager;
|
||||
import com.massivecraft.massivecore.pager.Stringifier;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
@ -44,45 +44,45 @@ public class CmdFactionsList extends FactionsCommand
|
||||
public void perform() throws MassiveException
|
||||
{
|
||||
// Args
|
||||
final int page = this.readArg();
|
||||
int page = this.readArg();
|
||||
|
||||
// NOTE: The faction list is quite slow and mostly thread safe.
|
||||
// We run it asynchronously to spare the primary server thread.
|
||||
final CommandSender sender = this.sender;
|
||||
|
||||
// Pager Create
|
||||
final Pager<Faction> pager = new Pager<Faction>(this, "Faction List", page, new Stringifier<Faction>() {
|
||||
@Override
|
||||
public String toString(Faction faction, int index)
|
||||
{
|
||||
if (faction.isNone())
|
||||
{
|
||||
return Txt.parse("<i>Factionless<i> %d online", FactionColl.get().getNone().getMPlayersWhereOnline(true).size());
|
||||
}
|
||||
else
|
||||
{
|
||||
return Txt.parse("%s<i> %d/%d online, %d/%d/%d",
|
||||
faction.getName(msender),
|
||||
faction.getMPlayersWhereOnline(true).size(),
|
||||
faction.getMPlayers().size(),
|
||||
faction.getLandCount(),
|
||||
faction.getPowerRounded(),
|
||||
faction.getPowerMaxRounded()
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
// Create Pager
|
||||
// Pager Items
|
||||
final List<Faction> factions = FactionColl.get().getAll(FactionListComparator.get());
|
||||
final PagerSimple<Faction> pager = new PagerSimple<Faction>(factions, sender);
|
||||
pager.setItems(factions);
|
||||
|
||||
// Use Pager
|
||||
List<String> messages = pager.getPageTxt(page, "Faction List", new Stringifier<Faction>() {
|
||||
@Override
|
||||
public String toString(Faction faction, int index)
|
||||
{
|
||||
if (faction.isNone())
|
||||
{
|
||||
return Txt.parse("<i>Factionless<i> %d online", FactionColl.get().getNone().getMPlayersWhereOnline(true).size());
|
||||
}
|
||||
else
|
||||
{
|
||||
return Txt.parse("%s<i> %d/%d online, %d/%d/%d",
|
||||
faction.getName(msender),
|
||||
faction.getMPlayersWhereOnline(true).size(),
|
||||
faction.getMPlayers().size(),
|
||||
faction.getLandCount(),
|
||||
faction.getPowerRounded(),
|
||||
faction.getPowerMaxRounded()
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Send Messages
|
||||
Mixin.messageOne(sender, messages);
|
||||
// Pager Message
|
||||
pager.message();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ public class CmdFactionsPermList extends FactionsCommand
|
||||
}
|
||||
|
||||
// Send messages
|
||||
message(Txt.getPage(messages, page, "Available Faction Perms", sender));
|
||||
message(Txt.getPage(messages, page, "Available Faction Perms", this));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,7 +15,8 @@ import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.cmd.ArgSetting;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.massivecore.pager.PagerSimple;
|
||||
import com.massivecraft.massivecore.mson.Mson;
|
||||
import com.massivecraft.massivecore.pager.Pager;
|
||||
import com.massivecraft.massivecore.pager.Stringifier;
|
||||
import com.massivecraft.massivecore.util.TimeDiffUtil;
|
||||
import com.massivecraft.massivecore.util.TimeUnit;
|
||||
@ -61,13 +62,9 @@ public class CmdFactionsStatus extends FactionsCommand
|
||||
final List<MPlayer> mplayers = faction.getMPlayers();
|
||||
Collections.sort(mplayers, sortedBy);
|
||||
|
||||
// Create Pager
|
||||
final PagerSimple<MPlayer> pager = new PagerSimple<MPlayer>(mplayers, sender);
|
||||
String pagerTitle = Txt.parse("<i>Status of %s<i>.", faction.describeTo(msender, true));
|
||||
|
||||
// Use Pager
|
||||
List<String> messages = pager.getPageTxt(page, pagerTitle, new Stringifier<MPlayer>(){
|
||||
|
||||
// Pager Create
|
||||
String title = Txt.parse("<i>Status of %s<i>.", faction.describeTo(msender, true));
|
||||
final Pager<MPlayer> pager = new Pager<MPlayer>(this, title, page, mplayers, new Stringifier<MPlayer>(){
|
||||
@Override
|
||||
public String toString(MPlayer mplayer, int index)
|
||||
{
|
||||
@ -109,11 +106,11 @@ public class CmdFactionsStatus extends FactionsCommand
|
||||
|
||||
return Txt.parse("%s%s %s %s", displayName, whiteSpace, power, lastActive);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Send message
|
||||
message(messages);
|
||||
|
||||
// Pager Message
|
||||
pager.message();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user