package com.massivecraft.factions.cmd; import java.util.Collections; import java.util.Comparator; import java.util.LinkedHashMap; import java.util.List; import com.massivecraft.factions.Perm; import com.massivecraft.factions.PlayerInactivityComparator; import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.cmd.arg.ARSortMPlayer; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.MPerm; import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.massivecore.cmd.MassiveCommandException; import com.massivecraft.massivecore.cmd.arg.ARInteger; import com.massivecraft.massivecore.cmd.req.ReqHasPerm; import com.massivecraft.massivecore.pager.PagerSimple; import com.massivecraft.massivecore.pager.Stringifier; import com.massivecraft.massivecore.util.TimeDiffUtil; import com.massivecraft.massivecore.util.TimeUnit; import com.massivecraft.massivecore.util.Txt; public class CmdFactionsStatus extends FactionsCommand { // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // public CmdFactionsStatus() { // Aliases this.addAliases("s", "status"); // Args this.addOptionalArg("page", "1"); this.addOptionalArg("faction", "you"); this.addOptionalArg("sort by", "time"); // Requirements this.addRequirements(ReqHasPerm.get(Perm.STATUS.node)); } // -------------------------------------------- // // OVERRIDE // -------------------------------------------- // @Override public void perform() throws MassiveCommandException { // Args Integer pageHumanBased = this.arg(0, ARInteger.get(), 1); Faction faction = this.arg(1, ARFaction.get(), msenderFaction); Comparator sortedBy = this.arg(2, ARSortMPlayer.get(), PlayerInactivityComparator.get()); // MPerm if ( ! MPerm.getPermStatus().has(msender, faction, true)) return; // Sort list 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(pageHumanBased, pagerTitle, new Stringifier(){ @Override public String toString(MPlayer mplayer) { // Name String displayName = mplayer.getNameAndSomething(msender.getColorTo(mplayer).toString(), ""); int length = 15 - displayName.length(); length = length <= 0 ? 1 : length; String whiteSpace = Txt.repeat(" ", length); // Power double currentPower = mplayer.getPower(); double maxPower = mplayer.getPowerMax(); String color; double percent = currentPower / maxPower; if (percent > 0.75) { color = ""; } else if (percent > 0.5) { color = ""; } else if (percent > 0.25) { color = ""; } else { color = ""; } String power = Txt.parse("Power: %s%.0f/%.0f", Txt.parse(color), currentPower, maxPower); // Time long lastActiveMillis = mplayer.getLastActivityMillis() - System.currentTimeMillis(); LinkedHashMap activeTimes = TimeDiffUtil.limit(TimeDiffUtil.unitcounts(lastActiveMillis, TimeUnit.getAllButMillis()), 3); String lastActive = mplayer.isOnline() ? Txt.parse("Online right now.") : Txt.parse("Last active: " + TimeDiffUtil.formatedMinimal(activeTimes, "")); return Txt.parse("%s%s %s %s", displayName, whiteSpace, power, lastActive); } }); // Send message sendMessage(messages); } }