From ffbe71f5ddd579e73596a54f9bffedf74419f4a1 Mon Sep 17 00:00:00 2001 From: ZeroEpoch1969 <13510767+ZeroEpoch1969@users.noreply.github.com> Date: Thu, 19 Apr 2018 07:29:19 -0700 Subject: [PATCH] Old admin mode and commandspy saving --- .../totalfreedommod/ChatManager.java | 34 +++++++++++++++++-- .../totalfreedommod/CommandSpy.java | 11 ++++-- .../totalfreedommod/admin/Admin.java | 11 +++++- .../command/Command_cmdspy.java | 10 +++--- .../totalfreedommod/command/Command_list.java | 28 ++++++++++++++- .../command/Command_oldadminmode.java | 26 ++++++++++++++ .../command/Command_vanish.java | 5 ++- .../totalfreedommod/rank/Displayable.java | 2 ++ .../totalfreedommod/rank/Rank.java | 26 ++++++-------- .../totalfreedommod/rank/Title.java | 11 +++++- 10 files changed, 135 insertions(+), 29 deletions(-) create mode 100644 src/main/java/me/totalfreedom/totalfreedommod/command/Command_oldadminmode.java diff --git a/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java b/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java index ad56ce72..b4559c9b 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/ChatManager.java @@ -1,6 +1,8 @@ package me.totalfreedom.totalfreedommod; +import me.totalfreedom.totalfreedommod.admin.Admin; import me.totalfreedom.totalfreedommod.player.FPlayer; +import me.totalfreedom.totalfreedommod.rank.Displayable; import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FSync; import static me.totalfreedom.totalfreedommod.util.FUtil.playerMsg; @@ -129,17 +131,43 @@ public class ChatManager extends FreedomService } } + public String getOldPrefix(Displayable display) + { + ChatColor color = display.getColor(); + + if (color.equals(ChatColor.AQUA)) + { + color = ChatColor.GOLD; + } + else if (color.equals(ChatColor.GOLD)) + { + color = ChatColor.LIGHT_PURPLE; + } + + String prefix = "(" + display.getAbbr() + ")"; + + return color + prefix; + } + public void adminChat(CommandSender sender, String message) { - String name = sender.getName() + " " + plugin.rm.getDisplay(sender).getColoredTag() + ChatColor.WHITE; - FLog.info("[ADMIN] " + name + ": " + message); + Displayable display = plugin.rm.getDisplay(sender); + FLog.info("[ADMIN] " + sender.getName() + " " + display.getTag() + ": " + message); checkMentions(message, true); for (Player player : server.getOnlinePlayers()) { if (plugin.al.isAdmin(player)) { - player.sendMessage("[" + ChatColor.AQUA + "ADMIN" + ChatColor.WHITE + "] " + ChatColor.DARK_RED + name + ": " + ChatColor.GOLD + message); + Admin admin = plugin.al.getAdmin(player); + if (admin.getOldAdminMode()) + { + player.sendMessage("[" + ChatColor.AQUA + "ADMIN" + ChatColor.WHITE + "] " + ChatColor.DARK_RED + sender.getName() + " " + getOldPrefix(display) + ChatColor.WHITE + ": " + ChatColor.AQUA + message); + } + else + { + player.sendMessage("[" + ChatColor.AQUA + "ADMIN" + ChatColor.WHITE + "] " + ChatColor.DARK_RED + sender.getName() + " " + display.getColoredTag() + ChatColor.WHITE + ": " + ChatColor.GOLD + message); + } } } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/CommandSpy.java b/src/main/java/me/totalfreedom/totalfreedommod/CommandSpy.java index b78cadd9..2ed134c3 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/CommandSpy.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/CommandSpy.java @@ -29,9 +29,16 @@ public class CommandSpy extends FreedomService { for (Player player : server.getOnlinePlayers()) { - if (plugin.al.isAdmin(player) && plugin.pl.getPlayer(player).cmdspyEnabled()) + if (plugin.al.isAdmin(player) && plugin.al.getAdmin(player).getCommandSpy()) { - FUtil.playerMsg(player, event.getPlayer().getName() + ": " + event.getMessage()); + if (plugin.al.isAdmin(event.getPlayer()) && !plugin.al.isSeniorAdmin(player)) + { + continue; + } + if (player != event.getPlayer()) + { + FUtil.playerMsg(player, event.getPlayer().getName() + ": " + event.getMessage()); + } } } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java b/src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java index 41c1eaa9..46c9d028 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/admin/Admin.java @@ -12,7 +12,6 @@ import me.totalfreedom.totalfreedommod.util.FUtil; import net.pravian.aero.base.ConfigLoadable; import net.pravian.aero.base.ConfigSavable; import net.pravian.aero.base.Validatable; -import net.pravian.aero.config.YamlConfig; import net.pravian.aero.util.Ips; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.Validate; @@ -46,6 +45,12 @@ public class Admin implements ConfigLoadable, ConfigSavable, Validatable @Getter @Setter private String tag = null; + @Getter + @Setter + private Boolean commandSpy = false; + @Getter + @Setter + private Boolean oldAdminMode = false; public static final String CONFIG_FILENAME = "admins.yml"; @@ -98,6 +103,8 @@ public class Admin implements ConfigLoadable, ConfigSavable, Validatable loginMessage = cs.getString("login_message", null); discordID = cs.getString("discord_id", null); tag = cs.getString("tag", null); + commandSpy = cs.getBoolean("command_spy", false); + oldAdminMode = cs.getBoolean("old_admin_mode", false); } @Override @@ -112,6 +119,8 @@ public class Admin implements ConfigLoadable, ConfigSavable, Validatable cs.set("login_message", loginMessage); cs.set("discord_id", discordID); cs.set("tag", tag); + cs.set("command_spy", commandSpy); + cs.set("old_admin_mode", oldAdminMode); } public boolean isAtLeast(Rank pRank) 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 c316a46a..13a8898d 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cmdspy.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cmdspy.java @@ -1,6 +1,6 @@ package me.totalfreedom.totalfreedommod.command; -import me.totalfreedom.totalfreedommod.player.FPlayer; +import me.totalfreedom.totalfreedommod.admin.Admin; import me.totalfreedom.totalfreedommod.rank.Rank; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -15,9 +15,11 @@ public class Command_cmdspy extends FreedomCommand public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - FPlayer playerdata = plugin.pl.getPlayer(playerSender); - playerdata.setCommandSpy(!playerdata.cmdspyEnabled()); - msg("CommandSpy " + (playerdata.cmdspyEnabled() ? "enabled." : "disabled.")); + Admin admin = plugin.al.getAdmin(playerSender); + admin.setCommandSpy(!admin.getCommandSpy()); + plugin.al.save(); + plugin.al.updateTables(); + msg("CommandSpy " + (admin.getCommandSpy() ? "enabled." : "disabled.")); return true; } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_list.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_list.java index 7268bfca..eb1923e2 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_list.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_list.java @@ -105,8 +105,16 @@ public class Command_list extends FreedomCommand { continue; } + final Displayable display = plugin.rm.getDisplay(p); - n.add(display.getColoredTag() + p.getName()); + if (!senderIsConsole && plugin.al.isAdmin(playerSender) && plugin.al.getAdmin(playerSender).getOldAdminMode()) + { + n.add(getOldPrefix(display) + p.getName()); + } + else + { + n.add(display.getColoredTag() + p.getName()); + } } String playerType = listFilter.toString().toLowerCase().replace('_', ' '); onlineUsers.append("Connected ") @@ -126,6 +134,24 @@ public class Command_list extends FreedomCommand n.clear(); return true; } + + public String getOldPrefix(Displayable display) + { + ChatColor color = display.getColor(); + + if (color.equals(ChatColor.AQUA)) + { + color = ChatColor.GOLD; + } + else if (color.equals(ChatColor.GOLD)) + { + color = ChatColor.LIGHT_PURPLE; + } + + String prefix = "[" + display.getAbbr() + "]"; + + return color + prefix; + } private enum ListFilter { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_oldadminmode.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_oldadminmode.java new file mode 100644 index 00000000..933f9f6b --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_oldadminmode.java @@ -0,0 +1,26 @@ +package me.totalfreedom.totalfreedommod.command; + +import me.totalfreedom.totalfreedommod.admin.Admin; +import me.totalfreedom.totalfreedommod.rank.Rank; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.ONLY_IN_GAME) +@CommandParameters(description = "Toggle old admin formatting", usage = "/", aliases = "oam") +public class Command_oldadminmode extends FreedomCommand +{ + + @Override + public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + { + + Admin admin = plugin.al.getAdmin(playerSender); + admin.setOldAdminMode(!admin.getOldAdminMode()); + plugin.al.save(); + plugin.al.updateTables(); + msg("Old admin mode has been " + (admin.getOldAdminMode() ? "enabled." : "disabled.")); + + return true; + } +} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vanish.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vanish.java index f18eb2e5..a96ddf55 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vanish.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_vanish.java @@ -39,7 +39,10 @@ public class Command_vanish extends FreedomCommand { tag = FUtil.colorize(admin.getTag()); } - plugin.pl.getPlayer(playerSender).setTag(tag); + else + { + plugin.pl.getPlayer(playerSender).setTag(tag); + } FLog.info(playerSender.getName() + " is no longer vanished."); for (Player player : server.getOnlinePlayers()) { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/rank/Displayable.java b/src/main/java/me/totalfreedom/totalfreedommod/rank/Displayable.java index 6eb94a71..a3e953a0 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/rank/Displayable.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/rank/Displayable.java @@ -9,6 +9,8 @@ public interface Displayable public String getTag(); + public String getAbbr(); + public ChatColor getColor(); public String getColoredName(); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/rank/Rank.java b/src/main/java/me/totalfreedom/totalfreedommod/rank/Rank.java index 4eec236f..14dfeecb 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/rank/Rank.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/rank/Rank.java @@ -18,6 +18,8 @@ public enum Rank implements Displayable private final Type type; @Getter private final String name; + @Getter + private final String abbr; private final String determiner; @Getter private final String tag; @@ -30,9 +32,10 @@ public enum Rank implements Displayable { this.type = type; this.name = name; + this.abbr = abbr; this.determiner = determiner; this.tag = abbr.isEmpty() ? "" : "[" + abbr + "]"; - this.coloredTag = abbr.isEmpty() ? "" : ChatColor.DARK_GRAY + "[" + color + abbr + ChatColor.DARK_GRAY + "]" + color; + this.coloredTag = ChatColor.DARK_GRAY + "[" + color + abbr + ChatColor.DARK_GRAY + "]" + color; this.color = color; } @@ -48,6 +51,12 @@ public enum Rank implements Displayable return determiner + " " + color + ChatColor.ITALIC + name; } + @Override + public String getAbbr() + { + return abbr; + } + public boolean isConsole() { return getType() == Type.ADMIN_CONSOLE; @@ -98,21 +107,6 @@ public enum Rank implements Displayable } } - public Rank getPlayerVariant() - { - switch (this) - { - case TELNET_ADMIN: - case TELNET_CONSOLE: - return TELNET_ADMIN; - case SENIOR_ADMIN: - case SENIOR_CONSOLE: - return SENIOR_ADMIN; - default: - return null; - } - } - public static Rank findRank(String string) { try diff --git a/src/main/java/me/totalfreedom/totalfreedommod/rank/Title.java b/src/main/java/me/totalfreedom/totalfreedommod/rank/Title.java index a382c8a1..ec1aa5a3 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/rank/Title.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/rank/Title.java @@ -13,6 +13,8 @@ public enum Title implements Displayable @Getter private final String name; @Getter + private final String abbr; + @Getter private final String tag; @Getter private final String coloredTag; @@ -23,8 +25,9 @@ public enum Title implements Displayable { this.determiner = determiner; this.name = name; - this.tag = "[" + tag + "]"; this.coloredTag = ChatColor.DARK_GRAY + "[" + color + tag + ChatColor.DARK_GRAY + "]" + color; + this.abbr = tag; + this.tag = "[" + tag + "]"; this.color = color; } @@ -40,4 +43,10 @@ public enum Title implements Displayable return determiner + " " + color + ChatColor.ITALIC + name; } + @Override + public String getAbbr() + { + return abbr; + } + }