From 8300b2ff2b783de2f02c6956abee0a11525ca676 Mon Sep 17 00:00:00 2001 From: drtshock Date: Tue, 6 Jan 2015 16:06:46 -0600 Subject: [PATCH] Allow players to monitor joins and leaves of their faction members. Larger servers tend to have join and leave messages disabled for the entire server. A few have requested to allow faction members to monitor join and leave messages of their own members. --- .../com/massivecraft/factions/FPlayer.java | 4 +++ .../massivecraft/factions/cmd/CmdLogins.java | 25 +++++++++++++++++++ .../massivecraft/factions/cmd/FCmdRoot.java | 2 ++ .../listeners/FactionsPlayerListener.java | 20 ++++++++++++++- .../factions/struct/Permission.java | 1 + .../factions/zcore/persist/MemoryFPlayer.java | 10 ++++++++ .../massivecraft/factions/zcore/util/TL.java | 7 +++++- .../factions/zcore/util/TextUtil.java | 2 +- src/main/resources/plugin.yml | 3 +++ 9 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdLogins.java diff --git a/src/main/java/com/massivecraft/factions/FPlayer.java b/src/main/java/com/massivecraft/factions/FPlayer.java index 897d5e27..83b58c86 100644 --- a/src/main/java/com/massivecraft/factions/FPlayer.java +++ b/src/main/java/com/massivecraft/factions/FPlayer.java @@ -32,6 +32,10 @@ public interface FPlayer extends EconomyParticipator { public void setFaction(Faction faction); + public void setMonitorJoins(boolean monitor); + + public boolean isMonitoringJoins(); + public Role getRole(); public void setRole(Role role); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdLogins.java b/src/main/java/com/massivecraft/factions/cmd/CmdLogins.java new file mode 100644 index 00000000..8b6ddbe1 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdLogins.java @@ -0,0 +1,25 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.struct.Permission; +import com.massivecraft.factions.zcore.util.TL; + +public class CmdLogins extends FCommand { + + public CmdLogins() { + super(); + this.aliases.add("login"); + this.aliases.add("logins"); + this.aliases.add("logout"); + this.aliases.add("logouts"); + this.senderMustBePlayer = true; + this.senderMustBeMember = true; + this.permission = Permission.MONITOR_LOGINS.node; + } + + @Override + public void perform() { + boolean monitor = fme.isMonitoringJoins(); + fme.msg(TL.COMMAND_LOGINS_TOGGLE, String.valueOf(!monitor)); + fme.setMonitorJoins(!monitor); + } +} diff --git a/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java b/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java index 7fbe8bbb..78e89bc3 100644 --- a/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java +++ b/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java @@ -61,6 +61,7 @@ public class FCmdRoot extends FCommand { public CmdSetFWarp cmdSetFWarp = new CmdSetFWarp(); public CmdDelFWarp cmdDelFWarp = new CmdDelFWarp(); public CmdModifyPower cmdModifyPower = new CmdModifyPower(); + public CmdLogins cmdLogins = new CmdLogins(); public FCmdRoot() { super(); @@ -138,6 +139,7 @@ public class FCmdRoot extends FCommand { this.addSubCommand(this.cmdSetFWarp); this.addSubCommand(this.cmdDelFWarp); this.addSubCommand(this.cmdModifyPower); + this.addSubCommand(this.cmdLogins); } @Override diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java index 6b118292..e9eed6c6 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -10,6 +10,7 @@ import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.util.VisualizeUtil; +import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TextUtil; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -64,6 +65,15 @@ public class FactionsPlayerListener implements Listener { FScoreboard.get(me).setDefaultSidebar(new FDefaultSidebar(), P.p.getConfig().getInt("default-update-interval", 20)); } FScoreboard.get(me).setSidebarVisibility(P.p.cmdBase.cmdSB.showBoard(me)); + + Faction myFaction = me.getFaction(); + if (!myFaction.isNone()) { + for (FPlayer player : myFaction.getFPlayersWhereOnline(true)) { + if (player != me && player.isMonitoringJoins()) { + player.msg(TL.FACTION_LOGIN, me.getName()); + } + } + } } @EventHandler(priority = EventPriority.NORMAL) @@ -76,10 +86,18 @@ public class FactionsPlayerListener implements Listener { me.setLastLoginTime(System.currentTimeMillis()); Faction myFaction = me.getFaction(); - if (myFaction != null) { + if (!myFaction.isNone()) { myFaction.memberLoggedOff(); } + if (!myFaction.isNone()) { + for (FPlayer player : myFaction.getFPlayersWhereOnline(true)) { + if (player != me && player.isMonitoringJoins()) { + player.msg(TL.FACTION_LOGOUT, me.getName()); + } + } + } + FScoreboard.remove(me); } diff --git a/src/main/java/com/massivecraft/factions/struct/Permission.java b/src/main/java/com/massivecraft/factions/struct/Permission.java index d1b438cf..2da3aadc 100644 --- a/src/main/java/com/massivecraft/factions/struct/Permission.java +++ b/src/main/java/com/massivecraft/factions/struct/Permission.java @@ -45,6 +45,7 @@ public enum Permission { MONEY_F2F("money.f2f"), MONEY_F2P("money.f2p"), MONEY_P2F("money.p2f"), + MONITOR_LOGINS("monitorlogins"), NO_BOOM("noboom"), OPEN("open"), OWNER("owner"), 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 6bac91f7..47b0100c 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java @@ -66,6 +66,8 @@ public abstract class MemoryFPlayer implements FPlayer { protected String id; + protected boolean monitorJoins; + //private transient String playerName; protected transient FLocation lastStoodAt = new FLocation(); // Where did this player stand the last time we checked? @@ -113,6 +115,14 @@ public abstract class MemoryFPlayer implements FPlayer { this.factionId = faction.getId(); } + public void setMonitorJoins(boolean monitor) { + this.monitorJoins = monitor; + } + + public boolean isMonitoringJoins() { + return this.monitorJoins; + } + public Role getRole() { return this.role; } 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 bc274475..bfe0bff6 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TL.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TL.java @@ -246,6 +246,8 @@ public enum TL { COMMAND_LOCK_LOCKED("Factions is now locked"), COMMAND_LOCK_UNLOCKED("Factions in now unlocked"), + COMMAND_LOGINS_TOGGLE("Set login / logout notifications for Faction members to: %s"), + COMMAND_MAP_TOSHOW("to show the map"), COMMAND_MAP_FORSHOW("for showing the map"), COMMAND_MAP_UPDATE_ENABLED("Map auto update ENABLED."), @@ -453,7 +455,10 @@ public enum TL { SAFEZONE("safezone", "&6Safezone"), SAFEZONE_DESCRIPTION("safezone-description", "Free from pvp and monsters."), TOGGLE_SB("toggle-sb", "You now have scoreboards set to {value}"), - DEFAULT_PREFIX("default-prefix", "{relationcolor}[{faction}] &r"); + DEFAULT_PREFIX("default-prefix", "{relationcolor}[{faction}] &r"), + FACTION_LOGIN("faction-login", "&e%s &9logged in."), + FACTION_LOGOUT("faction-logout", "&e%s &9logged out.."), + ; private String path; private String def; diff --git a/src/main/java/com/massivecraft/factions/zcore/util/TextUtil.java b/src/main/java/com/massivecraft/factions/zcore/util/TextUtil.java index 483d1684..46131104 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TextUtil.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TextUtil.java @@ -61,7 +61,7 @@ public class TextUtil { string = parseColorAmp(string); string = parseColorAcc(string); string = parseColorTags(string); - return string; + return ChatColor.translateAlternateColorCodes('&', string); } public static String parseColorAmp(String string) { diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 4d1b5da7..db195e0e 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -90,6 +90,7 @@ permissions: factions.scoreboard: true factions.showinvites: true factions.seechunk: true + factions.monitorlogins: true factions.admin: description: hand over your admin rights factions.admin.any: @@ -241,3 +242,5 @@ permissions: description: access your faction warps factions.modifypower: description: modify other player's power + factions.monitorlogins: + description: monitor join and leaves of faction members