admin chat discord formatting (FS-59)

This commit is contained in:
speed 2020-12-26 18:54:15 -05:00
parent 210b0f8b43
commit b9606fa0e3
16 changed files with 107 additions and 38 deletions

View File

@ -144,8 +144,7 @@ public class ChatManager extends FreedomService
public ChatColor getColor(Displayable display) public ChatColor getColor(Displayable display)
{ {
ChatColor color = display.getColor(); return display.getColor();
return color;
} }
public String getColoredTag(Displayable display) public String getColoredTag(Displayable display)

View File

@ -27,7 +27,7 @@ public class SavedFlags extends FreedomService
{ {
Map<String, Boolean> flags = null; Map<String, Boolean> flags = null;
File input = new File(TotalFreedomMod.plugin().getDataFolder(), SAVED_FLAGS_FILENAME); File input = new File(TotalFreedomMod.getPlugin().getDataFolder(), SAVED_FLAGS_FILENAME);
if (input.exists()) if (input.exists())
{ {
try try

View File

@ -140,7 +140,7 @@ public class Admin
{ {
this.active = active; this.active = active;
final TotalFreedomMod plugin = TotalFreedomMod.plugin(); final TotalFreedomMod plugin = TotalFreedomMod.getPlugin();
if (!active) if (!active)
{ {

View File

@ -40,7 +40,7 @@ public class CommandBlockerEntry
{ {
if (action == CommandBlockerAction.BLOCK_AND_EJECT && sender instanceof Player) if (action == CommandBlockerAction.BLOCK_AND_EJECT && sender instanceof Player)
{ {
TotalFreedomMod.plugin().ae.autoEject((Player)sender, "You used a prohibited command: " + command); TotalFreedomMod.getPlugin().ae.autoEject((Player)sender, "You used a prohibited command: " + command);
FUtil.bcastMsg(sender.getName() + " was automatically kicked for using harmful commands.", ChatColor.RED); FUtil.bcastMsg(sender.getName() + " was automatically kicked for using harmful commands.", ChatColor.RED);
return; return;
} }

View File

@ -32,7 +32,7 @@ public enum CommandBlockerRank
public static CommandBlockerRank fromSender(CommandSender sender) public static CommandBlockerRank fromSender(CommandSender sender)
{ {
Admin admin = TotalFreedomMod.plugin().al.getAdmin(sender); Admin admin = TotalFreedomMod.getPlugin().al.getAdmin(sender);
if (admin != null) if (admin != null)
{ {
if (admin.getRank() == Rank.SENIOR_ADMIN) if (admin.getRank() == Rank.SENIOR_ADMIN)

View File

@ -138,6 +138,7 @@ public class Command_myadmin extends FreedomCommand
return true; return true;
} }
case "setacformat":
case "setscformat": case "setscformat":
{ {
String format = StringUtils.join(args, " ", 1, args.length); String format = StringUtils.join(args, " ", 1, args.length);
@ -150,6 +151,7 @@ public class Command_myadmin extends FreedomCommand
return true; return true;
} }
case "clearacformat":
case "clearscformat": case "clearscformat":
{ {
target.setAcFormat(null); target.setAcFormat(null);
@ -203,8 +205,8 @@ public class Command_myadmin extends FreedomCommand
return Collections.emptyList(); return Collections.emptyList();
} }
List<String> singleArguments = Arrays.asList("clearips", "setscformat"); List<String> singleArguments = Arrays.asList("clearips", "setscformat", "setacformat");
List<String> doubleArguments = Arrays.asList("clearip", "clearscformat", "syncroles"); List<String> doubleArguments = Arrays.asList("clearip", "clearscformat", "clearacformat", "syncroles");
if (args.length == 1) if (args.length == 1)
{ {
List<String> options = new ArrayList<>(); List<String> options = new ArrayList<>();

View File

@ -239,7 +239,7 @@ public enum ConfigEntry
private MainConfig getConfig() private MainConfig getConfig()
{ {
return TotalFreedomMod.plugin().config; return TotalFreedomMod.getPlugin().config;
} }
public static ConfigEntry findConfigEntry(String name) public static ConfigEntry findConfigEntry(String name)

View File

@ -167,7 +167,6 @@ public class Discord extends FreedomService
public User getUser(String id) public User getUser(String id)
{ {
Guild guild = bot.getGuildById(ConfigEntry.DISCORD_SERVER_ID.getString()); Guild guild = bot.getGuildById(ConfigEntry.DISCORD_SERVER_ID.getString());
if (guild == null) if (guild == null)
{ {
FLog.severe("Either the bot is not in the Discord server or it doesn't exist. Check the server ID."); FLog.severe("Either the bot is not in the Discord server or it doesn't exist. Check the server ID.");
@ -175,7 +174,6 @@ public class Discord extends FreedomService
} }
Member member = guild.getMemberById(id); Member member = guild.getMemberById(id);
if (member == null) if (member == null)
{ {
return null; return null;

View File

@ -1,8 +1,14 @@
package me.totalfreedom.totalfreedommod.discord; package me.totalfreedom.totalfreedommod.discord;
import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import me.totalfreedom.totalfreedommod.admin.Admin;
import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.config.ConfigEntry;
import me.totalfreedom.totalfreedommod.rank.Displayable;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.rank.Title;
import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FLog;
import me.totalfreedom.totalfreedommod.util.FUtil;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
@ -23,23 +29,39 @@ public class DiscordToAdminChatListener extends ListenerAdapter
String chat_channel_id = ConfigEntry.DISCORD_ADMINCHAT_CHANNEL_ID.getString(); String chat_channel_id = ConfigEntry.DISCORD_ADMINCHAT_CHANNEL_ID.getString();
if (event.getMember() != null && !chat_channel_id.isEmpty() && event.getChannel().getId().equals(chat_channel_id)) if (event.getMember() != null && !chat_channel_id.isEmpty() && event.getChannel().getId().equals(chat_channel_id))
{ {
if (!event.getAuthor().getId().equals(Discord.bot.getSelfUser().getId())) if (!event.getAuthor().getId().equals(event.getJDA().getSelfUser().getId()))
{ {
Member member = event.getMember(); Member member = event.getMember();
String tag = dtml.getDisplay(member); String tag = dtml.getDisplay(member);
StringBuilder message = new StringBuilder(ChatColor.DARK_GRAY + "[" + ChatColor.DARK_AQUA + "ADMIN" + ChatColor.DARK_GRAY + "]"); StringBuilder message = new StringBuilder(ChatColor.DARK_GRAY + "[" + ChatColor.DARK_AQUA + "Discord" + ChatColor.DARK_GRAY + "] " + ChatColor.RESET);
Message msg = event.getMessage(); Message msg = event.getMessage();
if (tag != null) for (Player player : Bukkit.getOnlinePlayers())
{ {
message.append(" ").append(tag); if (TotalFreedomMod.getPlugin().al.isAdmin(player))
{
Admin admin = TotalFreedomMod.getPlugin().al.getAdmin(player);
String format = admin.getAcFormat();
if (format != null)
{
Displayable display = TotalFreedomMod.getPlugin().rm.getDisplay(player);
net.md_5.bungee.api.ChatColor color = getColor(display);
String m = format.replace("%name%", member.getEffectiveName())
.replace("%rank%", getDisplay(member))
.replace("%rankcolor%", color.toString())
.replace("%msg%", FUtil.colorize(msg.getContentDisplay()));
message.append(FUtil.colorize(m));
}
else
{
String m = ChatColor.DARK_RED + member.getEffectiveName() + " "
+ ChatColor.DARK_GRAY + tag + ChatColor.DARK_GRAY
+ ChatColor.WHITE + ": " + ChatColor.GOLD + FUtil.colorize(msg.getContentDisplay());
message.append(m);
}
}
} }
message.append(" " + ChatColor.RED).append(ChatColor.stripColor(member.getEffectiveName())).append(ChatColor.DARK_GRAY).append(":").append(ChatColor.RESET);
ComponentBuilder builder = new ComponentBuilder(message.toString()); ComponentBuilder builder = new ComponentBuilder(message.toString());
if (!msg.getContentDisplay().isEmpty())
{
builder.append(" ").append(ChatColor.stripColor(msg.getContentDisplay()));
message.append(" ").append(ChatColor.stripColor(msg.getContentDisplay())); // for logging
}
if (!msg.getAttachments().isEmpty()) if (!msg.getAttachments().isEmpty())
{ {
for (Message.Attachment attachment : msg.getAttachments()) for (Message.Attachment attachment : msg.getAttachments())
@ -48,13 +70,14 @@ public class DiscordToAdminChatListener extends ListenerAdapter
{ {
continue; continue;
} }
builder.append(" ");
TextComponent text = new TextComponent(ChatColor.YELLOW + "[Media]"); TextComponent text = new TextComponent(ChatColor.YELLOW + "[Media]");
text.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, attachment.getUrl())); text.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, attachment.getUrl()));
builder.append(text); builder.append(text);
message.append(" [Media]"); // for logging message.append("[Media]"); // for logging
} }
} }
for (Player player : Bukkit.getOnlinePlayers()) for (Player player : Bukkit.getOnlinePlayers())
{ {
if (TotalFreedomMod.getPlugin().al.isAdmin(player)) if (TotalFreedomMod.getPlugin().al.isAdmin(player))
@ -66,4 +89,50 @@ public class DiscordToAdminChatListener extends ListenerAdapter
} }
} }
} }
public static net.md_5.bungee.api.ChatColor getColor(Displayable display)
{
return display.getColor();
}
// Needed to display tags in custom AC messages
public String getDisplay(Member member)
{
Guild server = Discord.bot.getGuildById(ConfigEntry.DISCORD_SERVER_ID.getString());
// Server Owner
if (member.getRoles().contains(server.getRoleById(ConfigEntry.DISCORD_SERVER_OWNER_ROLE_ID.getString())))
{
return Title.OWNER.getAbbr();
}
// Developers
else if (member.getRoles().contains(server.getRoleById(ConfigEntry.DISCORD_DEVELOPER_ROLE_ID.getString())))
{
return Title.DEVELOPER.getAbbr();
}
// Executives
else if (member.getRoles().contains(server.getRoleById(ConfigEntry.DISCORD_EXECUTIVE_ROLE_ID.getString())))
{
return Title.EXECUTIVE.getAbbr();
}
// Senior Admins
else if (member.getRoles().contains(server.getRoleById(ConfigEntry.DISCORD_SENIOR_ADMIN_ROLE_ID.getString())))
{
return Rank.SENIOR_ADMIN.getAbbr();
}
// Admins
else if (member.getRoles().contains(server.getRoleById(ConfigEntry.DISCORD_NEW_ADMIN_ROLE_ID.getString())))
{
return Rank.ADMIN.getAbbr();
}
// Master Builders
else if (member.getRoles().contains(server.getRoleById(ConfigEntry.DISCORD_MASTER_BUILDER_ROLE_ID.getString())))
{
return Title.MASTER_BUILDER.getAbbr();
}
// OP, returning null breaks?
else
{
return Rank.OP.getAbbr();
}
}
} }

View File

@ -10,7 +10,7 @@ public class PrivateMessageListener extends ListenerAdapter
{ {
public void onPrivateMessageReceived(PrivateMessageReceivedEvent event) public void onPrivateMessageReceived(PrivateMessageReceivedEvent event)
{ {
if (!event.getAuthor().getId().equals(Discord.bot.getSelfUser().getId())) if (!event.getAuthor().getId().equals(event.getJDA().getSelfUser().getId()))
{ {
// Handle link code // Handle link code
if (event.getMessage().getContentRaw().matches("[0-9][0-9][0-9][0-9][0-9]")) if (event.getMessage().getContentRaw().matches("[0-9][0-9][0-9][0-9][0-9]"))
@ -24,12 +24,13 @@ public class PrivateMessageListener extends ListenerAdapter
player.setDiscordID(event.getMessage().getAuthor().getId()); player.setDiscordID(event.getMessage().getAuthor().getId());
player.setVerification(true); player.setVerification(true);
Admin admin = TotalFreedomMod.plugin().al.getEntryByName(name); Admin admin = TotalFreedomMod.getPlugin().al.getEntryByName(name);
if (admin != null) if (admin != null)
{ {
Discord.syncRoles(admin, player.getDiscordID()); Discord.syncRoles(admin, player.getDiscordID());
} }
TotalFreedomMod.plugin().pl.save(player);
TotalFreedomMod.getPlugin().pl.save(player);
Discord.LINK_CODES.remove(code); Discord.LINK_CODES.remove(code);
} }
else else

View File

@ -29,7 +29,7 @@ public abstract class ModuleExecutable
} }
// Sync to server thread // Sync to server thread
return Bukkit.getScheduler().callSyncMethod(TotalFreedomMod.plugin(), new Callable<NanoHTTPD.Response>() return Bukkit.getScheduler().callSyncMethod(TotalFreedomMod.getPlugin(), new Callable<NanoHTTPD.Response>()
{ {
@Override @Override
public NanoHTTPD.Response call() throws Exception public NanoHTTPD.Response call() throws Exception

View File

@ -36,6 +36,6 @@ public enum PermissionEntry
private PermissionConfig getConfig() private PermissionConfig getConfig()
{ {
return TotalFreedomMod.plugin().permissions; return TotalFreedomMod.getPlugin().permissions;
} }
} }

View File

@ -86,12 +86,12 @@ public class PlayerData
if (masterBuilder && !verification) if (masterBuilder && !verification)
{ {
verification = true; verification = true;
TotalFreedomMod.plugin().pl.save(this); TotalFreedomMod.getPlugin().pl.save(this);
} }
else if (!masterBuilder && discordID == null && verification) else if (!masterBuilder && discordID == null && verification)
{ {
this.verification = false; this.verification = false;
TotalFreedomMod.plugin().pl.save(this); TotalFreedomMod.getPlugin().pl.save(this);
} }
} }

View File

@ -11,7 +11,7 @@ public class FSync
public static void playerMsg(final Player player, final String message) public static void playerMsg(final Player player, final String message)
{ {
final TotalFreedomMod plugin = TotalFreedomMod.plugin(); final TotalFreedomMod plugin = TotalFreedomMod.getPlugin();
new BukkitRunnable() new BukkitRunnable()
{ {
@ -26,7 +26,7 @@ public class FSync
public static void playerMsg(final CommandSender sender, final String message) public static void playerMsg(final CommandSender sender, final String message)
{ {
final TotalFreedomMod plugin = TotalFreedomMod.plugin(); final TotalFreedomMod plugin = TotalFreedomMod.getPlugin();
new BukkitRunnable() new BukkitRunnable()
{ {
@ -41,7 +41,7 @@ public class FSync
public static void playerKick(final Player player, final String reason) public static void playerKick(final Player player, final String reason)
{ {
final TotalFreedomMod plugin = TotalFreedomMod.plugin(); final TotalFreedomMod plugin = TotalFreedomMod.getPlugin();
new BukkitRunnable() new BukkitRunnable()
{ {
@ -56,7 +56,7 @@ public class FSync
public static void adminChatMessage(final CommandSender sender, final String message) public static void adminChatMessage(final CommandSender sender, final String message)
{ {
final TotalFreedomMod plugin = TotalFreedomMod.plugin(); final TotalFreedomMod plugin = TotalFreedomMod.getPlugin();
new BukkitRunnable() new BukkitRunnable()
{ {
@ -71,7 +71,7 @@ public class FSync
public static void autoEject(final Player player, final String kickMessage) public static void autoEject(final Player player, final String kickMessage)
{ {
final TotalFreedomMod plugin = TotalFreedomMod.plugin(); final TotalFreedomMod plugin = TotalFreedomMod.getPlugin();
new BukkitRunnable() new BukkitRunnable()
{ {
@ -86,7 +86,7 @@ public class FSync
public static void bcastMsg(final String message, final ChatColor color) public static void bcastMsg(final String message, final ChatColor color)
{ {
final TotalFreedomMod plugin = TotalFreedomMod.plugin(); final TotalFreedomMod plugin = TotalFreedomMod.getPlugin();
new BukkitRunnable() new BukkitRunnable()
{ {

View File

@ -163,7 +163,7 @@ public class FUtil
List<String> names = new ArrayList<>(); List<String> names = new ArrayList<>();
for (Player player : Bukkit.getOnlinePlayers()) for (Player player : Bukkit.getOnlinePlayers())
{ {
if (!TotalFreedomMod.plugin().al.isVanished(player.getName())) if (!TotalFreedomMod.getPlugin().al.isVanished(player.getName()))
{ {
names.add(player.getName()); names.add(player.getName());
} }

View File

@ -64,7 +64,7 @@ public class History
FSync.playerMsg(sender, ChatColor.RED + "Player not found!"); FSync.playerMsg(sender, ChatColor.RED + "Player not found!");
} }
} }
}.runTaskAsynchronously(TotalFreedomMod.plugin()); }.runTaskAsynchronously(TotalFreedomMod.getPlugin());
} }
private static void printHistory(CommandSender sender, FName[] oldNames) private static void printHistory(CommandSender sender, FName[] oldNames)