Remove tooltips for f show and f list.

Tooltips were causing a lot of issues on larger servers. Constructing them as well as the lookups required to display them caused significant lag.

Resolves #197, #164.
This commit is contained in:
drtshock 2015-01-02 13:38:35 -06:00
parent 2209090783
commit 91f9d1d8db
3 changed files with 103 additions and 197 deletions

View File

@ -4,9 +4,6 @@ import com.massivecraft.factions.Conf;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
import mkremins.fanciful.FancyMessage;
import org.bukkit.ChatColor;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -35,7 +32,7 @@ public class CmdList extends FCommand {
@Override @Override
public void perform() { public void perform() {
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostList, TL.COMMAND_LIST_TOLIST.toString(), TL.COMMAND_LIST_FORLIST.toString())) { if (!payForCommand(Conf.econCostList, "to list the factions", "for listing the factions")) {
return; return;
} }
@ -74,7 +71,7 @@ public class CmdList extends FCommand {
} }
}); });
ArrayList<FancyMessage> lines = new ArrayList<FancyMessage>(); ArrayList<String> lines = new ArrayList<String>();
factionList.add(0, Factions.getInstance().getNone()); factionList.add(0, Factions.getInstance().getNone());
@ -92,22 +89,16 @@ public class CmdList extends FCommand {
end = factionList.size(); end = factionList.size();
} }
lines.add(new FancyMessage(p.txt.titleize(TL.COMMAND_LIST_FACTIONLIST.toString() + pagenumber + "/" + pagecount))); lines.add(p.txt.titleize("Faction List " + pagenumber + "/" + pagecount));
for (Faction faction : factionList.subList(start, end)) { for (Faction faction : factionList.subList(start, end)) {
if (faction.isNone()) { if (faction.isNone()) {
String online = String.valueOf(faction.getFPlayersWhereOnline(true).size()); lines.add(p.txt.parse("<i>Factionless<i> %d online", Factions.getInstance().getNone().getFPlayersWhereOnline(true).size()));
FancyMessage msg = new FancyMessage(TL.COMMAND_LIST_ONLINEFACTIONLESS.toString() + online).color(ChatColor.YELLOW);
lines.add(msg);
continue; continue;
} }
String online = " " + faction.getFPlayersWhereOnline(true).size() + "/" + faction.getFPlayers().size() + " online"; lines.add(p.txt.parse("%s<i> %d/%d online, %d/%d/%d", faction.getTag(fme), faction.getFPlayersWhereOnline(true).size(), faction.getFPlayers().size(), faction.getLandRounded(), faction.getPowerRounded(), faction.getPowerMaxRounded()));
FancyMessage msg = new FancyMessage(faction.getTag(fme) + online).color(ChatColor.YELLOW).tooltip(getToolTips(faction));
lines.add(msg);
//lines.add(p.txt.parse("%s<i> %d/%d online, %d/%d/%d", faction.getTag(fme), faction.getFPlayersWhereOnline(true).size(), faction.getFPlayers().size(), faction.getLandRounded(), faction.getPowerRounded(), faction.getPowerMaxRounded()));
} }
sendFancyMessage(lines); sendMessage(lines);
} }
} }

View File

