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

187 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;
import java.util.Collection;
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;
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()
{
Faction faction = this.arg(0, ARFaction.get(usenderFaction), usenderFaction);
2013-04-16 11:05:49 +02:00
if (faction == null) return;
UConf uconf = UConf.get(faction);
2013-04-25 16:02:37 +02:00
// INFO: Description
msg(Txt.titleize(faction.getName(usender)));
2011-10-10 13:40:24 +02:00
msg("<a>Description: <i>%s", faction.getDescription());
2013-04-25 16:02:37 +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);
// Display important flags
// TODO: Find the non default flags, and display them instead.
if (faction.getFlag(FFlag.PERMANENT))
2011-10-09 18:35:39 +02:00
{
2011-11-24 16:53:59 +01:00
msg("<a>This faction is permanent - remaining even with no members.");
}
if (faction.getFlag(FFlag.PEACEFUL))
2011-10-09 18:35:39 +02:00
{
2011-11-24 16:53:59 +01:00
msg("<a>This faction is peaceful - in truce with everyone.");
}
New "peaceful" status for factions which can only be set by server admins/moderators. Members of peaceful factions cannot deal or receive PvP damage (unless in a war zone which has friendly fire enabled), cannot claim land from another faction and likewise can't have their land claimed, and cannot be considered as ally or enemy of any other faction. Faction admins and moderators of peaceful factions can enable/disable all explosions inside their faction's territory at will. The main purpose of this is to provide a way for more peaceful players who don't want to take part in faction wars (or just want to take a break from them) to still have fun on the server. It is also meant to allow groups of players to make protected buildings, monuments, grand constructions, and so forth without having to worry about another faction destroying them. New conf.json settings: "peacefulTerritoryDisablePVP" (default true) prevents PvP damage for anyone inside a peaceful faction's territory "peacefulTerritoryDisableMonsters" (default false) provides protection against monsters spawning or attacking inside a peaceful faction's territory "peacefulMembersDisablePowerLoss" (default true) which keeps members of peaceful factions from suffering power loss when they die. New commands: /f peaceful [faction tag] - toggle the indicated faction's "peaceful" status /f noboom - enable/disable explosions inside your faction's territory; only available to faction admin and faction moderators for peaceful factions New permission nodes: factions.setPeaceful - ability to use the /f peaceful command (admins) factions.peacefulExplosionToggle - ability to use /f noboom (everyone)
2011-08-05 10:50:47 +02:00
2013-04-25 16:02:37 +02:00
// INFO: Open
msg("<a>Open: <i>"+(faction.isOpen() ? "<lime>Yes <i>- anyone can join" : "<rose>No <i>- only invited people can join"));
2013-04-25 16:02:37 +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
2013-04-22 09:37:53 +02:00
if (Econ.isEnabled(faction))
2011-10-09 18:35:39 +02:00
{
long landCount = faction.getLandCount();
for (FactionsEventChunkChangeType type : FactionsEventChunkChangeType.values())
2011-10-09 18:35:39 +02:00
{
Double money = uconf.econChunkCost.get(type);
if (money == null) money = 0D;
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));
}
// Show bank contents
if (UConf.get(faction).bankEnabled)
{
2013-04-22 09:37:53 +02:00
msg("<a>Bank contains: <i>"+Money.format(faction, Money.get(faction)));
}
}
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
}
sendMessage(Txt.parse("<a>Allied to: ") + Txt.implode(relationNames.get(Rel.ALLY), sepparator));
sendMessage(Txt.parse("<a>Enemies: ") + Txt.implode(relationNames.get(Rel.ENEMY), sepparator));
// List the members...
2013-04-25 16:02:37 +02:00
Collection<UPlayer> leaders = faction.getUPlayersWhereRole(Rel.LEADER);
Collection<UPlayer> officers = faction.getUPlayersWhereRole(Rel.OFFICER);
Collection<UPlayer> normals = faction.getUPlayersWhereRole(Rel.MEMBER);
Collection<UPlayer> recruits = faction.getUPlayersWhereRole(Rel.RECRUIT);
List<String> memberOnlineNames = new ArrayList<String>();
List<String> memberOfflineNames = new ArrayList<String>();
for (UPlayer follower : leaders)
2011-10-09 18:35:39 +02:00
{
2013-04-12 08:56:26 +02:00
if (follower.isOnline() && Mixin.isVisible(me, follower.getId()))
2011-10-09 18:35:39 +02:00
{
memberOnlineNames.add(follower.getNameAndTitle(usender));
2011-10-09 18:35:39 +02:00
}
else
2011-10-09 18:35:39 +02:00
{
memberOfflineNames.add(follower.getNameAndTitle(usender));
}
}
for (UPlayer follower : officers)
2011-10-09 18:35:39 +02:00
{
2013-04-12 08:56:26 +02:00
if (follower.isOnline() && Mixin.isVisible(me, follower.getId()))
2011-10-09 18:35:39 +02:00
{
memberOnlineNames.add(follower.getNameAndTitle(usender));
2011-10-09 18:35:39 +02:00
}
else
{
memberOfflineNames.add(follower.getNameAndTitle(usender));
}
}
for (UPlayer follower : normals)
2011-10-09 18:35:39 +02:00
{
2013-04-12 08:56:26 +02:00
if (follower.isOnline() && Mixin.isVisible(me, follower.getId()))
2011-10-09 18:35:39 +02:00
{
memberOnlineNames.add(follower.getNameAndTitle(usender));
}
else
{
memberOfflineNames.add(follower.getNameAndTitle(usender));
}
}
for (UPlayer follower : recruits)
{
if (follower.isOnline())
{
memberOnlineNames.add(follower.getNameAndTitle(usender));
}
else
{
memberOfflineNames.add(follower.getNameAndTitle(usender));
}
}
2013-04-10 10:45:47 +02:00
sendMessage(Txt.parse("<a>Members online: ") + Txt.implode(memberOnlineNames, sepparator));
sendMessage(Txt.parse("<a>Members offline: ") + Txt.implode(memberOfflineNames, sepparator));
}
}