From 47f0bf1ce5582882a274a36d575da1c9f60551f3 Mon Sep 17 00:00:00 2001 From: Trent Hensler Date: Sat, 10 Feb 2018 15:59:21 -0800 Subject: [PATCH] Tooltips in f map --- .../java/com/massivecraft/factions/Board.java | 3 +- .../com/massivecraft/factions/FPlayer.java | 6 + .../java/com/massivecraft/factions/P.java | 1 - .../massivecraft/factions/cmd/CmdFWarp.java | 1 - .../com/massivecraft/factions/cmd/CmdMap.java | 2 +- .../factions/cmd/CmdMoneyWithdraw.java | 1 - .../massivecraft/factions/cmd/CmdPerm.java | 2 - .../listeners/FactionsPlayerListener.java | 2 +- .../zcore/fperms/PermissableAction.java | 3 +- .../factions/zcore/persist/MemoryBoard.java | 108 +++++++++++++----- .../factions/zcore/persist/MemoryFPlayer.java | 22 ++++ .../factions/zcore/persist/MemoryFaction.java | 1 + 12 files changed, 116 insertions(+), 36 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/Board.java b/src/main/java/com/massivecraft/factions/Board.java index 833ca64d..27ac3cee 100644 --- a/src/main/java/com/massivecraft/factions/Board.java +++ b/src/main/java/com/massivecraft/factions/Board.java @@ -1,6 +1,7 @@ package com.massivecraft.factions; import com.massivecraft.factions.zcore.persist.json.JSONBoard; +import mkremins.fanciful.FancyMessage; import org.bukkit.World; import java.util.ArrayList; @@ -79,7 +80,7 @@ public abstract class Board { * The map is relative to a coord and a faction north is in the direction of decreasing x east is in the direction * of decreasing z */ - public abstract ArrayList getMap(Faction faction, FLocation flocation, double inDegrees); + public abstract ArrayList getMap(FPlayer fPlayer, FLocation flocation, double inDegrees); public abstract void forceSave(); diff --git a/src/main/java/com/massivecraft/factions/FPlayer.java b/src/main/java/com/massivecraft/factions/FPlayer.java index 8f6e7168..165bb952 100644 --- a/src/main/java/com/massivecraft/factions/FPlayer.java +++ b/src/main/java/com/massivecraft/factions/FPlayer.java @@ -6,6 +6,7 @@ import com.massivecraft.factions.struct.ChatMode; import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.util.WarmUpUtil; +import mkremins.fanciful.FancyMessage; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -239,6 +240,11 @@ public interface FPlayer extends EconomyParticipator { public void sendMessage(List messages); + public void sendFancyMessage(FancyMessage message); + + public void sendFancyMessage(List message); + + public boolean isOnlineAndVisibleTo(Player me); public void remove(); diff --git a/src/main/java/com/massivecraft/factions/P.java b/src/main/java/com/massivecraft/factions/P.java index 95c7b04d..081a3548 100644 --- a/src/main/java/com/massivecraft/factions/P.java +++ b/src/main/java/com/massivecraft/factions/P.java @@ -10,7 +10,6 @@ import com.massivecraft.factions.integration.Worldguard; import com.massivecraft.factions.integration.dynmap.EngineDynmap; import com.massivecraft.factions.listeners.*; import com.massivecraft.factions.struct.ChatMode; -import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.util.*; import com.massivecraft.factions.zcore.MPlugin; import com.massivecraft.factions.zcore.fperms.Access; diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFWarp.java b/src/main/java/com/massivecraft/factions/cmd/CmdFWarp.java index 5b698274..d1fc1cc2 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFWarp.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFWarp.java @@ -4,7 +4,6 @@ import com.massivecraft.factions.Conf; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.P; import com.massivecraft.factions.struct.Permission; -import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.util.LazyLocation; import com.massivecraft.factions.util.WarmUpUtil; import com.massivecraft.factions.zcore.fperms.Access; diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdMap.java b/src/main/java/com/massivecraft/factions/cmd/CmdMap.java index 9724cdac..fcc6ab7b 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdMap.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdMap.java @@ -57,7 +57,7 @@ public class CmdMap extends FCommand { } public void showMap() { - sendMessage(Board.getInstance().getMap(myFaction, new FLocation(fme), fme.getPlayer().getLocation().getYaw())); + sendFancyMessage(Board.getInstance().getMap(fme, new FLocation(fme), fme.getPlayer().getLocation().getYaw())); } @Override diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdMoneyWithdraw.java b/src/main/java/com/massivecraft/factions/cmd/CmdMoneyWithdraw.java index 63e5cdb8..d4f6d8f9 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdMoneyWithdraw.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdMoneyWithdraw.java @@ -5,7 +5,6 @@ import com.massivecraft.factions.P; import com.massivecraft.factions.iface.EconomyParticipator; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.struct.Permission; -import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.util.TL; diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdPerm.java b/src/main/java/com/massivecraft/factions/cmd/CmdPerm.java index cb450fd5..4ba08d2b 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdPerm.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdPerm.java @@ -1,7 +1,5 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.Faction; -import com.massivecraft.factions.Factions; import com.massivecraft.factions.P; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Relation; diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java index 3ba49a03..7d325c6b 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -180,7 +180,7 @@ public class FactionsPlayerListener implements Listener { P.p.log(Level.WARNING, "%s tried to show a faction map too soon and triggered exploit blocker.", player.getName()); } } else { - me.sendMessage(Board.getInstance().getMap(me.getFaction(), to, player.getLocation().getYaw())); + me.sendFancyMessage(Board.getInstance().getMap(me, to, player.getLocation().getYaw())); showTimes.put(player.getUniqueId(), System.currentTimeMillis() + P.p.getConfig().getLong("findfactionsexploit.cooldown", 2000)); } } else { diff --git a/src/main/java/com/massivecraft/factions/zcore/fperms/PermissableAction.java b/src/main/java/com/massivecraft/factions/zcore/fperms/PermissableAction.java index dfb3e2fc..9717fae6 100644 --- a/src/main/java/com/massivecraft/factions/zcore/fperms/PermissableAction.java +++ b/src/main/java/com/massivecraft/factions/zcore/fperms/PermissableAction.java @@ -20,8 +20,7 @@ public enum PermissableAction { PROMOTE("promote"), PERMS("perms"), SETWARP("setwarp"), - WARP("warp"), - ; + WARP("warp"),; private String name; diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryBoard.java b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryBoard.java index 0775d3b5..ff2b1ce1 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryBoard.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryBoard.java @@ -6,6 +6,10 @@ import com.massivecraft.factions.*; import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.util.AsciiCompass; import com.massivecraft.factions.util.LazyLocation; +import com.massivecraft.factions.zcore.util.TL; +import com.massivecraft.factions.zcore.util.TagReplacer; +import com.massivecraft.factions.zcore.util.TagUtil; +import mkremins.fanciful.FancyMessage; import org.bukkit.ChatColor; import org.bukkit.World; @@ -240,10 +244,19 @@ public abstract class MemoryBoard extends Board { * The map is relative to a coord and a faction north is in the direction of decreasing x east is in the direction * of decreasing z */ - public ArrayList getMap(Faction faction, FLocation flocation, double inDegrees) { - ArrayList ret = new ArrayList<>(); + public ArrayList getMap(FPlayer fplayer, FLocation flocation, double inDegrees) { + Faction faction = fplayer.getFaction(); + ArrayList ret = new ArrayList<>(); Faction factionLoc = getFactionAt(flocation); - ret.add(P.p.txt.titleize("(" + flocation.getCoordString() + ") " + factionLoc.getTag(faction))); + ret.add(new FancyMessage(P.p.txt.titleize("(" + flocation.getCoordString() + ") " + factionLoc.getTag(fplayer)))); + + // Get the compass + ArrayList asciiCompass = AsciiCompass.getAsciiCompass(inDegrees, ChatColor.RED, P.p.txt.parse("")); + + // Add the compass + ret.add(new FancyMessage(asciiCompass.get(0))); + ret.add(new FancyMessage(asciiCompass.get(1))); + ret.add(new FancyMessage(asciiCompass.get(2))); int halfWidth = Conf.mapWidth / 2; int halfHeight = Conf.mapHeight / 2; @@ -261,53 +274,96 @@ public abstract class MemoryBoard extends Board { // For each row for (int dz = 0; dz < height; dz++) { // Draw and add that row - StringBuilder row = new StringBuilder(); + FancyMessage row = new FancyMessage(""); for (int dx = 0; dx < width; dx++) { if (dx == halfWidth && dz == halfHeight) { - row.append(ChatColor.AQUA + "+"); + row.then("+").color(ChatColor.AQUA); } else { FLocation flocationHere = topLeft.getRelative(dx, dz); Faction factionHere = getFactionAt(flocationHere); - Relation relation = faction.getRelationTo(factionHere); + Relation relation = fplayer.getRelationTo(factionHere); if (factionHere.isWilderness()) { - row.append(ChatColor.GRAY + "-"); + row.then("-").color(ChatColor.GRAY); } else if (factionHere.isSafeZone()) { - row.append(Conf.colorPeaceful).append("+"); + row.then("+").color(Conf.colorPeaceful); } else if (factionHere.isWarZone()) { - row.append(ChatColor.DARK_RED + "+"); - } else if (factionHere == faction || - factionHere == factionLoc || - relation.isAtLeast(Relation.ALLY) || + row.then("+").color(ChatColor.DARK_RED); + } else if (factionHere == faction || factionHere == factionLoc || relation.isAtLeast(Relation.ALLY) || (Conf.showNeutralFactionsOnMap && relation.equals(Relation.NEUTRAL)) || (Conf.showEnemyFactionsOnMap && relation.equals(Relation.ENEMY))) { if (!fList.containsKey(factionHere.getTag())) { fList.put(factionHere.getTag(), Conf.mapKeyChrs[Math.min(chrIdx++, Conf.mapKeyChrs.length - 1)]); } char tag = fList.get(factionHere.getTag()); - row.append(factionHere.getColorTo(faction)).append("").append(tag); + + row.then(String.valueOf(tag)).color(factionHere.getColorTo(faction)).tooltip(getToolTip(factionHere, fplayer)); } else { - row.append(ChatColor.GRAY + "-"); + row.then("-").color(ChatColor.GRAY); } } } - ret.add(row.toString()); + ret.add(row); } - // Get the compass - ArrayList asciiCompass = AsciiCompass.getAsciiCompass(inDegrees, ChatColor.RED, P.p.txt.parse("")); - - // Add the compass - ret.set(1, asciiCompass.get(0) + ret.get(1).substring(3 * 3)); - ret.set(2, asciiCompass.get(1) + ret.get(2).substring(3 * 3)); - ret.set(3, asciiCompass.get(2) + ret.get(3).substring(3 * 3)); - // Add the faction key if (Conf.showMapFactionKey) { - StringBuilder fRow = new StringBuilder(); + FancyMessage fRow = new FancyMessage(""); for (String key : fList.keySet()) { - fRow.append(String.format("%s%s: %s ", ChatColor.GRAY, fList.get(key), key)); + fRow.then(String.format("%s: %s ", fList.get(key), key)).color(ChatColor.GRAY); + } + ret.add(fRow); + } + + return ret; + } + + private List getToolTip(Faction faction, FPlayer to) { + List ret = new ArrayList<>(); + List show = P.p.getConfig().getStringList("show"); + + if (!faction.isNormal()) { + String tag = faction.getTag(to); + // send header and that's all + String header = show.get(0); + if (TagReplacer.HEADER.contains(header)) { + ret.add(P.p.txt.titleize(tag)); + } else { + ret.add(P.p.txt.parse(TagReplacer.FACTION.replace(header, tag))); + } + return ret; // we only show header for non-normal factions + } + + for (String raw : show) { + // Hack to get rid of the extra underscores in title normally used to center tag + if(raw.contains("{header}")) { + raw = raw.replace("{header}", faction.getTag(to)); + } + + String parsed = TagUtil.parsePlain(faction, to, raw); // use relations + if (parsed == null) { + continue; // Due to minimal f show. + } + + if (TagUtil.hasFancy(parsed)) { + List fancy = TagUtil.parseFancy(faction, to, parsed); + if (fancy != null) { + for(FancyMessage msg : fancy) { + ret.add((P.p.txt.parse(msg.toOldMessageFormat()))); + } + } + continue; + } + + if (!parsed.contains("{notFrozen}") && !parsed.contains("{notPermanent}")) { + if (parsed.contains("{ig}")) { + // replaces all variables with no home TL + parsed = parsed.substring(0, parsed.indexOf("{ig}")) + TL.COMMAND_SHOW_NOHOME.toString(); + } + if (parsed.contains("%")) { + parsed = parsed.replaceAll("%", ""); // Just in case it got in there before we disallowed it. + } + ret.add(P.p.txt.parse(parsed)); } - ret.add(fRow.toString()); } return ret; diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java index 28af05ef..37e2c2aa 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java @@ -17,6 +17,7 @@ import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.util.RelationUtil; import com.massivecraft.factions.util.WarmUpUtil; import com.massivecraft.factions.zcore.util.TL; +import mkremins.fanciful.FancyMessage; import org.bukkit.*; import org.bukkit.entity.Player; @@ -892,6 +893,27 @@ public abstract class MemoryFPlayer implements FPlayer { } } + public void sendFancyMessage(FancyMessage message) { + Player player = getPlayer(); + if (player == null || !player.isOnGround()) { + return; + } + + message.send(player); + } + + public void sendFancyMessage(List messages) { + Player player = getPlayer(); + if (player == null || !player.isOnGround()) { + return; + } + + for (FancyMessage msg : messages) { + msg.send(player); + } + } + + public String getNameAndTitle(FPlayer fplayer) { return this.getColorTo(fplayer) + this.getNameAndTitle(); } diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java index 8754d2bb..49ba0435 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java @@ -383,6 +383,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { /** * Read only map of Permissions. + * * @return */ public Map> getPermissions() {