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
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.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();
}
}

View File

@ -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,22 +44,13 @@ 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;
Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), new Runnable()
{
@Override
public void run()
{
// Create Pager
final List<Faction> factions = FactionColl.get().getAll(FactionListComparator.get());
final PagerSimple<Faction> pager = new PagerSimple<Faction>(factions, sender);
// Use Pager
List<String> messages = pager.getPageTxt(page, "Faction List", new Stringifier<Faction>() {
// Pager Create
final Pager<Faction> pager = new Pager<Faction>(this, "Faction List", page, new Stringifier<Faction>() {
@Override
public String toString(Faction faction, int index)
{
@ -81,8 +72,17 @@ public class CmdFactionsList extends FactionsCommand
}
});
// Send Messages
Mixin.messageOne(sender, messages);
Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), new Runnable()
{
@Override
public void run()
{
// Pager Items
final List<Faction> factions = FactionColl.get().getAll(FactionListComparator.get());
pager.setItems(factions);
// Pager Message
pager.message();
}
});
}

View File

@ -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));
}
}

View File

@ -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();
}
}