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

180 lines
5.6 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.MFlag;
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.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;
2014-09-18 13:41:20 +02:00
public class CmdFactionsFaction extends FactionsCommand
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
2014-09-18 13:41:20 +02:00
Faction faction = this.arg(0, ARFaction.get(), msenderFaction);
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
2014-09-18 13:41:20 +02:00
msg(Txt.titleize("Faction " + faction.getName(msender)));
2013-04-26 17:54:06 +02:00
// INFO: Id (admin mode output only)
if (msender.isUsingAdminMode())
{
2014-10-15 12:05:16 +02:00
msg("<a>ID: <i>%s", faction.getId());
}
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
// TODO: Why hardcode displaying the open flag only? We should rather display everything publicly editable.
msg("<a>Open: <i>"+(faction.getFlag(MFlag.getFlagOpen()) ? "<lime>Yes<i>, anyone can join" : "<rose>No<i>, only invited people can join"));
2013-04-25 16:54:55 +02:00
// 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(MFlag.getFlagPermanent()))
{
2013-04-25 16:54:55 +02:00
msg("<a>This faction is permanent - remaining even with no followers.");
}
if (faction.getFlag(MFlag.getFlagPeaceful()))
2013-04-25 16:54:55 +02:00
{
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
2014-09-18 13:41:20 +02:00
Map<Rel, List<String>> relationNames = faction.getFactionNamesPerRelation(msender, true);
2011-11-24 16:53:59 +01:00
if (faction.getFlag(MFlag.getFlagPeaceful()))
2011-11-24 16:53:59 +01:00
{
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
2014-09-17 13:29:58 +02:00
List<MPlayer> followers = faction.getMPlayers();
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
{
2014-09-18 13:41:20 +02:00
followerNamesOnline.add(follower.getNameAndTitle(msender));
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)
2014-09-18 13:41:20 +02:00
followerNamesOffline.add(follower.getNameAndTitle(msender));
}
}
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));
}
}
}