Add tooltips for f show.
Refactor tooltip methods to be shared across command classes.
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Conf;
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
@@ -11,7 +10,6 @@ import org.bukkit.ChatColor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class CmdList extends FCommand {
|
||||
@@ -111,19 +109,4 @@ public class CmdList extends FCommand {
|
||||
|
||||
sendFancyMessage(lines);
|
||||
}
|
||||
|
||||
private List<String> getToolTips(Faction faction) {
|
||||
List<String> lines = new ArrayList<String>();
|
||||
for (String s : p.getConfig().getStringList("tooltips.list")) {
|
||||
lines.add(ChatColor.translateAlternateColorCodes('&',replaceFInfoTags(s, faction)));
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
private String replaceFInfoTags(String s, Faction faction) {
|
||||
boolean raidable = faction.getLandRounded() > faction.getPower();
|
||||
FPlayer fLeader = faction.getFPlayerAdmin();
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ import com.massivecraft.factions.integration.Econ;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.struct.Relation;
|
||||
import com.massivecraft.factions.struct.Role;
|
||||
import mkremins.fanciful.FancyMessage;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -85,131 +87,39 @@ public class CmdShow extends FCommand {
|
||||
}
|
||||
}
|
||||
|
||||
String listpart;
|
||||
|
||||
// List relation
|
||||
String allyList = p.txt.parse("<a>Allies: ");
|
||||
String enemyList = p.txt.parse("<a>Enemies: ");
|
||||
FancyMessage allies = new FancyMessage("Allies: ").color(ChatColor.GOLD);
|
||||
FancyMessage enemies = new FancyMessage("Enemies: ").color(ChatColor.GOLD);
|
||||
for (Faction otherFaction : Factions.getInstance().getAllFactions()) {
|
||||
if (otherFaction == faction) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Relation rel = otherFaction.getRelationTo(faction);
|
||||
if (!rel.isAlly() && !rel.isEnemy()) {
|
||||
continue; // if not ally or enemy, drop out now so we're not wasting time on it; good performance boost
|
||||
}
|
||||
|
||||
listpart = otherFaction.getTag(fme) + p.txt.parse("<i>") + ", ";
|
||||
String s = otherFaction.getTag(fme);
|
||||
if (rel.isAlly()) {
|
||||
allyList += listpart;
|
||||
allies.then(s).tooltip(getToolTips(otherFaction));
|
||||
} 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);
|
||||
}
|
||||
|
||||
if (allyList.length() > 2048) {
|
||||
String[] lines = splitString(allyList, 2048, 256000);
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
sendMessage(lines[i]);
|
||||
}
|
||||
} else {
|
||||
sendMessage(allyList);
|
||||
}
|
||||
if (enemyList.length() > 2048) {
|
||||
String[] lines = splitString(enemyList, 2048, 256000);
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
sendMessage(lines[i]);
|
||||
}
|
||||
} else {
|
||||
sendMessage(enemyList);
|
||||
}
|
||||
|
||||
// List the members...
|
||||
String onlineList = p.txt.parse("<a>") + "Members online: ";
|
||||
String offlineList = p.txt.parse("<a>") + "Members offline: ";
|
||||
boolean canSeePower = Permission.POWER_ANY.has(me);
|
||||
for (FPlayer follower : admins) {
|
||||
listpart = follower.getNameAndTitle(fme);
|
||||
if (canSeePower) {
|
||||
listpart += p.txt.parse("<i>(%d), ", follower.getPowerRounded());
|
||||
} else {
|
||||
listpart += p.txt.parse("<i>, ");
|
||||
}
|
||||
if (follower.isOnlineAndVisibleTo(me)) {
|
||||
onlineList += listpart;
|
||||
} else {
|
||||
offlineList += listpart;
|
||||
}
|
||||
}
|
||||
for (FPlayer follower : mods) {
|
||||
listpart = follower.getNameAndTitle(fme);
|
||||
if (canSeePower) {
|
||||
listpart += p.txt.parse("<i>(%d), ", follower.getPowerRounded());
|
||||
} else {
|
||||
listpart += p.txt.parse("<i>, ");
|
||||
}
|
||||
if (follower.isOnlineAndVisibleTo(me)) {
|
||||
onlineList += listpart;
|
||||
} else {
|
||||
offlineList += listpart;
|
||||
}
|
||||
}
|
||||
for (FPlayer follower : normals) {
|
||||
listpart = follower.getNameAndTitle(fme);
|
||||
if (canSeePower) {
|
||||
listpart += p.txt.parse("<i>(%d), ", follower.getPowerRounded());
|
||||
} else {
|
||||
listpart += p.txt.parse("<i>, ");
|
||||
}
|
||||
if (follower.isOnlineAndVisibleTo(me)) {
|
||||
onlineList += listpart;
|
||||
} else {
|
||||
offlineList += listpart;
|
||||
enemies.then(s).tooltip(getToolTips(otherFaction));
|
||||
}
|
||||
}
|
||||
|
||||
if (onlineList.endsWith(", ")) {
|
||||
onlineList = onlineList.substring(0, onlineList.length() - 2);
|
||||
}
|
||||
if (offlineList.endsWith(", ")) {
|
||||
offlineList = offlineList.substring(0, offlineList.length() - 2);
|
||||
|
||||
FancyMessage online = new FancyMessage("Members online: ").color(ChatColor.GOLD);
|
||||
FancyMessage offline = new FancyMessage("Members offline: ").color(ChatColor.GOLD);
|
||||
for (FPlayer p : faction.getFPlayers()) {
|
||||
String name = p.getNameAndTitle();
|
||||
if (p.isOnline()) {
|
||||
online.then(name).tooltip(getToolTips(p));
|
||||
} else {
|
||||
offline.then(name).tooltip(getToolTips(p));
|
||||
}
|
||||
}
|
||||
|
||||
if (onlineList.length() > 2048) {
|
||||
String[] lines = splitString(onlineList, 2048, 256000);
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
sendMessage(lines[i]);
|
||||
}
|
||||
} else {
|
||||
sendMessage(onlineList);
|
||||
}
|
||||
if (offlineList.length() > 2048) {
|
||||
String[] lines = splitString(offlineList, 2048, 256000);
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
sendMessage(lines[i]);
|
||||
}
|
||||
} else {
|
||||
sendMessage(offlineList);
|
||||
}
|
||||
}
|
||||
|
||||
private String[] splitString(String text, int chunkSize, int maxLength) {
|
||||
char[] data = text.toCharArray();
|
||||
int len = Math.min(data.length, maxLength);
|
||||
String[] result = new String[(len + chunkSize - 1) / chunkSize];
|
||||
int linha = 0;
|
||||
for (int i = 0; i < len; i += chunkSize) {
|
||||
result[linha] = new String(data, i, Math.min(chunkSize, len - i));
|
||||
linha++;
|
||||
}
|
||||
return result;
|
||||
// Send all at once ;D
|
||||
sendFancyMessage(allies);
|
||||
sendFancyMessage(enemies);
|
||||
sendFancyMessage(online);
|
||||
sendFancyMessage(offline);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user