Factions3/src/com/massivecraft/factions/cmd/CmdFactionsShow.java

163 lines
5.1 KiB
Java
Raw Normal View History

2011-10-09 21:57:43 +02:00
package com.massivecraft.factions.cmd;
import java.util.ArrayList;
2013-04-25 16:54:55 +02:00
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
2013-04-16 11:05:49 +02:00
import com.massivecraft.factions.cmd.arg.ARFaction;
2013-04-25 13:25:15 +02:00
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
import com.massivecraft.factions.entity.UConf;
import com.massivecraft.factions.entity.UPlayer;
2013-04-22 09:37:53 +02:00
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.event.FactionsEventChunkChangeType;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.FFlag;
import com.massivecraft.factions.Perm;
2013-04-25 16:54:55 +02:00
import com.massivecraft.factions.PlayerRoleComparator;
import com.massivecraft.factions.Rel;
2013-04-16 10:11:59 +02:00
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
2013-04-12 08:56:26 +02:00
import com.massivecraft.mcore.mixin.Mixin;
2013-04-22 09:37:53 +02:00
import com.massivecraft.mcore.money.Money;
import com.massivecraft.mcore.util.TimeDiffUtil;
import com.massivecraft.mcore.util.TimeUnit;
2013-04-10 10:32:04 +02:00
import com.massivecraft.mcore.util.Txt;
2013-04-10 13:12:22 +02:00
public class CmdFactionsShow extends FCommand
2011-10-09 18:35:39 +02:00
{
2013-04-10 13:12:22 +02:00
public CmdFactionsShow()
2011-10-09 18:35:39 +02:00
{
2013-04-25 16:02:37 +02:00
this.addAliases("s", "show", "who");
this.addOptionalArg("faction", "you");
2013-04-25 13:25:15 +02:00
this.addRequirements(ReqFactionsEnabled.get());
2013-04-16 10:11:59 +02:00
this.addRequirements(ReqHasPerm.get(Perm.SHOW.node));
2011-03-23 17:39:56 +01:00
}
2011-10-09 18:35:39 +02:00
@Override
public void perform()
{
2013-04-25 16:54:55 +02:00
// Args
Faction faction = this.arg(0, ARFaction.get(usenderFaction), usenderFaction);
2013-04-16 11:05:49 +02:00
if (faction == null) return;
2013-04-25 16:54:55 +02:00
// Data precalculation
UConf uconf = UConf.get(faction);
2013-04-25 16:54:55 +02:00
//boolean none = faction.isNone();
boolean normal = faction.isNormal();
2013-04-25 16:02:37 +02:00
// INFO: Description
msg(Txt.titleize(faction.getName(usender)));
2013-04-25 16:54:55 +02:00
msg("<a>Description: <i>%s", faction.getDescription());
2013-04-25 16:54:55 +02:00
if (normal)
2011-10-09 18:35:39 +02:00
{
2013-04-25 16:54:55 +02:00
// INFO: Age
long ageMillis = faction.getCreatedAtMillis() - System.currentTimeMillis();
LinkedHashMap<TimeUnit, Long> ageUnitcounts = TimeDiffUtil.limit(TimeDiffUtil.unitcounts(ageMillis, TimeUnit.getAllButMillis()), 3);
String ageString = TimeDiffUtil.formatedVerboose(ageUnitcounts, "<i>");
msg("<a>Age: <i>%s", ageString);
2013-04-25 16:54:55 +02:00
// INFO: Open
msg("<a>Open: <i>"+(faction.isOpen() ? "<lime>Yes<i>, anyone can join" : "<rose>No<i>, only invited people can join"));
// INFO: Power
double powerBoost = faction.getPowerBoost();
String boost = (powerBoost == 0.0) ? "" : (powerBoost > 0.0 ? " (bonus: " : " (penalty: ") + powerBoost + ")";
msg("<a>Land / Power / Maxpower: <i> %d/%d/%d %s", faction.getLandCount(), faction.getPowerRounded(), faction.getPowerMaxRounded(), boost);
// show the land value
if (Econ.isEnabled(faction))
2011-10-09 18:35:39 +02:00
{
2013-04-25 16:54:55 +02:00
long landCount = faction.getLandCount();
2013-04-25 16:54:55 +02:00
for (FactionsEventChunkChangeType type : FactionsEventChunkChangeType.values())
{
2013-04-25 16:54:55 +02:00
Double money = uconf.econChunkCost.get(type);
2013-04-26 08:02:32 +02:00
if (money == null) continue;
if (money == 0D) continue;
2013-04-25 16:54:55 +02:00
money *= landCount;
String word = null;
if (money > 0)
{
word = "cost";
}
else
{
word = "reward";
money *= -1;
}
msg("<a>Total land %s %s: <i>%s", type.toString().toLowerCase(), word, Money.format(faction, money));
}
2013-04-25 16:54:55 +02:00
// Show bank contents
if (UConf.get(faction).bankEnabled)
{
2013-04-25 16:54:55 +02:00
msg("<a>Bank contains: <i>"+Money.format(faction, Money.get(faction)));
}
}
2013-04-25 16:54:55 +02:00
// Display important flags
// TODO: Find the non default flags, and display them instead.
if (faction.getFlag(FFlag.PERMANENT))
{
2013-04-25 16:54:55 +02:00
msg("<a>This faction is permanent - remaining even with no followers.");
}
if (faction.getFlag(FFlag.PEACEFUL))
{
msg("<a>This faction is peaceful - in truce with everyone.");
}
}
2013-04-25 16:54:55 +02:00
2013-04-10 10:32:04 +02:00
String sepparator = Txt.parse("<i>")+", ";
// List the relations to other factions
Map<Rel, List<String>> relationNames = faction.getFactionNamesPerRelation(usender, true);
2011-11-24 16:53:59 +01:00
if (faction.getFlag(FFlag.PEACEFUL))
{
2013-04-10 10:32:04 +02:00
sendMessage(Txt.parse("<a>In Truce with:<i> *everyone*"));
2011-11-24 16:53:59 +01:00
}
else
{
sendMessage(Txt.parse("<a>In Truce with: ") + Txt.implode(relationNames.get(Rel.TRUCE), sepparator));
2011-11-24 16:53:59 +01:00
}
2013-04-25 16:54:55 +02:00
sendMessage(Txt.parse("<a>Allies: ") + Txt.implode(relationNames.get(Rel.ALLY), sepparator));
sendMessage(Txt.parse("<a>Enemies: ") + Txt.implode(relationNames.get(Rel.ENEMY), sepparator));
2013-04-25 16:54:55 +02:00
// List the followers...
List<String> followerNamesOnline = new ArrayList<String>();
List<String> followerNamesOffline = new ArrayList<String>();
2013-04-25 16:02:37 +02:00
2013-04-25 16:54:55 +02:00
List<UPlayer> followers = faction.getUPlayers();
Collections.sort(followers, PlayerRoleComparator.get());
2013-04-25 16:02:37 +02:00
2013-04-25 16:54:55 +02:00
for (UPlayer follower : followers)
2011-10-09 18:35:39 +02:00
{
2013-04-25 16:54:55 +02:00
if (follower.isOnline() && Mixin.isVisible(sender, follower.getId()))
2011-10-09 18:35:39 +02:00
{
2013-04-25 16:54:55 +02:00
followerNamesOnline.add(follower.getNameAndTitle(usender));
2011-10-09 18:35:39 +02:00
}
2013-04-25 16:54:55 +02:00
else if (normal)
2011-10-09 18:35:39 +02:00
{
2013-04-25 16:54:55 +02:00
// For the non-faction we skip the offline members since they are far to many (infinate almost)
followerNamesOffline.add(follower.getNameAndTitle(usender));
}
}
2013-04-25 16:54:55 +02:00
sendMessage(Txt.parse("<a>Followers online (%s): ", followerNamesOnline.size()) + Txt.implode(followerNamesOnline, sepparator));
2013-04-25 16:54:55 +02:00
if (normal)
{
2013-04-25 16:54:55 +02:00
sendMessage(Txt.parse("<a>Followers offline (%s): ", followerNamesOffline.size()) + Txt.implode(followerNamesOffline, sepparator));
}
}
}