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-04-04 20:55:21 +02:00
|
|
|
import com.massivecraft.factions.struct.Role;
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
|
|
|
public class CmdShow extends FCommand {
|
|
|
|
|
|
|
|
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("");
|
|
|
|
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
|
|
|
senderMustBePlayer = true;
|
|
|
|
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) {
|
|
|
|
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
|
2014-07-01 21:49:42 +02:00
|
|
|
if (!payForCommand(Conf.econCostShow, "to show faction information", "for showing faction information")) {
|
|
|
|
return;
|
|
|
|
}
|
2014-04-04 20:55:21 +02:00
|
|
|
|
|
|
|
Collection<FPlayer> admins = faction.getFPlayersWhereRole(Role.ADMIN);
|
|
|
|
Collection<FPlayer> mods = faction.getFPlayersWhereRole(Role.MODERATOR);
|
|
|
|
Collection<FPlayer> normals = faction.getFPlayersWhereRole(Role.NORMAL);
|
|
|
|
|
2014-07-01 22:10:18 +02:00
|
|
|
msg(p.txt.titleize(faction.getTag(fme)));
|
|
|
|
msg("<a>Description: <i>%s", faction.getDescription());
|
2014-04-04 20:55:21 +02:00
|
|
|
if (!faction.isNormal()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-01 22:10:18 +02:00
|
|
|
String peaceStatus = "";
|
|
|
|
if (faction.isPeaceful()) {
|
2014-04-04 20:55:21 +02:00
|
|
|
peaceStatus = " " + Conf.colorNeutral + "This faction is Peaceful";
|
|
|
|
}
|
|
|
|
|
|
|
|
msg("<a>Joining: <i>" + (faction.getOpen() ? "no invitation is needed" : "invitation is required") + peaceStatus);
|
|
|
|
|
|
|
|
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.getLandRounded(), faction.getPowerRounded(), faction.getPowerMaxRounded(), boost);
|
|
|
|
|
|
|
|
if (faction.isPermanent()) {
|
|
|
|
msg("<a>This faction is permanent, remaining even with no members.");
|
|
|
|
}
|
|
|
|
|
|
|
|
// show the land value
|
|
|
|
if (Econ.shouldBeUsed()) {
|
|
|
|
double value = Econ.calculateTotalLandValue(faction.getLandRounded());
|
2014-07-01 22:10:18 +02:00
|
|
|
double refund = value * Conf.econClaimRefundMultiplier;
|
|
|
|
if (value > 0) {
|
2014-04-04 20:55:21 +02:00
|
|
|
String stringValue = Econ.moneyString(value);
|
|
|
|
String stringRefund = (refund > 0.0) ? (" (" + Econ.moneyString(refund) + " depreciated)") : "";
|
|
|
|
msg("<a>Total land value: <i>" + stringValue + stringRefund);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Show bank contents
|
|
|
|
if (Conf.bankEnabled) {
|
|
|
|
msg("<a>Bank contains: <i>" + Econ.moneyString(Econ.getBalance(faction.getAccountId())));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String listpart;
|
|
|
|
|
|
|
|
// List relation
|
2014-07-01 22:10:18 +02:00
|
|
|
String allyList = p.txt.parse("<a>Allies: ");
|
|
|
|
String enemyList = p.txt.parse("<a>Enemies: ");
|
2014-10-19 07:37:25 +02:00
|
|
|
for (Faction otherFaction : Factions.getInstance().getAllFactions()) {
|
2014-07-01 22:10:18 +02:00
|
|
|
if (otherFaction == faction) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-04-04 20:55:21 +02:00
|
|
|
|
2014-07-01 22:10:18 +02:00
|
|
|
Relation rel = otherFaction.getRelationTo(faction);
|
|
|
|
if (!rel.isAlly() && !rel.isEnemy()) {
|
2014-04-04 20:55:21 +02:00
|
|
|
continue; // if not ally or enemy, drop out now so we're not wasting time on it; good performance boost
|
2014-07-01 21:49:42 +02:00
|
|
|
}
|
2014-04-04 20:55:21 +02:00
|
|
|
|
|
|
|
listpart = otherFaction.getTag(fme) + p.txt.parse("<i>") + ", ";
|
2014-07-01 22:10:18 +02:00
|
|
|
if (rel.isAlly()) {
|
|
|
|
allyList += listpart;
|
|
|
|
} else if (rel.isEnemy()) {
|
|
|
|
enemyList += listpart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (allyList.endsWith(", ")) {
|
|
|
|
allyList = allyList.substring(0, allyList.length() - 2);
|
|
|
|
}
|
|
|
|
if (enemyList.endsWith(", ")) {
|
|
|
|
enemyList = enemyList.substring(0, enemyList.length() - 2);
|
|
|
|
}
|
2014-04-04 20:55:21 +02:00
|
|
|
|
2014-10-14 20:30:05 +02:00
|
|
|
if (allyList.length() > 2048) {
|
2014-08-26 20:05:54 +02:00
|
|
|
String[] lines = splitString(allyList, 2048, 256000);
|
2014-10-14 20:30:05 +02:00
|
|
|
for (int i = 0; i < lines.length; i++) {
|
2014-08-26 20:05:54 +02:00
|
|
|
sendMessage(lines[i]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sendMessage(allyList);
|
|
|
|
}
|
2014-10-14 20:30:05 +02:00
|
|
|
if (enemyList.length() > 2048) {
|
2014-08-26 20:05:54 +02:00
|
|
|
String[] lines = splitString(enemyList, 2048, 256000);
|
2014-10-14 20:30:05 +02:00
|
|
|
for (int i = 0; i < lines.length; i++) {
|
2014-08-26 20:05:54 +02:00
|
|
|
sendMessage(lines[i]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sendMessage(enemyList);
|
|
|
|
}
|
2014-04-04 20:55:21 +02:00
|
|
|
|
|
|
|
// List the members...
|
|
|
|
String onlineList = p.txt.parse("<a>") + "Members online: ";
|
2014-07-01 22:10:18 +02:00
|
|
|
String offlineList = p.txt.parse("<a>") + "Members offline: ";
|
2014-10-20 00:11:03 +02:00
|
|
|
boolean canSeePower = Permission.POWER_ANY.has(me);
|
2014-07-01 22:10:18 +02:00
|
|
|
for (FPlayer follower : admins) {
|
2014-10-20 00:11:03 +02:00
|
|
|
listpart = follower.getNameAndTitle(fme);
|
|
|
|
if (canSeePower) {
|
|
|
|
listpart += p.txt.parse("<i>(%d), ", follower.getPowerRounded());
|
|
|
|
} else {
|
|
|
|
listpart += p.txt.parse("<i>, ");
|
|
|
|
}
|
2014-04-04 20:55:21 +02:00
|
|
|
if (follower.isOnlineAndVisibleTo(me)) {
|
|
|
|
onlineList += listpart;
|
2014-07-01 21:52:40 +02:00
|
|
|
} else {
|
2014-04-04 20:55:21 +02:00
|
|
|
offlineList += listpart;
|
|
|
|
}
|
2014-07-01 22:10:18 +02:00
|
|
|
}
|
|
|
|
for (FPlayer follower : mods) {
|
2014-10-20 00:11:03 +02:00
|
|
|
listpart = follower.getNameAndTitle(fme);
|
|
|
|
if (canSeePower) {
|
|
|
|
listpart += p.txt.parse("<i>(%d), ", follower.getPowerRounded());
|
|
|
|
} else {
|
|
|
|
listpart += p.txt.parse("<i>, ");
|
|
|
|
}
|
2014-07-01 21:52:40 +02:00
|
|
|
if (follower.isOnlineAndVisibleTo(me)) {
|
2014-04-04 20:55:21 +02:00
|
|
|
onlineList += listpart;
|
2014-07-01 21:52:40 +02:00
|
|
|
} else {
|
2014-04-04 20:55:21 +02:00
|
|
|
offlineList += listpart;
|
|
|
|
}
|
2014-07-01 22:10:18 +02:00
|
|
|
}
|
|
|
|
for (FPlayer follower : normals) {
|
2014-10-20 00:11:03 +02:00
|
|
|
listpart = follower.getNameAndTitle(fme);
|
|
|
|
if (canSeePower) {
|
|
|
|
listpart += p.txt.parse("<i>(%d), ", follower.getPowerRounded());
|
|
|
|
} else {
|
|
|
|
listpart += p.txt.parse("<i>, ");
|
|
|
|
}
|
2014-04-04 20:55:21 +02:00
|
|
|
if (follower.isOnlineAndVisibleTo(me)) {
|
|
|
|
onlineList += listpart;
|
2014-07-01 21:52:40 +02:00
|
|
|
} else {
|
2014-04-04 20:55:21 +02:00
|
|
|
offlineList += listpart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (onlineList.endsWith(", ")) {
|
|
|
|
onlineList = onlineList.substring(0, onlineList.length() - 2);
|
2014-07-01 22:10:18 +02:00
|
|
|
}
|
|
|
|
if (offlineList.endsWith(", ")) {
|
2014-04-04 20:55:21 +02:00
|
|
|
offlineList = offlineList.substring(0, offlineList.length() - 2);
|
|
|
|
}
|
|
|
|
|
2014-10-14 20:30:05 +02:00
|
|
|
if (onlineList.length() > 2048) {
|
2014-08-26 20:05:54 +02:00
|
|
|
String[] lines = splitString(onlineList, 2048, 256000);
|
2014-10-14 20:30:05 +02:00
|
|
|
for (int i = 0; i < lines.length; i++) {
|
2014-08-26 20:05:54 +02:00
|
|
|
sendMessage(lines[i]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sendMessage(onlineList);
|
|
|
|
}
|
2014-10-14 20:30:05 +02:00
|
|
|
if (offlineList.length() > 2048) {
|
2014-08-26 20:05:54 +02:00
|
|
|
String[] lines = splitString(offlineList, 2048, 256000);
|
2014-10-14 20:30:05 +02:00
|
|
|
for (int i = 0; i < lines.length; i++) {
|
2014-08-26 20:05:54 +02:00
|
|
|
sendMessage(lines[i]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sendMessage(offlineList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private String[] splitString(String text, int chunkSize, int maxLength) {
|
|
|
|
char[] data = text.toCharArray();
|
2014-10-14 20:30:05 +02:00
|
|
|
int len = Math.min(data.length, maxLength);
|
|
|
|
String[] result = new String[(len + chunkSize - 1) / chunkSize];
|
2014-08-26 20:05:54 +02:00
|
|
|
int linha = 0;
|
2014-10-14 20:30:05 +02:00
|
|
|
for (int i = 0; i < len; i += chunkSize) {
|
|
|
|
result[linha] = new String(data, i, Math.min(chunkSize, len - i));
|
2014-08-26 20:05:54 +02:00
|
|
|
linha++;
|
|
|
|
}
|
|
|
|
return result;
|
2014-04-04 20:55:21 +02:00
|
|
|
}
|
2011-03-22 15:45:41 +01:00
|
|
|
|
|
|
|
}
|