@ -1,19 +1,12 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf; import com.massivecraft.factions.*;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.util.MiscUtil; import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.zcore.util.TL;
import mkremins.fanciful.FancyMessage;
import org.bukkit.ChatColor;
import java.util.ArrayList; import java.util.Collection;
import java.util.List;
public class CmdShow extends FCommand { public class CmdShow extends FCommand {
@ -21,177 +14,133 @@ public class CmdShow extends FCommand {
this.aliases.add("show"); this.aliases.add("show");
this.aliases.add("who"); this.aliases.add("who");
//this.requiredArgs.add("");
this.optionalArgs.put("faction tag", "yours"); this.optionalArgs.put("faction tag", "yours");
this.permission = Permission.SHOW.node; this.permission = Permission.SHOW.node;
this.disableOnLock = false; this.disableOnLock = false;
senderMustBeMember = false; this.senderMustBePlayer = true;
senderMustBeModerator = false; this.senderMustBeMember = false;
senderMustBeAdmin = false; this.senderMustBeModerator = false;
this.senderMustBeAdmin = false;
} }
@Override
public void perform() { public void perform() {
Faction faction = myFaction; Faction faction = this.myFaction;
if (this.argIsSet(0)) { if (argIsSet(0)) {
faction = this.argAsFaction(0); faction = argAsFaction(0);
if (faction == null || faction.isNone()) { if (faction == null) {
msg(TL.COMMAND_SHOW_NOFACTION_OTHER);
return;
}
}
if (faction.isNone()) {
msg(TL.COMMAND_SHOW_NOFACTION_SELF);
return; return;
} }
// 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)) {
if (!payForCommand(Conf.econCostShow, "to show faction information", "for showing faction information")) {
return;
}
Collection<FPlayer> admins = faction.getFPlayersWhereRole(Role.ADMIN);
Collection<FPlayer> mods = faction.getFPlayersWhereRole(Role.MODERATOR);
Collection<FPlayer> normals = faction.getFPlayersWhereRole(Role.NORMAL);
msg((p).txt.titleize(faction.getTag(this.fme)));
msg("<a>Description: <i>%s", faction.getDescription());
if (!faction.isNormal()) {
return; return;
} }
String peaceStatus = ""; String peaceStatus = "";
if (faction.isPeaceful()) { if (faction.isPeaceful()) {
peaceStatus = " " + Conf.colorNeutral + TL.COMMAND_SHOW_PEACEFUL.toString(); 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(); double powerBoost = faction.getPowerBoost();
String boost = (powerBoost == 0.0) ? "" : (powerBoost > 0.0 ? TL.COMMAND_SHOW_BONUS.toString() : TL.COMMAND_SHOW_PENALTY.toString() + powerBoost + ")"); String boost = (powerBoost > 0.0D ? " (bonus: " : " (penalty: ") + powerBoost + ")";
msg("<a>Land / Power / Maxpower: <i> %d/%d/%d %s", faction.getLandRounded(), faction.getPowerRounded(), faction.getPowerMaxRounded(), boost);
List<FancyMessage> allies = new ArrayList<FancyMessage>();
List<FancyMessage> enemies = new ArrayList<FancyMessage>();
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;
}
Relation rel = otherFaction.getRelationTo(faction);
String s = otherFaction.getTag(fme);
if (rel.isAlly()) {
FancyMessage beforeAdd = null;
try {
beforeAdd = currentAllies.clone();
} catch (CloneNotSupportedException ignored) {}
if (firstAlly) {
currentAllies.then(s).tooltip(getToolTips(otherFaction));
} else {
currentAllies.then(", " + s).tooltip(getToolTips(otherFaction));
}
firstAlly = false;
if (currentAllies.toJSONString().length() > Short.MAX_VALUE) {
allies.add(beforeAdd);
currentAllies = new FancyMessage(s).tooltip(getToolTips(otherFaction));
}
} else if (rel.isEnemy()) {
FancyMessage beforeAdd = null;
try {
beforeAdd = currentEnemies.clone();
} catch (CloneNotSupportedException ignored) {}
if (firstEnemy) {
currentEnemies.then(s).tooltip(getToolTips(otherFaction));
} else {
currentEnemies.then(", " + s).tooltip(getToolTips(otherFaction));
}
firstEnemy = false;
if (currentEnemies.toJSONString().length() > Short.MAX_VALUE) {
enemies.add(beforeAdd);
currentEnemies = new FancyMessage(s).tooltip(getToolTips(otherFaction));
}
}
}
allies.add(currentAllies);
enemies.add(currentEnemies);
List<FancyMessage> online = new ArrayList<FancyMessage>();
List<FancyMessage> offline = new ArrayList<FancyMessage>();
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()) {
FancyMessage beforeAdd = null;
try {
beforeAdd = currentOnline.clone();
} catch (CloneNotSupportedException ignored) {}
if (firstOnline) {
currentOnline.then(name).tooltip(getToolTips(p));
} else {
currentOnline.then(", " + name).tooltip(getToolTips(p));
}
firstOnline = false;
if (currentOnline.toJSONString().length() > Short.MAX_VALUE) {
online.add(beforeAdd);
currentOnline = new FancyMessage(name).tooltip(getToolTips(p));
}
} else {
FancyMessage beforeAdd = null;
try {
beforeAdd = currentOffline.clone();
} catch (CloneNotSupportedException ignored) {}
if (firstOffline) {
currentOffline.then(name).tooltip(getToolTips(p));
} else {
currentOffline.then(", " + name).tooltip(getToolTips(p));
}
firstOffline = false;
if (currentOffline.toJSONString().length() > Short.MAX_VALUE) {
offline.add(beforeAdd);
currentOffline = new FancyMessage(name).tooltip(getToolTips(p));
}
}
}
online.add(currentOnline);
offline.add(currentOffline);
// 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()) { if (faction.isPermanent()) {
msg(TL.COMMAND_SHOW_PERMANENT); msg("<a>This faction is permanent, remaining even with no members.");
} }
// show the land value
if (Econ.shouldBeUsed()) { if (Econ.shouldBeUsed()) {
double value = Econ.calculateTotalLandValue(faction.getLandRounded()); double value = Econ.calculateTotalLandValue(faction.getLandRounded());
double refund = value * Conf.econClaimRefundMultiplier; double refund = value * Conf.econClaimRefundMultiplier;
if (value > 0) { if (value > 0.0D) {
String stringValue = Econ.moneyString(value); String stringValue = Econ.moneyString(value);
String stringRefund = (refund > 0.0) ? (TL.COMMAND_SHOW_DEPRECIATED.format(Econ.moneyString(refund))) : ""; String stringRefund = refund > 0.0D ? " (" + Econ.moneyString(refund) + " depreciated)" : "";
msg(TL.COMMAND_SHOW_LANDVALUE, stringValue, stringRefund); msg("<a>Total land value: <i>" + stringValue + stringRefund);
} }
//Show bank contents
if (Conf.bankEnabled) { if (Conf.bankEnabled) {
msg(TL.COMMAND_SHOW_BANKCONTAINS, Econ.moneyString(Econ.getBalance(faction.getAccountId()))); msg("<a>Bank contains: <i>" + Econ.moneyString(Econ.getBalance(faction.getAccountId())));
}
}
sendFancyMessage(allies);
sendFancyMessage(enemies);
sendFancyMessage(online);
sendFancyMessage(offline);
} }
} }
String allyList = p.txt.parse("<a>Allies: ");
String enemyList = p.txt.parse("<a>Enemies: ");
for (Faction otherFaction : Factions.getInstance().getAllFactions()) {
if (otherFaction != faction) {
Relation rel = otherFaction.getRelationTo(faction);
if ((rel.isAlly()) || (rel.isEnemy())) {
String listpart = otherFaction.getTag(this.fme) + p.txt.parse("<i>") + ", ";
if (rel.isAlly()) {
allyList = allyList + listpart;
} else if (rel.isEnemy()) {
enemyList = enemyList + listpart;
}
}
}
}
if (allyList.endsWith(", ")) {
allyList = allyList.substring(0, allyList.length() - 2);
}
if (enemyList.endsWith(", ")) {
enemyList = enemyList.substring(0, enemyList.length() - 2);
}
sendMessage(allyList);
sendMessage(enemyList);
String onlineList = p.txt.parse("<a>") + "Members online: ";
String offlineList = p.txt.parse("<a>") + "Members offline: ";
for (FPlayer follower : admins) {
String listpart = follower.getNameAndTitle(this.fme) + p.txt.parse("<i>") + ", ";
if (follower.isOnlineAndVisibleTo(this.me)) {
onlineList = onlineList + listpart;
} else {
offlineList = offlineList + listpart;
}
}
for (FPlayer follower : mods) {
String listpart = follower.getNameAndTitle(this.fme) + p.txt.parse("<i>") + ", ";
if (follower.isOnlineAndVisibleTo(this.me)) {
onlineList = onlineList + listpart;
} else {
offlineList = offlineList + listpart;
}
}
for (FPlayer follower : normals) {
String listpart = follower.getNameAndTitle(this.fme) + p.txt.parse("<i>") + ", ";
if (follower.isOnlineAndVisibleTo(this.me)) {
onlineList = onlineList + listpart;
} else {
offlineList = offlineList + listpart;
}
}
if (onlineList.endsWith(", ")) {
onlineList = onlineList.substring(0, onlineList.length() - 2);
}
if (offlineList.endsWith(", ")) {
offlineList = offlineList.substring(0, offlineList.length() - 2);
}
sendMessage(onlineList);
sendMessage(offlineList);
}
}

