Factions3/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPlayer.java

83 lines
2.8 KiB
Java
Raw Normal View History

package com.massivecraft.factions.cmd;
2013-04-26 17:54:06 +02:00
import java.util.LinkedHashMap;
import com.massivecraft.factions.Perm;
2014-09-17 13:29:58 +02:00
import com.massivecraft.factions.cmd.arg.ARMPlayer;
import com.massivecraft.factions.entity.MPlayer;
2014-06-04 14:02:23 +02:00
import com.massivecraft.massivecore.Progressbar;
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
import com.massivecraft.massivecore.util.TimeDiffUtil;
import com.massivecraft.massivecore.util.TimeUnit;
import com.massivecraft.massivecore.util.Txt;
public class CmdFactionsPlayer extends FCommand
{
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsPlayer()
{
2013-11-11 09:31:04 +01:00
// Aliases
this.addAliases("p", "player");
2013-11-11 09:31:04 +01:00
// Args
this.addOptionalArg("player", "you");
2013-11-11 09:31:04 +01:00
// Requirements
this.addRequirements(ReqHasPerm.get(Perm.PLAYER.node));
}
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void perform()
{
// Args
2014-09-17 13:29:58 +02:00
MPlayer mplayer = this.arg(0, ARMPlayer.getAny(), usender);
if (mplayer == null) return;
2013-04-26 17:54:06 +02:00
// INFO: Title
msg(Txt.titleize("Player " + mplayer.describeTo(usender)));
2013-04-26 17:54:06 +02:00
// INFO: Power (as progress bar)
2014-09-17 13:29:58 +02:00
double progressbarQuota = mplayer.getPower() / mplayer.getPowerMax();
int progressbarWidth = (int) Math.round(mplayer.getPowerMax() / mplayer.getPowerMaxUniversal() * 100);
2013-04-26 17:54:06 +02:00
msg("<k>Power: <v>%s", Progressbar.HEALTHBAR_CLASSIC.withQuota(progressbarQuota).withWidth(progressbarWidth).render());
// INFO: Power (as digits)
2014-09-17 13:29:58 +02:00
msg("<k>Power: <v>%.2f / %.2f", mplayer.getPower(), mplayer.getPowerMax());
2013-04-26 17:54:06 +02:00
// INFO: Power Boost
2014-09-17 13:29:58 +02:00
if (mplayer.hasPowerBoost())
2013-04-26 17:54:06 +02:00
{
2014-09-17 13:29:58 +02:00
double powerBoost = mplayer.getPowerBoost();
2013-04-26 17:54:06 +02:00
String powerBoostType = (powerBoost > 0 ? "bonus" : "penalty");
msg("<k>Power Boost: <v>%f <i>(a manually granted %s)", powerBoost, powerBoostType);
}
// INFO: Power per Hour
// If the player is not at maximum we wan't to display how much time left.
String stringTillMax = "";
2014-09-17 13:29:58 +02:00
double powerTillMax = mplayer.getPowerMax() - mplayer.getPower();
2013-04-26 17:54:06 +02:00
if (powerTillMax > 0)
{
2014-09-17 13:29:58 +02:00
long millisTillMax = (long) (powerTillMax * TimeUnit.MILLIS_PER_HOUR / mplayer.getPowerPerHour());
2013-04-26 17:54:06 +02:00
LinkedHashMap<TimeUnit, Long> unitcountsTillMax = TimeDiffUtil.unitcounts(millisTillMax, TimeUnit.getAllButMillis());
unitcountsTillMax = TimeDiffUtil.limit(unitcountsTillMax, 2);
String unitcountsTillMaxFormated = TimeDiffUtil.formatedVerboose(unitcountsTillMax, "<i>");
stringTillMax = Txt.parse(" <i>(%s <i>left till max)", unitcountsTillMaxFormated);
}
2014-09-17 13:29:58 +02:00
msg("<k>Power per Hour: <v>%.2f%s", mplayer.getPowerPerHour(), stringTillMax);
2013-04-26 17:54:06 +02:00
// INFO: Power per Death
2014-09-17 13:29:58 +02:00
msg("<k>Power per Death: <v>%.2f", mplayer.getPowerPerDeath());
}
2013-11-11 09:31:04 +01:00
}