From 5bf3161cf065b95323bb06b6d56e579657f96e7a Mon Sep 17 00:00:00 2001 From: Harry Jeffery Date: Sun, 27 Nov 2011 19:32:41 +0000 Subject: [PATCH] Added chat spy feature for admins --- plugin.yml | 5 ++- src/com/massivecraft/factions/FPlayer.java | 5 +++ .../massivecraft/factions/cmd/CmdChatSpy.java | 40 +++++++++++++++++++ .../massivecraft/factions/cmd/FCmdRoot.java | 2 + .../listeners/FactionsChatEarlyListener.java | 15 ++++++- .../factions/struct/Permission.java | 1 + 6 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 src/com/massivecraft/factions/cmd/CmdChatSpy.java diff --git a/plugin.yml b/plugin.yml index 20a84d8a..276bfdfa 100644 --- a/plugin.yml +++ b/plugin.yml @@ -26,10 +26,11 @@ permissions: factions.kit.halfmod: true factions.flag.set: true factions.kit.halfmod: - description: Can use adminmode + description: Can use adminmode and chat spy children: factions.kit.fullplayer: true factions.adminmode: true + factions.chatspy: true factions.kit.fullplayer: default: true description: Can also create new factions. @@ -71,6 +72,8 @@ permissions: factions.version: true factions.adminmode: description: enable admin bypass mode + factions.chatspy: + description: enable admin chat spy mode factions.autoclaim: description: auto-claim land as you walk around factions.chat: diff --git a/src/com/massivecraft/factions/FPlayer.java b/src/com/massivecraft/factions/FPlayer.java index a236c7fd..3ca7780c 100644 --- a/src/com/massivecraft/factions/FPlayer.java +++ b/src/com/massivecraft/factions/FPlayer.java @@ -100,6 +100,11 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator return chatMode; } + // FIELD: chatSpy + private transient boolean spyingChat = false; + public void setSpyingChat(boolean chatSpying) { this.spyingChat = chatSpying; } + public boolean isSpyingChat() { return spyingChat; } + // FIELD: account public MethodAccount getAccount() { diff --git a/src/com/massivecraft/factions/cmd/CmdChatSpy.java b/src/com/massivecraft/factions/cmd/CmdChatSpy.java new file mode 100644 index 00000000..e41dddbb --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdChatSpy.java @@ -0,0 +1,40 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.P; +import com.massivecraft.factions.struct.Permission; + +public class CmdChatSpy extends FCommand +{ + public CmdChatSpy() + { + super(); + this.aliases.add("chatspy"); + + this.optionalArgs.put("on/off", "flip"); + + this.permission = Permission.CHATSPY.node; + this.disableOnLock = false; + + senderMustBePlayer = true; + senderMustBeMember = false; + senderMustBeOfficer = false; + senderMustBeLeader = false; + } + + @Override + public void perform() + { + fme.setSpyingChat(this.argAsBool(0, ! fme.isSpyingChat())); + + if ( fme.isSpyingChat()) + { + fme.msg("You have enabled chat spying mode."); + P.p.log(fme.getName() + " has ENABLED chat spying mode."); + } + else + { + fme.msg("You have disabled chat spying mode."); + P.p.log(fme.getName() + " DISABLED chat spying mode."); + } + } +} diff --git a/src/com/massivecraft/factions/cmd/FCmdRoot.java b/src/com/massivecraft/factions/cmd/FCmdRoot.java index b0b993de..0b71dbb6 100644 --- a/src/com/massivecraft/factions/cmd/FCmdRoot.java +++ b/src/com/massivecraft/factions/cmd/FCmdRoot.java @@ -10,6 +10,7 @@ public class FCmdRoot extends FCommand public CmdAutoClaim cmdAutoClaim = new CmdAutoClaim(); public CmdAdmin cmdBypass = new CmdAdmin(); public CmdChat cmdChat = new CmdChat(); + public CmdChatSpy cmdChatSpy = new CmdChatSpy(); public CmdClaim cmdClaim = new CmdClaim(); public CmdConfig cmdConfig = new CmdConfig(); public CmdCreate cmdCreate = new CmdCreate(); @@ -72,6 +73,7 @@ public class FCmdRoot extends FCommand this.addSubCommand(this.cmdAutoClaim); this.addSubCommand(this.cmdBypass); this.addSubCommand(this.cmdChat); + this.addSubCommand(this.cmdChatSpy); this.addSubCommand(this.cmdClaim); this.addSubCommand(this.cmdConfig); this.addSubCommand(this.cmdCreate); diff --git a/src/com/massivecraft/factions/listeners/FactionsChatEarlyListener.java b/src/com/massivecraft/factions/listeners/FactionsChatEarlyListener.java index 41dd6adc..83637fab 100644 --- a/src/com/massivecraft/factions/listeners/FactionsChatEarlyListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsChatEarlyListener.java @@ -52,6 +52,13 @@ public class FactionsChatEarlyListener extends PlayerListener P.p.log(Level.INFO, ChatColor.stripColor("FactionChat "+me.getFaction().getTag()+": "+message)); + //Send to any players who are spying chat + for (FPlayer fplayer : FPlayers.i.getOnline()) + { + if( fplayer.isSpyingChat() ) + fplayer.sendMessage("FactionChat "+me.getFaction().getTag()+": "+message); + } + event.setCancelled(true); return; @@ -69,10 +76,14 @@ public class FactionsChatEarlyListener extends PlayerListener for (FPlayer fplayer : FPlayers.i.getOnline()) { if(myFaction.getRelationTo(fplayer) == Rel.ALLY) - fplayer.sendMessage(message); + fplayer.sendMessage(message); + + //Send to any players who are spying chat + if( fplayer.isSpyingChat() ) + fplayer.sendMessage("AllianceChat " + message); } - P.p.log(Level.INFO, ChatColor.stripColor("AllianceChat: "+message)); + P.p.log(Level.INFO, ChatColor.stripColor("AllianceChat "+message)); event.setCancelled(true); return; diff --git a/src/com/massivecraft/factions/struct/Permission.java b/src/com/massivecraft/factions/struct/Permission.java index e66c3313..b977257b 100644 --- a/src/com/massivecraft/factions/struct/Permission.java +++ b/src/com/massivecraft/factions/struct/Permission.java @@ -8,6 +8,7 @@ public enum Permission ADMIN("adminmode"), AUTOCLAIM("autoclaim"), CHAT("chat"), + CHATSPY("chatspy"), CLAIM("claim"), CONFIG("config"), CREATE("create"),