diff --git a/src/main/java/me/totalfreedom/totalfreedommod/CommandSpy.java b/src/main/java/me/totalfreedom/totalfreedommod/CommandSpy.java index d90cf4f17..28d8aac5f 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/CommandSpy.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/CommandSpy.java @@ -1,10 +1,13 @@ package me.totalfreedom.totalfreedommod; +import me.totalfreedom.totalfreedommod.admin.Admin; +import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerJoinEvent; public class CommandSpy extends FreedomService { @@ -41,4 +44,28 @@ public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) } } + // This will check if the user joining has command spy enabled, and if they are an admin. If they are not an admin it will ensure their command spy access has been removed, and if they are it will check to see if the admin has left command spy enabled or not on previous use. + @EventHandler(priority = EventPriority.MONITOR) + public void onPlayerJoin(PlayerJoinEvent event) + { + Admin admin = getAdmin((Player) event.getPlayer()); + FPlayer playerdata = plugin.pl.getPlayer(event.getPlayer()); + + if (plugin.al.isAdmin(event.getPlayer())) + { + if (admin.hasCommandSpy()) + { + playerdata.setCommandSpy(playerdata.cmdspyEnabled() == true); + } + else + { + playerdata.setCommandSpy(playerdata.cmdspyEnabled() == false); + } + } + else + { + playerdata.setCommandSpy(playerdata.cmdspyEnabled() == false); + } + } + } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/LoginProcess.java b/src/main/java/me/totalfreedom/totalfreedommod/LoginProcess.java index 67469bdf1..b405899fe 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/LoginProcess.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/LoginProcess.java @@ -196,7 +196,7 @@ public void run() if (lockdownEnabled) { - FUtil.playerMsg(player, "Warning: Server is currenty in lockdown-mode, new players will not be able to join!", ChatColor.RED); + FUtil.playerMsg(player, "Warning: Server is currently in lockdown-mode, new players will not be able to join!", ChatColor.RED); } } }.runTaskLater(plugin, 20L * 1L); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java b/src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java index 35b61d631..97ed2e3c0 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java @@ -1,8 +1,10 @@ package me.totalfreedom.totalfreedommod.admin; import com.google.common.collect.Lists; + import java.util.Date; import java.util.List; + import lombok.Getter; import lombok.Setter; import me.totalfreedom.totalfreedommod.LogViewer.LogsRegistrationMode; @@ -39,6 +41,9 @@ public class Admin implements ConfigLoadable, ConfigSavable, Validatable @Getter @Setter private String loginMessage = null; + @Getter + @Setter + private boolean commandSpy = true; public Admin(Player player) { @@ -62,7 +67,8 @@ public String toString() .append("- Last Login: ").append(FUtil.dateToString(lastLogin)).append("\n") .append("- Custom Login Message: ").append(loginMessage).append("\n") .append("- Rank: ").append(rank.getName()).append("\n") - .append("- Is Active: ").append(active); + .append("- Is Active: ").append(active).append("\n") + .append("- CommandSpy: ").append(commandSpy); return output.toString(); } @@ -97,6 +103,7 @@ public void saveTo(ConfigurationSection cs) cs.set("ips", Lists.newArrayList(ips)); cs.set("last_login", FUtil.dateToString(lastLogin)); cs.set("login_message", loginMessage); + cs.set("commandspy", commandSpy); } public boolean isAtLeast(Rank pRank) @@ -109,6 +116,16 @@ public boolean hasLoginMessage() return loginMessage != null && !loginMessage.isEmpty(); } + public boolean hasCommandSpy() + { + return commandSpy; + } + + public boolean setCommandSpy(boolean commandSpyStatus) + { + return commandSpy = commandSpyStatus; + } + // Util IP methods public void addIp(String ip) { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java b/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java index 95872050f..75425182b 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java @@ -3,10 +3,12 @@ import com.google.common.base.Function; import com.google.common.collect.Maps; import com.google.common.collect.Sets; + import java.util.Date; import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; + import lombok.Getter; import me.totalfreedom.totalfreedommod.FreedomService; import me.totalfreedom.totalfreedommod.TotalFreedomMod; diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cmdspy.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cmdspy.java index c316a46ae..c046bd15c 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cmdspy.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cmdspy.java @@ -1,5 +1,6 @@ package me.totalfreedom.totalfreedommod.command; +import me.totalfreedom.totalfreedommod.admin.Admin; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.rank.Rank; import org.bukkit.command.Command; @@ -14,9 +15,18 @@ public class Command_cmdspy extends FreedomCommand @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - + Admin admin = getAdmin(playerSender); FPlayer playerdata = plugin.pl.getPlayer(playerSender); playerdata.setCommandSpy(!playerdata.cmdspyEnabled()); + if (playerdata.cmdspyEnabled()) + { + admin.setCommandSpy(true); + } + else + { + admin.setCommandSpy(false); + } + msg("CommandSpy " + (playerdata.cmdspyEnabled() ? "enabled." : "disabled.")); return true;