From 64e234144eaa0223a3690d6664f7f626996fef50 Mon Sep 17 00:00:00 2001 From: drtshock Date: Thu, 13 Nov 2014 12:45:57 -0600 Subject: [PATCH] /f list tool tips --- .../massivecraft/factions/cmd/CmdInvite.java | 2 +- .../massivecraft/factions/cmd/CmdList.java | 35 ++++++++++++++++--- .../massivecraft/factions/zcore/MCommand.java | 11 ++++++ src/main/resources/config.yml | 14 ++++++++ 4 files changed, 56 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdInvite.java b/src/main/java/com/massivecraft/factions/cmd/CmdInvite.java index 06b2b58c..de96e58a 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdInvite.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdInvite.java @@ -51,7 +51,7 @@ public class CmdInvite extends FCommand { // Tooltips, colors, and commands only apply to the string immediately before it. FancyMessage message = new FancyMessage(fme.describeTo(you, true)).tooltip("Click to join!").command("f join " + myFaction.getTag()).then(" has invited you to join ").color(ChatColor.YELLOW).tooltip("Click to join!").command("f join " + myFaction.getTag()).then(myFaction.describeTo(you)).tooltip("Click to join!").command("f join " + myFaction.getTag()); - message.send(you.getPlayer()); + sendFancyMessage(message); //you.msg("%s invited you to %s", fme.describeTo(you, true), myFaction.describeTo(you)); myFaction.msg("%s invited %s to your faction.", fme.describeTo(myFaction, true), you.describeTo(myFaction)); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdList.java b/src/main/java/com/massivecraft/factions/cmd/CmdList.java index ee21a5c1..b1099949 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdList.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdList.java @@ -1,13 +1,17 @@ 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; +import mkremins.fanciful.FancyMessage; +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 { @@ -71,7 +75,7 @@ public class CmdList extends FCommand { } }); - ArrayList lines = new ArrayList(); + ArrayList lines = new ArrayList(); factionList.add(0, Factions.getInstance().getNone()); @@ -89,16 +93,37 @@ public class CmdList extends FCommand { end = factionList.size(); } - lines.add(p.txt.titleize("Faction List " + pagenumber + "/" + pagecount)); + lines.add(new FancyMessage(p.txt.titleize("Faction List " + pagenumber + "/" + pagecount))); for (Faction faction : factionList.subList(start, end)) { if (faction.isNone()) { - lines.add(p.txt.parse("Factionless %d online", Factions.getInstance().getNone().getFPlayersWhereOnline(true).size())); + String online = String.valueOf(faction.getFPlayersWhereOnline(true).size()); + FancyMessage msg = new FancyMessage("Factionless " + online + " online").color(ChatColor.YELLOW); + lines.add(msg); continue; } - lines.add(p.txt.parse("%s %d/%d online, %d/%d/%d", faction.getTag(fme), faction.getFPlayersWhereOnline(true).size(), faction.getFPlayers().size(), faction.getLandRounded(), faction.getPowerRounded(), faction.getPowerMaxRounded())); + String online = " " + faction.getFPlayersWhereOnline(true).size() + "/" + faction.getFPlayers().size() + " online"; + + FancyMessage msg = new FancyMessage(faction.getTag(fme) + online).color(ChatColor.YELLOW).tooltip(getToolTips(faction)); + lines.add(msg); + //lines.add(p.txt.parse("%s %d/%d online, %d/%d/%d", faction.getTag(fme), faction.getFPlayersWhereOnline(true).size(), faction.getFPlayers().size(), faction.getLandRounded(), faction.getPowerRounded(), faction.getPowerMaxRounded())); } - sendMessage(lines); + sendFancyMessage(lines); + } + + private List getToolTips(Faction faction) { + List lines = new ArrayList(); + for (String s : p.getConfig().getStringList("tooltips.list")) { + lines.add(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())); } } diff --git a/src/main/java/com/massivecraft/factions/zcore/MCommand.java b/src/main/java/com/massivecraft/factions/zcore/MCommand.java index 4cdb2706..d04ba048 100644 --- a/src/main/java/com/massivecraft/factions/zcore/MCommand.java +++ b/src/main/java/com/massivecraft/factions/zcore/MCommand.java @@ -1,6 +1,7 @@ package com.massivecraft.factions.zcore; import com.massivecraft.factions.zcore.util.TextUtil; +import mkremins.fanciful.FancyMessage; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -257,6 +258,16 @@ public abstract class MCommand { } } + public void sendFancyMessage(FancyMessage message) { + message.send(sender); + } + + public void sendFancyMessage(List messages) { + for(FancyMessage m : messages) { + sendFancyMessage(m); + } + } + // -------------------------------------------- // // Argument Readers // -------------------------------------------- // diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index e4bcf8f9..6d8fa378 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -38,6 +38,20 @@ warp-cost: # http://i.gyazo.com/6a1a31222e58a5d60ff341c13f6a8404.gif disable-pistons-in-territory: false +# ToolTips +# This section is to configure tooltips for things like /f list +tooltips: + + # This shows up when someone does /f list for the top factions. + # It will not sure up for factionless of course, just actual factions. + # You can't use color codes here. + list: + - "Leader: {leader}" + - "Claimed: {chunks}" + - "Raidable: {raidable}" + - "Warps: {warps}" + - "Power: {power}/{maxPower}" + # Configuration section for Scoreboards # This will allow you to completely customize how your scoreboards look. # Make sure that no lines are duplicates of each other otherwise only the first will display.