Merge branch 'development' into paldiu-local

This commit is contained in:
Paldiu 2021-01-04 13:14:53 -06:00
commit c7b0f77910
15 changed files with 177 additions and 64 deletions

View File

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

View File

@ -153,7 +153,7 @@ public class Admin
{ {
this.active = active; this.active = active;
final TotalFreedomMod plugin = TotalFreedomMod.plugin(); final TotalFreedomMod plugin = TotalFreedomMod.getPlugin();
// Avoiding stupid NPE compiler warnings // Avoiding stupid NPE compiler warnings
if (plugin == null) if (plugin == null)

View File

@ -39,7 +39,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

@ -23,7 +23,7 @@ public enum CommandBlockerRank
public static CommandBlockerRank fromSender(CommandSender sender) public static CommandBlockerRank fromSender(CommandSender sender)
{ {
Admin admin = Objects.requireNonNull(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

@ -245,6 +245,19 @@ public enum ConfigEntry
private MainConfig getConfig() private MainConfig getConfig()
{ {
return Objects.requireNonNull(TotalFreedomMod.plugin()).config; return TotalFreedomMod.getPlugin().config;
}
public static ConfigEntry findConfigEntry(String name)
{
name = name.toLowerCase().replace("_", "");
for (ConfigEntry entry : values())
{
if (entry.toString().toLowerCase().replace("_", "").equals(name))
{
return entry;
}
}
return null;
} }
} }

View File

@ -243,7 +243,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.");
@ -251,7 +250,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;
@ -21,46 +27,109 @@ public class DiscordToAdminChatListener extends ListenerAdapter
public void onMessageReceived(MessageReceivedEvent event) public void onMessageReceived(MessageReceivedEvent event)
{ {
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) && !event.getAuthor().getId().equals(event.getJDA().getSelfUser().getId()))
{ {
if (!event.getAuthor().getId().equals(Discord.bot.getSelfUser().getId())) Member member = event.getMember();
String tag = dtml.getDisplay(member);
StringBuilder message = new StringBuilder(ChatColor.DARK_GRAY + "[" + ChatColor.DARK_AQUA + "Discord" + ChatColor.DARK_GRAY + "] " + ChatColor.RESET);
Message msg = event.getMessage();
for (Player player : Bukkit.getOnlinePlayers())
{ {
Member member = event.getMember(); if (TotalFreedomMod.getPlugin().al.isAdmin(player))
String tag = dtml.getDisplay(member);
StringBuilder message = new StringBuilder(ChatColor.DARK_GRAY + "[" + ChatColor.DARK_AQUA + "ADMIN" + ChatColor.DARK_GRAY + "]");
Message msg = event.getMessage();
if (tag != null)
{ {
message.append(" ").append(tag); Admin admin = TotalFreedomMod.getPlugin().al.getAdmin(player);
} String format = admin.getAcFormat();
message.append(" ").append(ChatColor.RED).append(ChatColor.stripColor(member.getEffectiveName())).append(ChatColor.DARK_GRAY).append(":").append(ChatColor.RESET); if (format != null)
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())
{ {
attachment.getUrl(); Displayable display = TotalFreedomMod.getPlugin().rm.getDisplay(player);
builder.append(" "); net.md_5.bungee.api.ChatColor color = getColor(display);
TextComponent text = new TextComponent(ChatColor.YELLOW + "[Media]"); String m = format.replace("%name%", member.getEffectiveName())
text.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, attachment.getUrl())); .replace("%rank%", getDisplay(member))
builder.append(text); .replace("%rankcolor%", color.toString())
message.append(" [Media]"); // for logging .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);
} }
} }
for (Player player : Bukkit.getOnlinePlayers())
{
if (TotalFreedomMod.getPlugin().al.isAdmin(player))
{
player.spigot().sendMessage(builder.create());
}
}
FLog.info(message.toString());
} }
ComponentBuilder builder = new ComponentBuilder(message.toString());
if (!msg.getAttachments().isEmpty())
{
for (Message.Attachment attachment : msg.getAttachments())
{
if (attachment.getUrl() == null)
{
continue;
}
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))
{
player.spigot().sendMessage(builder.create());
}
}
FLog.info(message.toString());
}
}
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

@ -11,7 +11,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]"))
@ -25,12 +25,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 = Objects.requireNonNull(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());
} }
Objects.requireNonNull(TotalFreedomMod.plugin()).pl.save(player);
TotalFreedomMod.getPlugin().pl.save(player);
Discord.LINK_CODES.remove(code); Discord.LINK_CODES.remove(code);
} }
else else

View File

@ -16,6 +16,35 @@ public abstract class ModuleExecutable
this.async = async; this.async = async;
} }
public NanoHTTPD.Response execute(final NanoHTTPD.HTTPSession session)
{
try
{
if (async)
{
return getResponse(session);
}
// Sync to server thread
return Bukkit.getScheduler().callSyncMethod(TotalFreedomMod.getPlugin(), new Callable<NanoHTTPD.Response>()
{
@Override
public NanoHTTPD.Response call() throws Exception
{
return getResponse(session);
}
}).get();
}
catch (Exception ex)
{
FLog.severe(ex);
}
return null;
}
public abstract NanoHTTPD.Response getResponse(NanoHTTPD.HTTPSession session);
public static ModuleExecutable forClass(final TotalFreedomMod plugin, Class<? extends HTTPDModule> clazz, boolean async) public static ModuleExecutable forClass(final TotalFreedomMod plugin, Class<? extends HTTPDModule> clazz, boolean async)
{ {
final Constructor<? extends HTTPDModule> cons; final Constructor<? extends HTTPDModule> cons;

View File

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

View File

@ -78,12 +78,12 @@ public class PlayerData
if (masterBuilder && !verification) if (masterBuilder && !verification)
{ {
verification = true; verification = true;
Objects.requireNonNull(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;
Objects.requireNonNull(TotalFreedomMod.plugin()).pl.save(this); TotalFreedomMod.getPlugin().pl.save(this);
} }
} }

View File

@ -11,8 +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();
assert plugin != null;
new BukkitRunnable() new BukkitRunnable()
{ {
@ -27,8 +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();
assert plugin != null;
new BukkitRunnable() new BukkitRunnable()
{ {
@ -43,8 +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();
assert plugin != null;
new BukkitRunnable() new BukkitRunnable()
{ {
@ -59,8 +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();
assert plugin != null;
new BukkitRunnable() new BukkitRunnable()
{ {
@ -75,8 +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();
assert plugin != null;
new BukkitRunnable() new BukkitRunnable()
{ {
@ -91,8 +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();
assert plugin != null;
new BukkitRunnable() new BukkitRunnable()
{ {

View File

@ -139,7 +139,14 @@ public class FUtil
public static boolean isDeveloper(Player player) public static boolean isDeveloper(Player player)
{ {
return DEVELOPERS.contains(player.getUniqueId().toString()); if (Bukkit.getOnlineMode())
{
return DEVELOPERS.contains(player.getUniqueId().toString());
}
else
{
return DEVELOPER_NAMES.contains(player.getName());
}
} }
public static boolean inDeveloperMode() public static boolean inDeveloperMode()
@ -162,7 +169,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 (!Objects.requireNonNull(TotalFreedomMod.plugin()).al.isVanished(player.getName())) if (!TotalFreedomMod.getPlugin().al.isVanished(player.getName()))
{ {
names.add(player.getName()); names.add(player.getName());
} }

View File

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