package com.massivecraft.factions.cmd; import java.util.LinkedHashMap; import com.massivecraft.factions.Perm; import com.massivecraft.factions.cmd.arg.ARMPlayer; import com.massivecraft.factions.entity.MPlayer; 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 FactionsCommand { // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // public CmdFactionsPlayer() { // Aliases this.addAliases("p", "player"); // Args this.addOptionalArg("player", "you"); // Requirements this.addRequirements(ReqHasPerm.get(Perm.PLAYER.node)); } // -------------------------------------------- // // OVERRIDE // -------------------------------------------- // @Override public void perform() { // Args MPlayer mplayer = this.arg(0, ARMPlayer.getAny(), msender); if (mplayer == null) return; // INFO: Title msg(Txt.titleize("Player " + mplayer.describeTo(msender))); // INFO: Power (as progress bar) double progressbarQuota = 0; double playerPowerMax = mplayer.getPowerMax(); if (playerPowerMax != 0) { progressbarQuota = mplayer.getPower() / playerPowerMax; } int progressbarWidth = (int) Math.round(mplayer.getPowerMax() / mplayer.getPowerMaxUniversal() * 100); msg("Power: %s", Progressbar.HEALTHBAR_CLASSIC.withQuota(progressbarQuota).withWidth(progressbarWidth).render()); // INFO: Power (as digits) msg("Power: %.2f / %.2f", mplayer.getPower(), mplayer.getPowerMax()); // INFO: Power Boost if (mplayer.hasPowerBoost()) { double powerBoost = mplayer.getPowerBoost(); String powerBoostType = (powerBoost > 0 ? "bonus" : "penalty"); msg("Power Boost: %f (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 = ""; double powerTillMax = mplayer.getPowerMax() - mplayer.getPower(); if (powerTillMax > 0) { long millisTillMax = (long) (powerTillMax * TimeUnit.MILLIS_PER_HOUR / mplayer.getPowerPerHour()); LinkedHashMap unitcountsTillMax = TimeDiffUtil.unitcounts(millisTillMax, TimeUnit.getAllButMillis()); unitcountsTillMax = TimeDiffUtil.limit(unitcountsTillMax, 2); String unitcountsTillMaxFormated = TimeDiffUtil.formatedVerboose(unitcountsTillMax, ""); stringTillMax = Txt.parse(" (%s left till max)", unitcountsTillMaxFormated); } msg("Power per Hour: %.2f%s", mplayer.getPowerPerHour(), stringTillMax); // INFO: Power per Death msg("Power per Death: %.2f", mplayer.getPowerPerDeath()); } }