2013-04-25 17:17:23 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
|
|
|
|
2013-04-26 17:54:06 +02:00
|
|
|
import java.util.LinkedHashMap;
|
2014-10-06 13:08:34 +02:00
|
|
|
import java.util.Map.Entry;
|
2013-04-26 17:54:06 +02:00
|
|
|
|
2013-04-25 17:17:23 +02:00
|
|
|
import com.massivecraft.factions.Perm;
|
2014-09-17 13:29:58 +02:00
|
|
|
import com.massivecraft.factions.cmd.arg.ARMPlayer;
|
2014-10-06 13:08:34 +02:00
|
|
|
import com.massivecraft.factions.entity.MConf;
|
2014-09-17 13:17:33 +02:00
|
|
|
import com.massivecraft.factions.entity.MPlayer;
|
2014-10-06 13:08:34 +02:00
|
|
|
import com.massivecraft.factions.event.EventFactionsRemovePlayerMillis;
|
2015-02-12 12:00:55 +01:00
|
|
|
import com.massivecraft.massivecore.MassiveException;
|
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;
|
2013-04-25 17:17:23 +02:00
|
|
|
|
2014-09-18 13:41:20 +02:00
|
|
|
public class CmdFactionsPlayer extends FactionsCommand
|
2013-04-25 17:17:23 +02:00
|
|
|
{
|
2013-11-11 09:31:04 +01:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// CONSTRUCT
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
2013-04-26 14:01:28 +02:00
|
|
|
public CmdFactionsPlayer()
|
2013-04-25 17:17:23 +02:00
|
|
|
{
|
2013-11-11 09:31:04 +01:00
|
|
|
// Aliases
|
2013-04-26 14:01:28 +02:00
|
|
|
this.addAliases("p", "player");
|
2013-11-11 09:31:04 +01:00
|
|
|
|
|
|
|
// Args
|
2015-05-06 17:04:35 +02:00
|
|
|
this.addArg(ARMPlayer.getAny(), "player", "you");
|
2013-11-11 09:31:04 +01:00
|
|
|
|
|
|
|
// Requirements
|
2013-04-26 14:01:28 +02:00
|
|
|
this.addRequirements(ReqHasPerm.get(Perm.PLAYER.node));
|
2013-04-25 17:17:23 +02:00
|
|
|
}
|
2013-11-11 09:31:04 +01:00
|
|
|
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// OVERRIDE
|
|
|
|
// -------------------------------------------- //
|
2013-04-25 17:17:23 +02:00
|
|
|
|
|
|
|
@Override
|
2015-02-12 12:00:55 +01:00
|
|
|
public void perform() throws MassiveException
|
2013-04-25 17:17:23 +02:00
|
|
|
{
|
|
|
|
// Args
|
2015-05-06 17:04:35 +02:00
|
|
|
MPlayer mplayer = this.readArg(msender);
|
2013-04-25 17:17:23 +02:00
|
|
|
|
2013-04-26 17:54:06 +02:00
|
|
|
// INFO: Title
|
2014-09-18 13:41:20 +02:00
|
|
|
msg(Txt.titleize("Player " + mplayer.describeTo(msender)));
|
2013-04-26 17:54:06 +02:00
|
|
|
|
|
|
|
// INFO: Power (as progress bar)
|
2014-10-03 13:22:35 +02:00
|
|
|
double progressbarQuota = 0;
|
|
|
|
double playerPowerMax = mplayer.getPowerMax();
|
|
|
|
if (playerPowerMax != 0)
|
|
|
|
{
|
|
|
|
progressbarQuota = mplayer.getPower() / playerPowerMax;
|
|
|
|
}
|
|
|
|
|
2014-09-17 13:29:58 +02:00
|
|
|
int progressbarWidth = (int) Math.round(mplayer.getPowerMax() / mplayer.getPowerMaxUniversal() * 100);
|
2014-10-06 13:08:34 +02:00
|
|
|
msg("<a>Power: <v>%s", Progressbar.HEALTHBAR_CLASSIC.withQuota(progressbarQuota).withWidth(progressbarWidth).render());
|
2013-04-26 17:54:06 +02:00
|
|
|
|
|
|
|
// INFO: Power (as digits)
|
2014-10-06 13:08:34 +02:00
|
|
|
msg("<a>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");
|
2014-10-06 13:08:34 +02:00
|
|
|
msg("<a>Power Boost: <v>%f <i>(a manually granted %s)", powerBoost, powerBoostType);
|
2013-04-26 17:54:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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-10-06 13:08:34 +02:00
|
|
|
msg("<a>Power per Hour: <v>%.2f%s", mplayer.getPowerPerHour(), stringTillMax);
|
2013-04-26 17:54:06 +02:00
|
|
|
|
|
|
|
// INFO: Power per Death
|
2014-10-06 13:08:34 +02:00
|
|
|
msg("<a>Power per Death: <v>%.2f", mplayer.getPowerPerDeath());
|
2013-04-25 17:17:23 +02:00
|
|
|
|
2014-10-06 13:08:34 +02:00
|
|
|
// Display automatic kick / remove info if the system is in use
|
|
|
|
if (MConf.get().removePlayerMillisDefault <= 0) return;
|
|
|
|
|
|
|
|
EventFactionsRemovePlayerMillis event = new EventFactionsRemovePlayerMillis(false, mplayer);
|
|
|
|
event.run();
|
|
|
|
msg("<i>Automatic removal after %s <i>of inactivity:", format(event.getMillis()));
|
|
|
|
for (Entry<String, Long> causeMillis : event.getCauseMillis().entrySet())
|
|
|
|
{
|
|
|
|
String cause = causeMillis.getKey();
|
|
|
|
long millis = causeMillis.getValue();
|
|
|
|
msg("<a>%s<a>: <v>%s", cause, format(millis));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// TIME FORMAT
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
|
|
|
public static String format(long millis)
|
|
|
|
{
|
|
|
|
LinkedHashMap<TimeUnit, Long> unitcounts = TimeDiffUtil.unitcounts(millis, TimeUnit.getAllBut(TimeUnit.MILLISECOND, TimeUnit.WEEK, TimeUnit.MONTH));
|
|
|
|
return TimeDiffUtil.formatedVerboose(unitcounts);
|
2013-04-25 17:17:23 +02:00
|
|
|
}
|
2013-11-11 09:31:04 +01:00
|
|
|
|
2013-04-25 17:17:23 +02:00
|
|
|
}
|