From a59c226747c6b73e65e9f5b0e17043857a6a2b83 Mon Sep 17 00:00:00 2001 From: Joshua Murphy Date: Thu, 22 Nov 2018 02:09:58 -0500 Subject: [PATCH] Added Focus/Config Fixes --- .../com/massivecraft/factions/Faction.java | 5 ++ .../massivecraft/factions/cmd/CmdFocus.java | 53 +++++++++++++++++++ .../massivecraft/factions/cmd/FCmdRoot.java | 4 ++ .../factions/scoreboards/FTeamWrapper.java | 27 +++++++--- .../factions/struct/Permission.java | 1 + .../factions/zcore/persist/MemoryFaction.java | 6 +++ .../massivecraft/factions/zcore/util/TL.java | 6 +++ src/main/resources/config.yml | 19 +++++-- src/main/resources/plugin.yml | 2 + 9 files changed, 111 insertions(+), 12 deletions(-) create mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdFocus.java diff --git a/src/main/java/com/massivecraft/factions/Faction.java b/src/main/java/com/massivecraft/factions/Faction.java index 08150ee9..8a160cba 100644 --- a/src/main/java/com/massivecraft/factions/Faction.java +++ b/src/main/java/com/massivecraft/factions/Faction.java @@ -51,6 +51,10 @@ public interface Faction extends EconomyParticipator { Set getInvites(); + String getFocused(); + + void setFocused(String setFocused); + String getId(); void setId(String id); @@ -330,4 +334,5 @@ public interface Faction extends EconomyParticipator { String getPaypal(); void paypalSet(String paypal); + } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFocus.java b/src/main/java/com/massivecraft/factions/cmd/CmdFocus.java new file mode 100644 index 00000000..44433907 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFocus.java @@ -0,0 +1,53 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.SavageFactions; +import com.massivecraft.factions.scoreboards.FTeamWrapper; +import com.massivecraft.factions.struct.Permission; +import com.massivecraft.factions.zcore.util.TL; + +public class CmdFocus + extends FCommand { + public CmdFocus() { + aliases.add("focus"); + + requiredArgs.add("player"); + + permission = Permission.FOCUS.node; + + senderMustBePlayer = true; + senderMustBeMember = false; + senderMustBeModerator = true; + senderMustBeColeader = false; + senderMustBeAdmin = false; + } + + public void perform() { + if (!SavageFactions.plugin.getConfig().getBoolean("ffocus.Enabled")) { + fme.msg(TL.GENERIC_DISABLED); + return; + } + FPlayer target = argAsFPlayer(0); + if (target == null) { + return; + } + if (target.getFaction().getId().equalsIgnoreCase(myFaction.getId())) { + fme.msg(TL.COMMAND_FOCUS_SAMEFACTION); + return; + } + if ((myFaction.getFocused() != null) && (myFaction.getFocused().equalsIgnoreCase(target.getName()))) { + myFaction.setFocused(null); + myFaction.msg(TL.COMMAND_FOCUS_NO_LONGER, target.getName()); + FTeamWrapper.updatePrefixes(target.getFaction()); + return; + } + myFaction.msg(TL.COMMAND_FOCUS_FOCUSSING, target.getName()); + myFaction.setFocused(target.getName()); + FTeamWrapper.updatePrefixes(target.getFaction()); + } + + public TL getUsageTranslation() { + return TL.COMMAND_FOCUS_DESCRIPTION; + } +} + diff --git a/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java b/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java index 6e589054..71c9f3cd 100644 --- a/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java +++ b/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java @@ -22,6 +22,7 @@ public class FCmdRoot extends FCommand { public CmdDeinvite cmdDeinvite = new CmdDeinvite(); public CmdDescription cmdDescription = new CmdDescription(); public CmdDisband cmdDisband = new CmdDisband(); + public CmdFocus cmdFocus = new CmdFocus(); public CmdHelp cmdHelp = new CmdHelp(); public CmdHome cmdHome = new CmdHome(); public CmdInvite cmdInvite = new CmdInvite(); @@ -223,6 +224,9 @@ public class FCmdRoot extends FCommand { } else { SavageFactions.plugin.log("CoreProtect not found, disabling Inspect"); } + if (SavageFactions.plugin.getConfig().getBoolean("ffocus.Enabled")) { + addSubCommand(this.cmdFocus); + } if (SavageFactions.plugin.getConfig().getBoolean("enable-faction-flight", false)) { this.addSubCommand(this.cmdFly); diff --git a/src/main/java/com/massivecraft/factions/scoreboards/FTeamWrapper.java b/src/main/java/com/massivecraft/factions/scoreboards/FTeamWrapper.java index 82a39c6d..f234abb6 100644 --- a/src/main/java/com/massivecraft/factions/scoreboards/FTeamWrapper.java +++ b/src/main/java/com/massivecraft/factions/scoreboards/FTeamWrapper.java @@ -3,7 +3,9 @@ package com.massivecraft.factions.scoreboards; import com.massivecraft.factions.*; import com.massivecraft.factions.zcore.util.TL; import me.clip.placeholderapi.PlaceholderAPI; +import net.milkbowl.vault.chat.Chat; import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.OfflinePlayer; import org.bukkit.scoreboard.Scoreboard; import org.bukkit.scoreboard.Team; @@ -166,20 +168,31 @@ public class FTeamWrapper { if (SavageFactions.plugin.getConfig().getBoolean("scoreboard.default-prefixes", false)) { FPlayer fplayer = fboard.getFPlayer(); Team team = teams.get(fboard); + boolean focused = false; + if ((SavageFactions.plugin.getConfig().getBoolean("ffocus.Enabled")) && (fplayer.getFaction() != null) && (fplayer.getFaction().getFocused() != null)) { + for (FPlayer fp : this.faction.getFPlayersWhereOnline(true)) { + if (fplayer.getFaction().getFocused().equalsIgnoreCase(fp.getName())) { + team.setPrefix(ChatColor.translateAlternateColorCodes('&', SavageFactions.plugin.getConfig().getString("ffocus.Prefix", "&7»&b"))); + focused = true; + } + } + } + if (!focused) { + String prefix = TL.DEFAULT_PREFIX.toString(); - String prefix = TL.DEFAULT_PREFIX.toString(); - if (SavageFactions.plugin.PlaceholderApi) { prefix = PlaceholderAPI.setPlaceholders(fplayer.getPlayer(), prefix); prefix = PlaceholderAPI.setBracketPlaceholders(fplayer.getPlayer(), prefix); - } - prefix = prefix.replace("{relationcolor}", faction.getRelationTo(fplayer).getColor().toString()); - prefix = prefix.replace("{faction}", faction.getTag().substring(0, Math.min("{faction}".length() + 16 - prefix.length(), faction.getTag().length()))); - if (team.getPrefix() == null || !team.getPrefix().equals(prefix)) { - team.setPrefix(prefix); + prefix = prefix.replace("{relationcolor}", this.faction.getRelationTo(fplayer).getColor().toString()); + prefix = prefix.replace("{faction}", + this.faction.getTag().substring(0, Math.min("{faction}".length() + 16 - prefix.length(), this.faction.getTag().length()))); + if ((team.getPrefix() == null) || (!team.getPrefix().equals(prefix))) { + team.setPrefix(prefix); + } } } } + private void addPlayer(OfflinePlayer player) { if (members.add(player)) { for (Team team : teams.values()) { diff --git a/src/main/java/com/massivecraft/factions/struct/Permission.java b/src/main/java/com/massivecraft/factions/struct/Permission.java index f3c5c22e..bcb23a95 100644 --- a/src/main/java/com/massivecraft/factions/struct/Permission.java +++ b/src/main/java/com/massivecraft/factions/struct/Permission.java @@ -29,6 +29,7 @@ public enum Permission { DISBAND("disband"), DISBAND_ANY("disband.any"), FLY("fly"), + FOCUS("focus"), HELP("help"), HOME("home"), INVITE("invite"), 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 bf937442..8946fc8b 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java @@ -62,6 +62,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { protected Role defaultRole; protected Map> permissions = new HashMap<>(); protected Set bans = new HashSet<>(); + protected String player; Inventory chest; Map bannerSerialized; private long lastDeath; @@ -193,6 +194,10 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { this.maxVaults = value; } + public String getFocused() { return this.player; } + + public void setFocused(String fp) { this.player = fp; } + public Set getInvites() { return invites; } @@ -324,6 +329,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { return tnt; } + public Location getVault() { if (vault == null) { return null; diff --git a/src/main/java/com/massivecraft/factions/zcore/util/TL.java b/src/main/java/com/massivecraft/factions/zcore/util/TL.java index d75e0714..91fcd50a 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TL.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TL.java @@ -290,6 +290,12 @@ public enum TL { COMMAND_FLY_CHECK_ENEMY("&c&l[!]&7 Cannot fly here, an enemy is &cnearby"), COMMAND_FLY_NO_EPEARL("&c&l[!] &7You &ccannot&7 throw enderpearls while flying!"), + COMMAND_FOCUS_SAMEFACTION("&c[!] You may not focus players in your faction!"), + COMMAND_FOCUS_FOCUSSING("&c&l[!] &7Your faction is now focusing &c%s"), + COMMAND_FOCUS_NO_LONGER("&c&l[!] &7Your faction is no longer focusing &c%s"), + COMMAND_FOCUS_DESCRIPTION("Focus a Specific Player"), + + COMMAND_FWARP_CLICKTOWARP("&c&l[!]&7 Click to &cwarp!"), COMMAND_FWARP_COMMANDFORMAT("&c&l[!]&7 /f warp &c[password]"), COMMAND_FWARP_WARPED("&c&l[!]&7 Warped to &c%1$s"), diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index b0254563..aaeb4f36 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -692,11 +692,11 @@ fwarp-gui: name: ' ' lore: - - ############################################################ - # +------------------------------------------------------+ # - # | Faction Rules | # - # +------------------------------------------------------+ # - ############################################################ +############################################################ +# +------------------------------------------------------+ # +# | Faction Rules | # +# +------------------------------------------------------+ # +############################################################ frules: Enabled: true default-rules: @@ -736,6 +736,15 @@ fnear: Enabled: true Radius: 50 +############################################################ +# +------------------------------------------------------+ # +# | Faction Focus | # +# +------------------------------------------------------+ # +############################################################ +#Note This will ONLY work if you have SavageFactions Scoreboard Enabled! +ffocus: + Enabled: true + Prefix: '&7»&b' ############################################################ # +------------------------------------------------------+ # diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 37752b54..57c0b3ef 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -320,6 +320,8 @@ permissions: description: kill invisible holograms factions.stealth: description: Enter faction stealth mode + factions.focus: + description: Focus a certain player in another faction factions.coords: description: broadcast your coords to the player factions.chest: