Saber-Factions/src/main/java/com/massivecraft/factions/cmd/CmdShow.java

184 lines
7.3 KiB
Java
Raw Normal View History

2011-10-09 21:57:43 +02:00
package com.massivecraft.factions.cmd;
2011-07-18 22:06:02 +02:00
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
2011-10-09 18:35:39 +02:00
import com.massivecraft.factions.Factions;
2014-04-04 20:55:21 +02:00
import com.massivecraft.factions.integration.Econ;
2011-10-09 18:35:39 +02:00
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Relation;
2014-12-07 04:44:00 +01:00
import com.massivecraft.factions.util.MiscUtil;
import com.massivecraft.factions.zcore.util.TL;
import mkremins.fanciful.FancyMessage;
import org.bukkit.ChatColor;
2014-04-04 20:55:21 +02:00
import java.util.ArrayList;
import java.util.List;
2014-04-04 20:55:21 +02:00
public class CmdShow extends FCommand {
private static final int ARBITRARY_LIMIT = 25000;
2014-04-04 20:55:21 +02:00
public CmdShow() {
2014-07-01 22:10:18 +02:00
this.aliases.add("show");
this.aliases.add("who");
2014-04-04 20:55:21 +02:00
// this.requiredArgs.add("");
2014-04-04 20:55:21 +02:00
this.optionalArgs.put("faction tag", "yours");
2014-07-01 22:10:18 +02:00
this.permission = Permission.SHOW.node;
this.disableOnLock = false;
2014-04-04 20:55:21 +02:00
2014-07-01 22:10:18 +02:00
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
2014-04-04 20:55:21 +02:00
}
@Override
public void perform() {
2014-07-01 22:10:18 +02:00
Faction faction = myFaction;
if (this.argIsSet(0)) {
faction = this.argAsFaction(0);
if (faction == null) {
2014-07-01 22:10:18 +02:00
return;
}
2014-04-04 20:55:21 +02:00
}
// if economy is enabled, they're not on the bypass list, and this
// command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostShow, TL.COMMAND_SHOW_TOSHOW, TL.COMMAND_SHOW_FORSHOW)) {
return;
}
2014-07-01 22:10:18 +02:00
String peaceStatus = "";
if (faction.isPeaceful()) {
peaceStatus = " " + Conf.colorNeutral + TL.COMMAND_SHOW_PEACEFUL.toString();
2014-04-04 20:55:21 +02:00
}
double powerBoost = faction.getPowerBoost();
String boost = (powerBoost == 0.0) ? "" : (powerBoost > 0.0 ? TL.COMMAND_SHOW_BONUS.toString() : TL.COMMAND_SHOW_PENALTY.toString() + powerBoost + ")");
2014-04-04 20:55:21 +02:00
String raidable = faction.getLandRounded() > faction.getPowerRounded() ? TL.RAIDABLE_TRUE.toString() : TL.RAIDABLE_FALSE.toString();
2014-04-04 20:55:21 +02:00
List<FancyMessage> allies = new ArrayList<FancyMessage>();
List<FancyMessage> enemies = new ArrayList<FancyMessage>();
if (!faction.isNone()) {
FancyMessage currentAllies = new FancyMessage(TL.COMMAND_SHOW_ALLIES.toString()).color(ChatColor.GOLD);
FancyMessage currentEnemies = new FancyMessage(TL.COMMAND_SHOW_ENEMIES.toString()).color(ChatColor.GOLD);
boolean firstAlly = true;
boolean firstEnemy = true;
for (Faction otherFaction : Factions.getInstance().getAllFactions()) {
if (otherFaction == faction) {
continue;
2014-11-17 21:30:41 +01:00
}
Relation rel = otherFaction.getRelationTo(faction);
String s = otherFaction.getTag(fme);
if (rel.isAlly()) {
if (firstAlly) {
currentAllies.then(s).tooltip(getToolTips(otherFaction));
} else {
currentAllies.then(", " + s).tooltip(getToolTips(otherFaction));
}
firstAlly = false;
2014-11-17 21:30:41 +01:00
if (currentAllies.toJSONString().length() > ARBITRARY_LIMIT) {
allies.add(currentAllies);
currentAllies = new FancyMessage("");
}
} else if (rel.isEnemy()) {
if (firstEnemy) {
currentEnemies.then(s).tooltip(getToolTips(otherFaction));
} else {
currentEnemies.then(", " + s).tooltip(getToolTips(otherFaction));
}
firstEnemy = false;
2014-11-17 21:30:41 +01:00
if (currentEnemies.toJSONString().length() > ARBITRARY_LIMIT) {
enemies.add(currentEnemies);
currentEnemies = new FancyMessage("");
}
2014-11-17 21:30:41 +01:00
}
}
allies.add(currentAllies);
enemies.add(currentEnemies);
}
2014-11-17 21:30:41 +01:00
List<FancyMessage> online = new ArrayList<FancyMessage>();
List<FancyMessage> offline = new ArrayList<FancyMessage>();
if (!faction.isNone()) {
FancyMessage currentOnline = new FancyMessage(TL.COMMAND_SHOW_MEMBERSONLINE.toString()).color(ChatColor.GOLD);
FancyMessage currentOffline = new FancyMessage(TL.COMMAND_SHOW_MEMBERSOFFLINE.toString()).color(ChatColor.GOLD);
boolean firstOnline = true;
boolean firstOffline = true;
for (FPlayer p : MiscUtil.rankOrder(faction.getFPlayers())) {
String name = p.getNameAndTitle();
if (p.isOnline()) {
if (firstOnline) {
currentOnline.then(name).tooltip(getToolTips(p));
} else {
currentOnline.then(", " + name).tooltip(getToolTips(p));
}
firstOnline = false;
if (currentOnline.toJSONString().length() > ARBITRARY_LIMIT) {
online.add(currentOnline);
currentOnline = new FancyMessage();
}
2014-11-17 21:30:41 +01:00
} else {
if (firstOffline) {
currentOffline.then(name).tooltip(getToolTips(p));
} else {
currentOffline.then(", " + name).tooltip(getToolTips(p));
}
firstOffline = false;
if (currentOffline.toJSONString().length() > ARBITRARY_LIMIT) {
offline.add(currentOffline);
currentOffline = new FancyMessage();
}
2014-11-17 21:30:41 +01:00
}
}
online.add(currentOnline);
offline.add(currentOffline);
2014-11-17 21:30:41 +01:00
}
// Send all at once ;D
msg(p.txt.titleize(faction.getTag(fme)));
msg(TL.COMMAND_SHOW_DESCRIPTION, faction.getDescription());
if (!faction.isNormal()) {
return;
}
msg(TL.COMMAND_SHOW_JOINING.toString() + peaceStatus, (faction.getOpen() ? TL.COMMAND_SHOW_UNINVITED.toString() : TL.COMMAND_SHOW_INVITATION.toString()));
msg(TL.COMMAND_SHOW_POWER, faction.getLandRounded(), faction.getPowerRounded(), faction.getPowerMaxRounded(), boost);
if (faction.isPermanent()) {
msg(TL.COMMAND_SHOW_PERMANENT);
2014-07-01 22:10:18 +02:00
}
// show the land value
if (Econ.shouldBeUsed()) {
double value = Econ.calculateTotalLandValue(faction.getLandRounded());
double refund = value * Conf.econClaimRefundMultiplier;
if (value > 0) {
String stringValue = Econ.moneyString(value);
String stringRefund = (refund > 0.0) ? (TL.COMMAND_SHOW_DEPRECIATED.format(Econ.moneyString(refund))) : "";
msg(TL.COMMAND_SHOW_LANDVALUE, stringValue, stringRefund);
}
// Show bank contents
if (Conf.bankEnabled) {
msg(TL.COMMAND_SHOW_BANKCONTAINS, Econ.moneyString(Econ.getBalance(faction.getAccountId())));
}
}
sendFancyMessage(allies);
sendFancyMessage(enemies);
sendFancyMessage(online);
sendFancyMessage(offline);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_SHOW_COMMANDDESCRIPTION;
}
2015-02-26 15:58:09 +01:00
}