View File

@ -279,40 +279,6 @@ public abstract class MCommand<T extends MPlugin> {
} }
} }
public List<String> getToolTips(FPlayer player) {
List<String> lines = new ArrayList<String>();
for (String s : p.getConfig().getStringList("tooltips.show")) {
lines.add(ChatColor.translateAlternateColorCodes('&', replaceFPlayerTags(s, player)));
}
return lines;
}
public List<String> getToolTips(Faction faction) {
List<String> lines = new ArrayList<String>();
for (String s : p.getConfig().getStringList("tooltips.list")) {
lines.add(ChatColor.translateAlternateColorCodes('&', replaceFactionTags(s, faction)));
}
return lines;
}
public String replaceFPlayerTags(String s, FPlayer player) {
String humanized = DurationFormatUtils.formatDurationWords(System.currentTimeMillis() - player.getLastLoginTime(), true, true) + " ago";
String lastSeen = player.isOnline() ? ChatColor.GREEN + "Online" : (System.currentTimeMillis() - player.getLastLoginTime() < 432000000 ? ChatColor.YELLOW + humanized : ChatColor.RED + humanized);
String balance = Econ.isSetup() ? Econ.getFriendlyBalance(player) : "no balance";
String power = player.getPowerRounded() + "/" + player.getPowerMaxRounded();
String group = P.p.getPrimaryGroup(Bukkit.getOfflinePlayer(player.getName()));
return s.replace("{balance}", balance).replace("{lastSeen}", lastSeen).replace("{power}", power).replace("{group}", group);
}
public String replaceFactionTags(String s, Faction faction) {
boolean raidable = faction.getLandRounded() > faction.getPower();
FPlayer fLeader = faction.getFPlayerAdmin();
String online = String.valueOf(faction.getFPlayersWhereOnline(true).size());
String members = String.valueOf(faction.getFPlayers().size());
String leader = fLeader == null ? "Server" : fLeader.getName().substring(0, fLeader.getName().length() > 14 ? 13 : fLeader.getName().length());
return s.replace("{power}", String.valueOf(faction.getPowerRounded())).replace("{maxPower}", String.valueOf(faction.getPowerMaxRounded())).replace("{leader}", leader).replace("{chunks}", String.valueOf(faction.getLandRounded())).replace("{raidable}", String.valueOf(raidable)).replace("{warps}", String.valueOf(faction.getWarps().size())).replace("{online}", online).replace("{members}", members);
}
// -------------------------------------------- // // -------------------------------------------- //
// Argument Readers // Argument Readers
// -------------------------------------------- // // -------------------------------------------- //