mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
admin chat discord formatting (FS-59)
This commit is contained in:
parent
210b0f8b43
commit
b9606fa0e3
@ -144,8 +144,7 @@ public class ChatManager extends FreedomService
|
||||
|
||||
public ChatColor getColor(Displayable display)
|
||||
{
|
||||
ChatColor color = display.getColor();
|
||||
return color;
|
||||
return display.getColor();
|
||||
}
|
||||
|
||||
public String getColoredTag(Displayable display)
|
||||
|
@ -27,7 +27,7 @@ public class SavedFlags extends FreedomService
|
||||
{
|
||||
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())
|
||||
{
|
||||
try
|
||||
|
@ -140,7 +140,7 @@ public class Admin
|
||||
{
|
||||
this.active = active;
|
||||
|
||||
final TotalFreedomMod plugin = TotalFreedomMod.plugin();
|
||||
final TotalFreedomMod plugin = TotalFreedomMod.getPlugin();
|
||||
|
||||
if (!active)
|
||||
{
|
||||
|
@ -40,7 +40,7 @@ public class CommandBlockerEntry
|
||||
{
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ public enum CommandBlockerRank
|
||||
|
||||
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.getRank() == Rank.SENIOR_ADMIN)
|
||||
|
@ -138,6 +138,7 @@ public class Command_myadmin extends FreedomCommand
|
||||
return true;
|
||||
}
|
||||
|
||||
case "setacformat":
|
||||
case "setscformat":
|
||||
{
|
||||
String format = StringUtils.join(args, " ", 1, args.length);
|
||||
@ -150,6 +151,7 @@ public class Command_myadmin extends FreedomCommand
|
||||
return true;
|
||||
}
|
||||
|
||||
case "clearacformat":
|
||||
case "clearscformat":
|
||||
{
|
||||
target.setAcFormat(null);
|
||||
@ -203,8 +205,8 @@ public class Command_myadmin extends FreedomCommand
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<String> singleArguments = Arrays.asList("clearips", "setscformat");
|
||||
List<String> doubleArguments = Arrays.asList("clearip", "clearscformat", "syncroles");
|
||||
List<String> singleArguments = Arrays.asList("clearips", "setscformat", "setacformat");
|
||||
List<String> doubleArguments = Arrays.asList("clearip", "clearscformat", "clearacformat", "syncroles");
|
||||
if (args.length == 1)
|
||||
{
|
||||
List<String> options = new ArrayList<>();
|
||||
|
@ -239,7 +239,7 @@ public enum ConfigEntry
|
||||
|
||||
private MainConfig getConfig()
|
||||
{
|
||||
return TotalFreedomMod.plugin().config;
|
||||
return TotalFreedomMod.getPlugin().config;
|
||||
}
|
||||
|
||||
public static ConfigEntry findConfigEntry(String name)
|
||||
|
@ -167,7 +167,6 @@ public class Discord extends FreedomService
|
||||
public User getUser(String id)
|
||||
{
|
||||
Guild guild = bot.getGuildById(ConfigEntry.DISCORD_SERVER_ID.getString());
|
||||
|
||||
if (guild == null)
|
||||
{
|
||||
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);
|
||||
|
||||
if (member == null)
|
||||
{
|
||||
return null;
|
||||
|
@ -1,8 +1,14 @@
|
||||
package me.totalfreedom.totalfreedommod.discord;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.admin.Admin;
|
||||
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.FUtil;
|
||||
import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
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();
|
||||
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();
|
||||
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();
|
||||
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));
|
||||
}
|
||||
message.append(" " + ChatColor.RED).append(ChatColor.stripColor(member.getEffectiveName())).append(ChatColor.DARK_GRAY).append(":").append(ChatColor.RESET);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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())
|
||||
{
|
||||
for (Message.Attachment attachment : msg.getAttachments())
|
||||
@ -48,13 +70,14 @@ public class DiscordToAdminChatListener extends ListenerAdapter
|
||||
{
|
||||
continue;
|
||||
}
|
||||
builder.append(" ");
|
||||
|
||||
TextComponent text = new TextComponent(ChatColor.YELLOW + "[Media]");
|
||||
text.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, attachment.getUrl()));
|
||||
builder.append(text);
|
||||
message.append("[Media]"); // for logging
|
||||
}
|
||||
}
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@ public class PrivateMessageListener extends ListenerAdapter
|
||||
{
|
||||
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
|
||||
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.setVerification(true);
|
||||
|
||||
Admin admin = TotalFreedomMod.plugin().al.getEntryByName(name);
|
||||
Admin admin = TotalFreedomMod.getPlugin().al.getEntryByName(name);
|
||||
if (admin != null)
|
||||
{
|
||||
Discord.syncRoles(admin, player.getDiscordID());
|
||||
}
|
||||
TotalFreedomMod.plugin().pl.save(player);
|
||||
|
||||
TotalFreedomMod.getPlugin().pl.save(player);
|
||||
Discord.LINK_CODES.remove(code);
|
||||
}
|
||||
else
|
||||
|
@ -29,7 +29,7 @@ public abstract class ModuleExecutable
|
||||
}
|
||||
|
||||
// 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
|
||||
public NanoHTTPD.Response call() throws Exception
|
||||
|
@ -36,6 +36,6 @@ public enum PermissionEntry
|
||||
|
||||
private PermissionConfig getConfig()
|
||||
{
|
||||
return TotalFreedomMod.plugin().permissions;
|
||||
return TotalFreedomMod.getPlugin().permissions;
|
||||
}
|
||||
}
|
||||
|
@ -86,12 +86,12 @@ public class PlayerData
|
||||
if (masterBuilder && !verification)
|
||||
{
|
||||
verification = true;
|
||||
TotalFreedomMod.plugin().pl.save(this);
|
||||
TotalFreedomMod.getPlugin().pl.save(this);
|
||||
}
|
||||
else if (!masterBuilder && discordID == null && verification)
|
||||
{
|
||||
this.verification = false;
|
||||
TotalFreedomMod.plugin().pl.save(this);
|
||||
TotalFreedomMod.getPlugin().pl.save(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ public class FSync
|
||||
|
||||
public static void playerMsg(final Player player, final String message)
|
||||
{
|
||||
final TotalFreedomMod plugin = TotalFreedomMod.plugin();
|
||||
final TotalFreedomMod plugin = TotalFreedomMod.getPlugin();
|
||||
new BukkitRunnable()
|
||||
{
|
||||
|
||||
@ -26,7 +26,7 @@ public class FSync
|
||||
|
||||
public static void playerMsg(final CommandSender sender, final String message)
|
||||
{
|
||||
final TotalFreedomMod plugin = TotalFreedomMod.plugin();
|
||||
final TotalFreedomMod plugin = TotalFreedomMod.getPlugin();
|
||||
new BukkitRunnable()
|
||||
{
|
||||
|
||||
@ -41,7 +41,7 @@ public class FSync
|
||||
|
||||
public static void playerKick(final Player player, final String reason)
|
||||
{
|
||||
final TotalFreedomMod plugin = TotalFreedomMod.plugin();
|
||||
final TotalFreedomMod plugin = TotalFreedomMod.getPlugin();
|
||||
new BukkitRunnable()
|
||||
{
|
||||
|
||||
@ -56,7 +56,7 @@ public class FSync
|
||||
|
||||
public static void adminChatMessage(final CommandSender sender, final String message)
|
||||
{
|
||||
final TotalFreedomMod plugin = TotalFreedomMod.plugin();
|
||||
final TotalFreedomMod plugin = TotalFreedomMod.getPlugin();
|
||||
new BukkitRunnable()
|
||||
{
|
||||
|
||||
@ -71,7 +71,7 @@ public class FSync
|
||||
|
||||
public static void autoEject(final Player player, final String kickMessage)
|
||||
{
|
||||
final TotalFreedomMod plugin = TotalFreedomMod.plugin();
|
||||
final TotalFreedomMod plugin = TotalFreedomMod.getPlugin();
|
||||
new BukkitRunnable()
|
||||
{
|
||||
|
||||
@ -86,7 +86,7 @@ public class FSync
|
||||
|
||||
public static void bcastMsg(final String message, final ChatColor color)
|
||||
{
|
||||
final TotalFreedomMod plugin = TotalFreedomMod.plugin();
|
||||
final TotalFreedomMod plugin = TotalFreedomMod.getPlugin();
|
||||
new BukkitRunnable()
|
||||
{
|
||||
|
||||
|
@ -163,7 +163,7 @@ public class FUtil
|
||||
List<String> names = new ArrayList<>();
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
if (!TotalFreedomMod.plugin().al.isVanished(player.getName()))
|
||||
if (!TotalFreedomMod.getPlugin().al.isVanished(player.getName()))
|
||||
{
|
||||
names.add(player.getName());
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ public class History
|
||||
FSync.playerMsg(sender, ChatColor.RED + "Player not found!");
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(TotalFreedomMod.plugin());
|
||||
}.runTaskAsynchronously(TotalFreedomMod.getPlugin());
|
||||
}
|
||||
|
||||
private static void printHistory(CommandSender sender, FName[] oldNames)
|
||||
|
Loading…
Reference in New Issue
Block a user