Factions/src/main/java/com/massivecraft/factions/cmd/CmdFactionsFaction.java

173 lines
5.3 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;
import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.entity.MPlayer;
2013-04-22 09:37:53 +02:00
import com.massivecraft.factions.entity.Faction;
2014-06-04 16:47:01 +02:00
import com.massivecraft.factions.event.EventFactionsChunkChangeType;
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;
2014-06-04 14:02:23 +02:00
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
import com.massivecraft.massivecore.mixin.Mixin;
import com.massivecraft.massivecore.money.Money;
import com.massivecraft.massivecore.util.TimeDiffUtil;
import com.massivecraft.massivecore.util.TimeUnit;
import com.massivecraft.massivecore.util.Txt;
public class CmdFactionsFaction extends FCommand
2011-10-09 18:35:39 +02:00
{
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsFaction()
2011-10-09 18:35:39 +02:00
{
2013-11-11 09:31:04 +01:00
// Aliases
this.addAliases("f", "faction");
2013-11-11 09:31:04 +01:00
// Args
this.addOptionalArg("faction", "you");
2013-11-11 09:31:04 +01:00
// Requirements
this.addRequirements(ReqHasPerm.get(Perm.FACTION.node));
2011-03-23 17:39:56 +01:00
}
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
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);
2013-04-16 11:05:49 +02:00
if (faction == null) return;
2013-04-25 16:54:55 +02:00
// Data precalculation
//boolean none = faction.isNone();
boolean normal = faction.isNormal();
2013-04-26 17:54:06 +02:00
// INFO: Title
msg(Txt.titleize(Txt.upperCaseFirst(faction.getUniverse()) + " Faction " + faction.getName(usender)));
2013-04-25 16:02:37 +02:00
// INFO: Description
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())
2011-10-09 18:35:39 +02:00
{
2013-04-25 16:54:55 +02:00
long landCount = faction.getLandCount();
2014-06-04 16:47:01 +02:00
for (EventFactionsChunkChangeType type : EventFactionsChunkChangeType.values())
{
Double money = MConf.get().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(money));
}
2013-04-25 16:54:55 +02:00
// Show bank contents
if (MConf.get().bankEnabled)
{
msg("<a>Bank contains: <i>"+Money.format(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
List<MPlayer> followers = faction.getUPlayers();
2013-04-25 16:54:55 +02:00
Collections.sort(followers, PlayerRoleComparator.get());
2013-04-25 16:02:37 +02:00
for (MPlayer follower : followers)
2011-10-09 18:35:39 +02:00
{
if (follower.isOnline() && Mixin.canSee(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));
}
}
}