From 3d50e843601bb4625439f3bb6de01b35fec288a6 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Fri, 26 Apr 2013 17:54:06 +0200 Subject: [PATCH] Improvements to info commands. --- .../factions/cmd/CmdFactionsFaction.java | 4 +- .../factions/cmd/CmdFactionsPlayer.java | 52 ++++++++++++++++--- .../factions/mixin/PowerMixinDefault.java | 2 +- 3 files changed, 49 insertions(+), 9 deletions(-) diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsFaction.java b/src/com/massivecraft/factions/cmd/CmdFactionsFaction.java index 2d79c14d..3c274acc 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsFaction.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsFaction.java @@ -48,8 +48,10 @@ public class CmdFactionsFaction extends FCommand //boolean none = faction.isNone(); boolean normal = faction.isNormal(); + // INFO: Title + msg(Txt.titleize(Txt.upperCaseFirst(faction.getUniverse()) + " Faction " + faction.getName(usender))); + // INFO: Description - msg(Txt.titleize(faction.getName(usender))); msg("Description: %s", faction.getDescription()); if (normal) diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPlayer.java b/src/com/massivecraft/factions/cmd/CmdFactionsPlayer.java index ec1f99e4..821a8bd5 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPlayer.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPlayer.java @@ -1,10 +1,16 @@ package com.massivecraft.factions.cmd; +import java.util.LinkedHashMap; + import com.massivecraft.factions.Perm; import com.massivecraft.factions.cmd.arg.ARUPlayer; import com.massivecraft.factions.cmd.req.ReqFactionsEnabled; import com.massivecraft.factions.entity.UPlayer; +import com.massivecraft.mcore.Progressbar; import com.massivecraft.mcore.cmd.req.ReqHasPerm; +import com.massivecraft.mcore.util.TimeDiffUtil; +import com.massivecraft.mcore.util.TimeUnit; +import com.massivecraft.mcore.util.Txt; public class CmdFactionsPlayer extends FCommand { @@ -22,14 +28,46 @@ public class CmdFactionsPlayer extends FCommand public void perform() { // Args - UPlayer target = this.arg(0, ARUPlayer.getStartAny(sender), usender); - if (target == null) return; + UPlayer uplayer = this.arg(0, ARUPlayer.getStartAny(sender), usender); + if (uplayer == null) return; - // TODO: Print info - - double powerBoost = target.getPowerBoost(); - String boost = (powerBoost == 0.0) ? "" : (powerBoost > 0.0 ? " (bonus: " : " (penalty: ") + powerBoost + ")"; + // INFO: Title + msg(Txt.titleize(Txt.upperCaseFirst(uplayer.getUniverse()) + " Player " + uplayer.describeTo(usender))); + + // INFO: Power (as progress bar) + double progressbarQuota = uplayer.getPower() / uplayer.getPowerMax(); + int progressbarWidth = (int) Math.round(uplayer.getPowerMax() / uplayer.getPowerMaxUniversal() * 100); + msg("Power: %s", Progressbar.HEALTHBAR_CLASSIC.withQuota(progressbarQuota).withWidth(progressbarWidth).render()); + + // INFO: Power (as digits) + msg("Power: %.2f / %.2f", uplayer.getPower(), uplayer.getPowerMax()); + + // INFO: Power Boost + if (uplayer.hasPowerBoost()) + { + double powerBoost = uplayer.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 = uplayer.getPowerMax() - uplayer.getPower(); + if (powerTillMax > 0) + { + long millisTillMax = (long) (powerTillMax * TimeUnit.MILLIS_PER_HOUR / uplayer.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", uplayer.getPowerPerHour(), stringTillMax); + + // INFO: Power per Death + msg("Power per Death: %.2f", uplayer.getPowerPerDeath()); - msg("%s - Power / Maxpower: %.2f / %.2f %s", target.describeTo(usender, true), target.getPower(), target.getPowerMax(), boost); } } \ No newline at end of file diff --git a/src/com/massivecraft/factions/mixin/PowerMixinDefault.java b/src/com/massivecraft/factions/mixin/PowerMixinDefault.java index 75acc66a..98f39b14 100644 --- a/src/com/massivecraft/factions/mixin/PowerMixinDefault.java +++ b/src/com/massivecraft/factions/mixin/PowerMixinDefault.java @@ -31,7 +31,7 @@ public class PowerMixinDefault implements PowerMixin @Override public double getMin(UPlayer uplayer) { - return UConf.get(uplayer).powerMin + uplayer.getPowerBoost(); + return UConf.get(uplayer).powerMin; } @Override