From 658905c4e8af9e9b041ac782524b60171dc5996d Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Sat, 5 Sep 2015 13:44:24 +0200 Subject: [PATCH] MassiveCore - Pager Improvement --- .../factions/cmd/CmdFactionsFlagList.java | 2 +- .../factions/cmd/CmdFactionsInviteList.java | 15 ++--- .../factions/cmd/CmdFactionsList.java | 62 +++++++++---------- .../factions/cmd/CmdFactionsPermList.java | 2 +- .../factions/cmd/CmdFactionsStatus.java | 19 +++--- 5 files changed, 47 insertions(+), 53 deletions(-) diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsFlagList.java b/src/com/massivecraft/factions/cmd/CmdFactionsFlagList.java index b2cb019b..b5e1d278 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsFlagList.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsFlagList.java @@ -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)); } } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsInviteList.java b/src/com/massivecraft/factions/cmd/CmdFactionsInviteList.java index 723c73ba..785ae2ff 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsInviteList.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsInviteList.java @@ -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 mplayers = faction.getInvitedMPlayers(); - final PagerSimple pager = new PagerSimple(mplayers, sender); - - // Use Pager - List messages = pager.getPageTxt(page, "Invited Players List", new Stringifier(){ - + final Pager pager = new Pager(this, "Invited Players List", page, mplayers, new Stringifier(){ 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(); } } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsList.java b/src/com/massivecraft/factions/cmd/CmdFactionsList.java index 6255fdcd..2b26643e 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsList.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsList.java @@ -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 pager = new Pager(this, "Faction List", page, new Stringifier() { + @Override + public String toString(Faction faction, int index) + { + if (faction.isNone()) + { + return Txt.parse("Factionless %d online", FactionColl.get().getNone().getMPlayersWhereOnline(true).size()); + } + else + { + return Txt.parse("%s %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 factions = FactionColl.get().getAll(FactionListComparator.get()); - final PagerSimple pager = new PagerSimple(factions, sender); + pager.setItems(factions); - // Use Pager - List messages = pager.getPageTxt(page, "Faction List", new Stringifier() { - @Override - public String toString(Faction faction, int index) - { - if (faction.isNone()) - { - return Txt.parse("Factionless %d online", FactionColl.get().getNone().getMPlayersWhereOnline(true).size()); - } - else - { - return Txt.parse("%s %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(); } }); } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPermList.java b/src/com/massivecraft/factions/cmd/CmdFactionsPermList.java index 511eacb1..5c749921 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPermList.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPermList.java @@ -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)); } } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsStatus.java b/src/com/massivecraft/factions/cmd/CmdFactionsStatus.java index 9e208c3f..e5dcda21 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsStatus.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsStatus.java @@ -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 mplayers = faction.getMPlayers(); Collections.sort(mplayers, sortedBy); - // Create Pager - final PagerSimple pager = new PagerSimple(mplayers, sender); - String pagerTitle = Txt.parse("Status of %s.", faction.describeTo(msender, true)); - - // Use Pager - List messages = pager.getPageTxt(page, pagerTitle, new Stringifier(){ - + // Pager Create + String title = Txt.parse("Status of %s.", faction.describeTo(msender, true)); + final Pager pager = new Pager(this, title, page, mplayers, new Stringifier(){ @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(); } }