MassiveCore - Pager Improvement

This commit is contained in:
Olof Larsson 2015-09-05 13:44:24 +02:00
parent 841a2da73d
commit 658905c4e8
5 changed files with 47 additions and 53 deletions

View File

@ -48,7 +48,7 @@ public class CmdFactionsFlagList extends FactionsCommand
} }
//Send messages //Send messages
message(Txt.getPage(messages, page, "Available Faction Flags", sender)); message(Txt.getPage(messages, page, "Available Faction Flags", this));
} }
} }

View File

@ -11,7 +11,8 @@ import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.cmd.ArgSetting; import com.massivecraft.massivecore.cmd.ArgSetting;
import com.massivecraft.massivecore.cmd.req.ReqHasPerm; 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.pager.Stringifier;
import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.util.Txt;
@ -51,13 +52,9 @@ public class CmdFactionsInviteList extends FactionsCommand
// MPerm // MPerm
if ( ! MPerm.getPermInvite().has(msender, msenderFaction, true)) return; if ( ! MPerm.getPermInvite().has(msender, msenderFaction, true)) return;
// Create Pager // Pager Create
final List<MPlayer> mplayers = faction.getInvitedMPlayers(); final List<MPlayer> mplayers = faction.getInvitedMPlayers();
final PagerSimple<MPlayer> pager = new PagerSimple<MPlayer>(mplayers, sender); final Pager<MPlayer> pager = new Pager<MPlayer>(this, "Invited Players List", page, mplayers, new Stringifier<MPlayer>(){
// Use Pager
List<String> messages = pager.getPageTxt(page, "Invited Players List", new Stringifier<MPlayer>(){
public String toString(MPlayer target, int index) public String toString(MPlayer target, int index)
{ {
// TODO: Madus would like to implement this in MPlayer // TODO: Madus would like to implement this in MPlayer
@ -77,8 +74,8 @@ public class CmdFactionsInviteList extends FactionsCommand
} }
}); });
// Send message // Pager Message
message(messages); pager.message();
} }
} }

View File

@ -3,7 +3,6 @@ package com.massivecraft.factions.cmd;
import java.util.List; import java.util.List;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import com.massivecraft.factions.FactionListComparator; import com.massivecraft.factions.FactionListComparator;
import com.massivecraft.factions.Factions; 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.ArgSetting;
import com.massivecraft.massivecore.cmd.req.ReqHasPerm; import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
import com.massivecraft.massivecore.mixin.Mixin; 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.pager.Stringifier;
import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.util.Txt;
@ -44,45 +44,45 @@ public class CmdFactionsList extends FactionsCommand
public void perform() throws MassiveException public void perform() throws MassiveException
{ {
// Args // Args
final int page = this.readArg(); int page = this.readArg();
// NOTE: The faction list is quite slow and mostly thread safe. // NOTE: The faction list is quite slow and mostly thread safe.
// We run it asynchronously to spare the primary server thread. // 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() Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), new Runnable()
{ {
@Override @Override
public void run() public void run()
{ {
// Create Pager // Pager Items
final List<Faction> factions = FactionColl.get().getAll(FactionListComparator.get()); final List<Faction> factions = FactionColl.get().getAll(FactionListComparator.get());
final PagerSimple<Faction> pager = new PagerSimple<Faction>(factions, sender); pager.setItems(factions);
// Use Pager // Pager Message
List<String> messages = pager.getPageTxt(page, "Faction List", new Stringifier<Faction>() { pager.message();
@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);
} }
}); });
} }

View File

@ -48,7 +48,7 @@ public class CmdFactionsPermList extends FactionsCommand
} }
// Send messages // Send messages
message(Txt.getPage(messages, page, "Available Faction Perms", sender)); message(Txt.getPage(messages, page, "Available Faction Perms", this));
} }
} }

View File

@ -15,7 +15,8 @@ import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.cmd.ArgSetting; import com.massivecraft.massivecore.cmd.ArgSetting;
import com.massivecraft.massivecore.cmd.req.ReqHasPerm; 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.pager.Stringifier;
import com.massivecraft.massivecore.util.TimeDiffUtil; import com.massivecraft.massivecore.util.TimeDiffUtil;
import com.massivecraft.massivecore.util.TimeUnit; import com.massivecraft.massivecore.util.TimeUnit;
@ -61,13 +62,9 @@ public class CmdFactionsStatus extends FactionsCommand
final List<MPlayer> mplayers = faction.getMPlayers(); final List<MPlayer> mplayers = faction.getMPlayers();
Collections.sort(mplayers, sortedBy); Collections.sort(mplayers, sortedBy);
// Create Pager // Pager Create
final PagerSimple<MPlayer> pager = new PagerSimple<MPlayer>(mplayers, sender); String title = Txt.parse("<i>Status of %s<i>.", faction.describeTo(msender, true));
String pagerTitle = 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>(){
// Use Pager
List<String> messages = pager.getPageTxt(page, pagerTitle, new Stringifier<MPlayer>(){
@Override @Override
public String toString(MPlayer mplayer, int index) 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); return Txt.parse("%s%s %s %s", displayName, whiteSpace, power, lastActive);
} }
}); });
// Send message
message(messages); // Pager Message
pager.message();
} }
} }