Factions/src/com/massivecraft/factions/cmd/CmdFactionsStatus.java

116 lines
3.6 KiB
Java
Raw Normal View History

2015-01-25 00:13:19 +01:00
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;
2015-02-12 12:00:55 +01:00
import com.massivecraft.massivecore.MassiveException;
2015-05-13 23:00:53 +02:00
import com.massivecraft.massivecore.cmd.ArgSetting;
2015-01-25 00:13:19 +01:00
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
2015-09-05 13:44:24 +02:00
import com.massivecraft.massivecore.pager.Pager;
2015-01-25 00:13:19 +01:00
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
2015-05-13 23:00:53 +02:00
this.addArg(ArgSetting.getPage());
2015-05-06 17:04:35 +02:00
this.addArg(ARFaction.get(), "faction", "you");
this.addArg(ARSortMPlayer.get(), "sort by", "time");
2015-01-25 00:13:19 +01:00
// Requirements
this.addRequirements(ReqHasPerm.get(Perm.STATUS.node));
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
2015-02-12 12:00:55 +01:00
public void perform() throws MassiveException
2015-01-25 00:13:19 +01:00
{
// Args
2015-05-13 23:00:53 +02:00
int page = this.readArg();
2015-05-06 17:04:35 +02:00
Faction faction = this.readArg(msenderFaction);
Comparator<MPlayer> sortedBy = this.readArg(PlayerInactivityComparator.get());
2015-01-25 00:13:19 +01:00
// MPerm
if ( ! MPerm.getPermStatus().has(msender, faction, true)) return;
// Sort list
final List<MPlayer> mplayers = faction.getMPlayers();
Collections.sort(mplayers, sortedBy);
2015-09-05 13:44:24 +02:00
// 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>(){
2015-01-25 00:13:19 +01:00
@Override
2015-02-17 10:40:15 +01:00
public String toString(MPlayer mplayer, int index)
2015-01-25 00:13:19 +01:00
{
// 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 = "<green>";
}
else if (percent > 0.5)
{
color = "<yellow>";
}
else if (percent > 0.25)
{
color = "<rose>";
}
else
{
color = "<red>";
}
String power = Txt.parse("<art>Power: %s%.0f<gray>/<green>%.0f", Txt.parse(color), currentPower, maxPower);
// Time
long lastActiveMillis = mplayer.getLastActivityMillis() - System.currentTimeMillis();
LinkedHashMap<TimeUnit, Long> activeTimes = TimeDiffUtil.limit(TimeDiffUtil.unitcounts(lastActiveMillis, TimeUnit.getAllButMillis()), 3);
2015-10-12 11:35:46 +02:00
String lastActive = mplayer.isOnline(msender) ? Txt.parse("<lime>Online right now.") : Txt.parse("<i>Last active: " + TimeDiffUtil.formatedMinimal(activeTimes, "<i>"));
2015-01-25 00:13:19 +01:00
return Txt.parse("%s%s %s %s", displayName, whiteSpace, power, lastActive);
}
});
2015-09-05 13:44:24 +02:00
// Pager Message
pager.message();
2015-01-25 00:13:19 +01:00
}
}