Add tooltips for f show.
Refactor tooltip methods to be shared across command classes.
This commit is contained in:
parent
43826d986f
commit
c4f4036e1d
@ -12,10 +12,14 @@ import com.massivecraft.factions.struct.ChatMode;
|
|||||||
import com.massivecraft.factions.util.*;
|
import com.massivecraft.factions.util.*;
|
||||||
import com.massivecraft.factions.zcore.MPlugin;
|
import com.massivecraft.factions.zcore.MPlugin;
|
||||||
import com.massivecraft.factions.zcore.util.TextUtil;
|
import com.massivecraft.factions.zcore.util.TextUtil;
|
||||||
|
import net.milkbowl.vault.permission.Permission;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
|
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
@ -42,6 +46,8 @@ public class P extends MPlugin {
|
|||||||
// Persistence related
|
// Persistence related
|
||||||
private boolean locked = false;
|
private boolean locked = false;
|
||||||
|
|
||||||
|
public static Permission perms = null;
|
||||||
|
|
||||||
public boolean getLocked() {
|
public boolean getLocked() {
|
||||||
return this.locked;
|
return this.locked;
|
||||||
}
|
}
|
||||||
@ -112,6 +118,7 @@ public class P extends MPlugin {
|
|||||||
getServer().getPluginManager().registerEvents(blockListener, this);
|
getServer().getPluginManager().registerEvents(blockListener, this);
|
||||||
|
|
||||||
saveDefaultConfig();
|
saveDefaultConfig();
|
||||||
|
setupPermissions();
|
||||||
|
|
||||||
// since some other plugins execute commands directly through this command interface, provide it
|
// since some other plugins execute commands directly through this command interface, provide it
|
||||||
this.getCommand(this.refCommand).setExecutor(this);
|
this.getCommand(this.refCommand).setExecutor(this);
|
||||||
@ -120,6 +127,12 @@ public class P extends MPlugin {
|
|||||||
this.loadSuccessful = true;
|
this.loadSuccessful = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean setupPermissions() {
|
||||||
|
RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class);
|
||||||
|
perms = rsp.getProvider();
|
||||||
|
return perms != null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GsonBuilder getGsonBuilder() {
|
public GsonBuilder getGsonBuilder() {
|
||||||
Type mapFLocToStringSetType = new TypeToken<Map<FLocation, Set<String>>>() {
|
Type mapFLocToStringSetType = new TypeToken<Map<FLocation, Set<String>>>() {
|
||||||
@ -306,6 +319,10 @@ public class P extends MPlugin {
|
|||||||
return players;
|
return players;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPrimaryGroup(OfflinePlayer player) {
|
||||||
|
return perms == null ? " " : perms.getPrimaryGroup(Bukkit.getWorlds().get(0).toString(), player);
|
||||||
|
}
|
||||||
|
|
||||||
public void debug(Level level, String s) {
|
public void debug(Level level, String s) {
|
||||||
if (getConfig().getBoolean("debug", false)) {
|
if (getConfig().getBoolean("debug", false)) {
|
||||||
getLogger().log(level, s);
|
getLogger().log(level, s);
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.massivecraft.factions.cmd;
|
package com.massivecraft.factions.cmd;
|
||||||
|
|
||||||
import com.massivecraft.factions.Conf;
|
import com.massivecraft.factions.Conf;
|
||||||
import com.massivecraft.factions.FPlayer;
|
|
||||||
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;
|
||||||
@ -11,7 +10,6 @@ import org.bukkit.ChatColor;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
|
||||||
public class CmdList extends FCommand {
|
public class CmdList extends FCommand {
|
||||||
@ -111,19 +109,4 @@ public class CmdList extends FCommand {
|
|||||||
|
|
||||||
sendFancyMessage(lines);
|
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.Permission;
|
||||||
import com.massivecraft.factions.struct.Relation;
|
import com.massivecraft.factions.struct.Relation;
|
||||||
import com.massivecraft.factions.struct.Role;
|
import com.massivecraft.factions.struct.Role;
|
||||||
|
import mkremins.fanciful.FancyMessage;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
@ -85,131 +87,39 @@ public class CmdShow extends FCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String listpart;
|
FancyMessage allies = new FancyMessage("Allies: ").color(ChatColor.GOLD);
|
||||||
|
FancyMessage enemies = new FancyMessage("Enemies: ").color(ChatColor.GOLD);
|
||||||
// List relation
|
|
||||||
String allyList = p.txt.parse("<a>Allies: ");
|
|
||||||
String enemyList = p.txt.parse("<a>Enemies: ");
|
|
||||||
for (Faction otherFaction : Factions.getInstance().getAllFactions()) {
|
for (Faction otherFaction : Factions.getInstance().getAllFactions()) {
|
||||||
if (otherFaction == faction) {
|
if (otherFaction == faction) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Relation rel = otherFaction.getRelationTo(faction);
|
Relation rel = otherFaction.getRelationTo(faction);
|
||||||
if (!rel.isAlly() && !rel.isEnemy()) {
|
String s = otherFaction.getTag(fme);
|
||||||
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>") + ", ";
|
|
||||||
if (rel.isAlly()) {
|
if (rel.isAlly()) {
|
||||||
allyList += listpart;
|
allies.then(s).tooltip(getToolTips(otherFaction));
|
||||||
} else if (rel.isEnemy()) {
|
} else if (rel.isEnemy()) {
|
||||||
enemyList += listpart;
|
enemies.then(s).tooltip(getToolTips(otherFaction));
|
||||||
}
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (onlineList.endsWith(", ")) {
|
|
||||||
onlineList = onlineList.substring(0, onlineList.length() - 2);
|
|
||||||
}
|
|
||||||
if (offlineList.endsWith(", ")) {
|
|
||||||
offlineList = offlineList.substring(0, offlineList.length() - 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (onlineList.length() > 2048) {
|
FancyMessage online = new FancyMessage("Members online: ").color(ChatColor.GOLD);
|
||||||
String[] lines = splitString(onlineList, 2048, 256000);
|
FancyMessage offline = new FancyMessage("Members offline: ").color(ChatColor.GOLD);
|
||||||
for (int i = 0; i < lines.length; i++) {
|
for (FPlayer p : faction.getFPlayers()) {
|
||||||
sendMessage(lines[i]);
|
String name = p.getNameAndTitle();
|
||||||
}
|
if (p.isOnline()) {
|
||||||
|
online.then(name).tooltip(getToolTips(p));
|
||||||
} else {
|
} else {
|
||||||
sendMessage(onlineList);
|
offline.then(name).tooltip(getToolTips(p));
|
||||||
}
|
|
||||||
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) {
|
// Send all at once ;D
|
||||||
char[] data = text.toCharArray();
|
sendFancyMessage(allies);
|
||||||
int len = Math.min(data.length, maxLength);
|
sendFancyMessage(enemies);
|
||||||
String[] result = new String[(len + chunkSize - 1) / chunkSize];
|
sendFancyMessage(online);
|
||||||
int linha = 0;
|
sendFancyMessage(offline);
|
||||||
for (int i = 0; i < len; i += chunkSize) {
|
|
||||||
result[linha] = new String(data, i, Math.min(chunkSize, len - i));
|
|
||||||
linha++;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -379,6 +379,10 @@ public class Econ {
|
|||||||
return format.format(econ.getBalance(Bukkit.getOfflinePlayer(uuid)));
|
return format.format(econ.getBalance(Bukkit.getOfflinePlayer(uuid)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getFriendlyBalance(FPlayer player) {
|
||||||
|
return format.format(econ.getBalance(Bukkit.getOfflinePlayer(player.getName())));
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean setBalance(String account, double amount) {
|
public static boolean setBalance(String account, double amount) {
|
||||||
double current = econ.getBalance(Bukkit.getOfflinePlayer(account));
|
double current = econ.getBalance(Bukkit.getOfflinePlayer(account));
|
||||||
if (current > amount) {
|
if (current > amount) {
|
||||||
|
@ -1,8 +1,14 @@
|
|||||||
package com.massivecraft.factions.zcore;
|
package com.massivecraft.factions.zcore;
|
||||||
|
|
||||||
|
import com.massivecraft.factions.FPlayer;
|
||||||
|
import com.massivecraft.factions.Faction;
|
||||||
|
import com.massivecraft.factions.P;
|
||||||
|
import com.massivecraft.factions.integration.Econ;
|
||||||
import com.massivecraft.factions.zcore.util.TextUtil;
|
import com.massivecraft.factions.zcore.util.TextUtil;
|
||||||
import mkremins.fanciful.FancyMessage;
|
import mkremins.fanciful.FancyMessage;
|
||||||
|
import org.apache.commons.lang.time.DurationFormatUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@ -263,11 +269,45 @@ public abstract class MCommand<T extends MPlugin> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void sendFancyMessage(List<FancyMessage> messages) {
|
public void sendFancyMessage(List<FancyMessage> messages) {
|
||||||
for(FancyMessage m : messages) {
|
for (FancyMessage m : messages) {
|
||||||
sendFancyMessage(m);
|
sendFancyMessage(m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
// -------------------------------------------- //
|
// -------------------------------------------- //
|
||||||
|
@ -42,15 +42,29 @@ disable-pistons-in-territory: false
|
|||||||
# This section is to configure tooltips for things like /f list
|
# This section is to configure tooltips for things like /f list
|
||||||
tooltips:
|
tooltips:
|
||||||
|
|
||||||
|
# List
|
||||||
# This shows up when someone does /f list for the top factions.
|
# This shows up when someone does /f list for the top factions.
|
||||||
# It will not sure up for factionless of course, just actual factions.
|
# It will not sure up for factionless of course, just actual factions.
|
||||||
# You can use color codes here.
|
# You can use color codes here.
|
||||||
list:
|
list:
|
||||||
- "Leader: {leader}"
|
- "&6Leader: &f{leader}"
|
||||||
- "Claimed: {chunks}"
|
- "&6Claimed: &f{chunks}"
|
||||||
- "Raidable: {raidable}"
|
- "&6Raidable: &f{raidable}"
|
||||||
- "Warps: {warps}"
|
- "&6Warps: &f{warps}"
|
||||||
- "Power: {power}/{maxPower}"
|
- "&6Power: &f{power}/{maxPower}"
|
||||||
|
- "&6Members: &f{online}/{members}"
|
||||||
|
|
||||||
|
# Show
|
||||||
|
# This shows up when someone does /f show.
|
||||||
|
# It adds tooltips to each player in the list here, nothing else.
|
||||||
|
# {group} will show the players primary group if you have vault installed.
|
||||||
|
# {balance} will show their balance if you have vault installed.
|
||||||
|
# {lastSeen} will show human readable info on when the player was last seen, or online.
|
||||||
|
show:
|
||||||
|
- "&6Last Seen: &f{lastSeen}"
|
||||||
|
- "&6Power: &f{power}"
|
||||||
|
- "&6Rank: &f{group}"
|
||||||
|
- "&6Balance: &a${balance}"
|
||||||
|
|
||||||
# Configuration section for Scoreboards
|
# Configuration section for Scoreboards
|
||||||
# This will allow you to completely customize how your scoreboards look.
|
# This will allow you to completely customize how your scoreboards look.
|
||||||
|
Loading…
Reference in New Issue
Block a user