2011-10-09 21:57:43 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
2011-03-22 15:45:41 +01:00
|
|
|
|
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;
|
2012-11-06 16:43:30 +01:00
|
|
|
import com.massivecraft.factions.struct.Relation;
|
2014-12-07 04:44:00 +01:00
|
|
|
import com.massivecraft.factions.util.MiscUtil;
|
2015-01-22 00:58:33 +01:00
|
|
|
import com.massivecraft.factions.zcore.util.TL;
|
2014-11-13 20:49:13 +01:00
|
|
|
import mkremins.fanciful.FancyMessage;
|
|
|
|
import org.bukkit.ChatColor;
|
2014-04-04 20:55:21 +02:00
|
|
|
|
2014-11-17 20:16:58 +01:00
|
|
|
import java.util.ArrayList;
|
2014-12-15 00:24:25 +01:00
|
|
|
import java.util.List;
|
2014-04-04 20:55:21 +02:00
|
|
|
|
|
|
|
public class CmdShow extends FCommand {
|
2014-12-30 06:31:36 +01:00
|
|
|
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
|
|
|
|
2015-01-03 01:19:57 +01: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);
|
2015-05-07 17:39:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (faction == null) {
|
|
|
|
return;
|
2014-04-04 20:55:21 +02:00
|
|
|
}
|
|
|
|
|
2015-01-03 01:19:57 +01:00
|
|
|
// if economy is enabled, they're not on the bypass list, and this
|
|
|
|
// command has a cost set, make 'em pay
|
2015-01-22 00:58:33 +01:00
|
|
|
if (!payForCommand(Conf.econCostShow, TL.COMMAND_SHOW_TOSHOW, TL.COMMAND_SHOW_FORSHOW)) {
|
2014-12-30 05:02:18 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-01 22:10:18 +02:00
|
|
|
String peaceStatus = "";
|
|
|
|
if (faction.isPeaceful()) {
|
2014-12-08 00:12:52 +01:00
|
|
|
peaceStatus = " " + Conf.colorNeutral + TL.COMMAND_SHOW_PEACEFUL.toString();
|
2014-04-04 20:55:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
double powerBoost = faction.getPowerBoost();
|
2015-01-27 18:07:55 +01:00
|
|
|
String boost = (powerBoost == 0.0) ? "" : (powerBoost > 0.0 ? TL.COMMAND_SHOW_BONUS.toString() : TL.COMMAND_SHOW_PENALTY.toString() + powerBoost + ")");
|
2015-04-26 02:15:54 +02:00
|
|
|
|
2014-12-15 00:24:25 +01:00
|
|
|
List<FancyMessage> allies = new ArrayList<FancyMessage>();
|
|
|
|
List<FancyMessage> enemies = new ArrayList<FancyMessage>();
|
2015-01-03 01:19:57 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-01-03 01:19:57 +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
|
|
|
|
2015-01-03 01:19:57 +01:00
|
|
|
if (currentAllies.toJSONString().length() > ARBITRARY_LIMIT) {
|
|
|
|
allies.add(currentAllies);
|
2015-03-31 11:43:05 +02:00
|
|
|
currentAllies = new FancyMessage("");
|
2015-01-03 01:19:57 +01:00
|
|
|
}
|
|
|
|
} 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
|
|
|
|
2015-01-03 01:19:57 +01:00
|
|
|
if (currentEnemies.toJSONString().length() > ARBITRARY_LIMIT) {
|
|
|
|
enemies.add(currentEnemies);
|
2015-03-31 11:43:05 +02:00
|
|
|
currentEnemies = new FancyMessage("");
|
2015-01-03 01:19:57 +01:00
|
|
|
}
|
2014-11-17 21:30:41 +01:00
|
|
|
}
|
|
|
|
}
|
2015-01-03 01:19:57 +01:00
|
|
|
allies.add(currentAllies);
|
|
|
|
enemies.add(currentEnemies);
|
2015-01-02 20:38:35 +01:00
|
|
|
}
|
2014-11-17 21:30:41 +01:00
|
|
|
|
2014-12-15 00:24:25 +01:00
|
|
|
List<FancyMessage> online = new ArrayList<FancyMessage>();
|
|
|
|
List<FancyMessage> offline = new ArrayList<FancyMessage>();
|
2015-01-03 01:19:57 +01:00
|
|
|
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 {
|
2015-01-03 01:19:57 +01:00
|
|
|
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();
|
2015-01-02 20:38:35 +01:00
|
|
|
}
|
2014-11-17 21:30:41 +01:00
|
|
|
}
|
|
|
|
}
|
2015-01-03 01:19:57 +01:00
|
|
|
online.add(currentOnline);
|
|
|
|
offline.add(currentOffline);
|
2014-11-17 21:30:41 +01:00
|
|
|
}
|
2014-12-15 00:24:25 +01:00
|
|
|
|
2014-11-13 20:49:13 +01:00
|
|
|
// Send all at once ;D
|
2014-12-11 05:32:47 +01:00
|
|
|
msg(p.txt.titleize(faction.getTag(fme)));
|
|
|
|
msg(TL.COMMAND_SHOW_DESCRIPTION, faction.getDescription());
|
|
|
|
if (!faction.isNormal()) {
|
|
|
|
return;
|
2015-01-02 20:38:35 +01:00
|
|
|
}
|
2014-12-11 05:32:47 +01:00
|
|
|
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
|
|
|
}
|
2014-12-11 05:32:47 +01: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);
|
|
|
|
}
|
|
|
|
|
2015-01-03 01:19:57 +01:00
|
|
|
// Show bank contents
|
2014-12-11 05:32:47 +01:00
|
|
|
if (Conf.bankEnabled) {
|
|
|
|
msg(TL.COMMAND_SHOW_BANKCONTAINS, Econ.moneyString(Econ.getBalance(faction.getAccountId())));
|
|
|
|
}
|
|
|
|
}
|
2014-12-11 05:36:46 +01:00
|
|
|
|
2014-11-13 20:49:13 +01:00
|
|
|
sendFancyMessage(allies);
|
|
|
|
sendFancyMessage(enemies);
|
|
|
|
sendFancyMessage(online);
|
|
|
|
sendFancyMessage(offline);
|
2015-01-02 20:38:35 +01:00
|
|
|
}
|
2015-01-22 00:58:33 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public TL getUsageTranslation() {
|
|
|
|
return TL.COMMAND_SHOW_COMMANDDESCRIPTION;
|
|
|
|
}
|
2015-02-26 15:58:09 +01:00
|
|
|
|
2015-01-02 20:38:35 +01:00
|
|
|
}
|