Merge pull request #48 from Xyntexx/feature/create_parent_for_configs
Feature/create parent for configs
This commit is contained in:
commit
43a69545f5
|
@ -139,7 +139,7 @@ public class DiscordClient extends ListenerAdapter
|
||||||
|
|
||||||
private static void AssignVars()
|
private static void AssignVars()
|
||||||
{
|
{
|
||||||
FileConfiguration mainConfig = MainConfig.getMainConfig();
|
FileConfiguration mainConfig = DiscordWhitelister.mainConfig.getFileConfiguration();
|
||||||
|
|
||||||
// assign vars here instead of every time a message is received, as they do not change
|
// assign vars here instead of every time a message is received, as they do not change
|
||||||
targetTextChannels = new String[mainConfig.getList("target-text-channels").size()];
|
targetTextChannels = new String[mainConfig.getList("target-text-channels").size()];
|
||||||
|
@ -281,15 +281,15 @@ public class DiscordClient extends ListenerAdapter
|
||||||
{
|
{
|
||||||
String addCommandExample = "!whitelist add";
|
String addCommandExample = "!whitelist add";
|
||||||
if(DiscordWhitelister.useCustomPrefixes)
|
if(DiscordWhitelister.useCustomPrefixes)
|
||||||
addCommandExample = CustomPrefixConfig.getCustomPrefixesConfig().getString("whitelist-add-prefix").trim();
|
addCommandExample = DiscordWhitelister.customPrefixConfig.getFileConfiguration().getString("whitelist-add-prefix").trim();
|
||||||
|
|
||||||
instructionalMessageEmbed = CreateEmbeddedMessage("How to Whitelist", ("Use `" + addCommandExample + " <minecraftUsername>` to whitelist yourself.\n" +
|
instructionalMessageEmbed = CreateEmbeddedMessage("How to Whitelist", ("Use `" + addCommandExample + " <minecraftUsername>` to whitelist yourself.\n" +
|
||||||
"In the case of whitelisting an incorrect name, please contact a staff member to clear it from the whitelist."), EmbedMessageType.INFO).build();
|
"In the case of whitelisting an incorrect name, please contact a staff member to clear it from the whitelist."), EmbedMessageType.INFO).build();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
String customTitle = CustomMessagesConfig.getCustomMessagesConfig().getString("instructional-message-title");
|
String customTitle = DiscordWhitelister.customMessagesConfig.getFileConfiguration().getString("instructional-message-title");
|
||||||
String customMessage = CustomMessagesConfig.getCustomMessagesConfig().getString("instructional-message");
|
String customMessage = DiscordWhitelister.customMessagesConfig.getFileConfiguration().getString("instructional-message");
|
||||||
|
|
||||||
instructionalMessageEmbed = CreateEmbeddedMessage(customTitle, customMessage, EmbedMessageType.INFO).build();
|
instructionalMessageEmbed = CreateEmbeddedMessage(customTitle, customMessage, EmbedMessageType.INFO).build();
|
||||||
}
|
}
|
||||||
|
@ -446,7 +446,7 @@ public class DiscordClient extends ListenerAdapter
|
||||||
|
|
||||||
if(!DiscordWhitelister.useCustomMessages)
|
if(!DiscordWhitelister.useCustomMessages)
|
||||||
{
|
{
|
||||||
if(!MainConfig.getMainConfig().getBoolean("set-removed-message-colour-to-red"))
|
if(!DiscordWhitelister.mainConfig.getFileConfiguration().getBoolean("set-removed-message-colour-to-red"))
|
||||||
embedBuilderSuccess = CreateEmbeddedMessage((finalNameToRemove + " has been removed"), (author.getAsMention() + " has removed `" + finalNameToRemove + "` from the whitelist."), EmbedMessageType.SUCCESS);
|
embedBuilderSuccess = CreateEmbeddedMessage((finalNameToRemove + " has been removed"), (author.getAsMention() + " has removed `" + finalNameToRemove + "` from the whitelist."), EmbedMessageType.SUCCESS);
|
||||||
else
|
else
|
||||||
embedBuilderSuccess = CreateEmbeddedMessage((finalNameToRemove + " has been removed"), (author.getAsMention() + " has removed `" + finalNameToRemove + "` from the whitelist."), EmbedMessageType.FAILURE);
|
embedBuilderSuccess = CreateEmbeddedMessage((finalNameToRemove + " has been removed"), (author.getAsMention() + " has removed `" + finalNameToRemove + "` from the whitelist."), EmbedMessageType.FAILURE);
|
||||||
|
@ -460,7 +460,7 @@ public class DiscordClient extends ListenerAdapter
|
||||||
customMessage = customMessage.replaceAll("\\{Sender}", author.getAsMention());
|
customMessage = customMessage.replaceAll("\\{Sender}", author.getAsMention());
|
||||||
customMessage = customMessage.replaceAll("\\{MinecraftUsername}", finalNameToRemove);
|
customMessage = customMessage.replaceAll("\\{MinecraftUsername}", finalNameToRemove);
|
||||||
|
|
||||||
if(!MainConfig.getMainConfig().getBoolean("set-removed-message-colour-to-red"))
|
if(!DiscordWhitelister.mainConfig.getFileConfiguration().getBoolean("set-removed-message-colour-to-red"))
|
||||||
embedBuilderSuccess = CreateEmbeddedMessage(customTitle, customMessage, EmbedMessageType.SUCCESS);
|
embedBuilderSuccess = CreateEmbeddedMessage(customTitle, customMessage, EmbedMessageType.SUCCESS);
|
||||||
else
|
else
|
||||||
embedBuilderSuccess = CreateEmbeddedMessage(customTitle, customMessage, EmbedMessageType.FAILURE);
|
embedBuilderSuccess = CreateEmbeddedMessage(customTitle, customMessage, EmbedMessageType.FAILURE);
|
||||||
|
@ -470,7 +470,7 @@ public class DiscordClient extends ListenerAdapter
|
||||||
{
|
{
|
||||||
String playerUUID = DiscordClient.minecraftUsernameToUUID(finalNameToRemove);
|
String playerUUID = DiscordClient.minecraftUsernameToUUID(finalNameToRemove);
|
||||||
|
|
||||||
if(!MainConfig.getMainConfig().getBoolean("use-crafatar-for-avatars"))
|
if(!DiscordWhitelister.mainConfig.getFileConfiguration().getBoolean("use-crafatar-for-avatars"))
|
||||||
embedBuilderSuccess.setThumbnail("https://minotar.net/armor/bust/" + playerUUID + "/100.png");
|
embedBuilderSuccess.setThumbnail("https://minotar.net/armor/bust/" + playerUUID + "/100.png");
|
||||||
else
|
else
|
||||||
embedBuilderSuccess.setThumbnail("https://crafatar.com/avatars/" + playerUUID + "?size=100&default=MHF_Steve&overlay.png");
|
embedBuilderSuccess.setThumbnail("https://crafatar.com/avatars/" + playerUUID + "?size=100&default=MHF_Steve&overlay.png");
|
||||||
|
@ -557,7 +557,7 @@ public class DiscordClient extends ListenerAdapter
|
||||||
|
|
||||||
if (authorPermissions.isUserCanAdd() && !authorPermissions.isUserCanAddRemove())
|
if (authorPermissions.isUserCanAdd() && !authorPermissions.isUserCanAddRemove())
|
||||||
{
|
{
|
||||||
String higherPermRoles = MainConfig.getMainConfig().getList("add-remove-roles").toString();
|
String higherPermRoles = DiscordWhitelister.mainConfig.getFileConfiguration().getList("add-remove-roles").toString();
|
||||||
higherPermRoles = higherPermRoles.replaceAll("\\[", "");
|
higherPermRoles = higherPermRoles.replaceAll("\\[", "");
|
||||||
higherPermRoles = higherPermRoles.replaceAll("]", "");
|
higherPermRoles = higherPermRoles.replaceAll("]", "");
|
||||||
|
|
||||||
|
@ -652,7 +652,7 @@ public class DiscordClient extends ListenerAdapter
|
||||||
UserList.getUserList().set(userid, null);
|
UserList.getUserList().set(userid, null);
|
||||||
}
|
}
|
||||||
UserList.SaveStore();
|
UserList.SaveStore();
|
||||||
if (MainConfig.getMainConfig().getBoolean("unwhitelist-and-clear-perms-on-name-clear")) {
|
if (DiscordWhitelister.mainConfig.getFileConfiguration().getBoolean("unwhitelist-and-clear-perms-on-name-clear")) {
|
||||||
// Remove name from the whitelist
|
// Remove name from the whitelist
|
||||||
UnWhitelist(splitMessage[userNameIndex]);
|
UnWhitelist(splitMessage[userNameIndex]);
|
||||||
}
|
}
|
||||||
|
@ -663,8 +663,8 @@ public class DiscordClient extends ListenerAdapter
|
||||||
if (nameFound) {
|
if (nameFound) {
|
||||||
// Success message
|
// Success message
|
||||||
if (DiscordWhitelister.useCustomMessages) {
|
if (DiscordWhitelister.useCustomMessages) {
|
||||||
String clearNameTitle = CustomMessagesConfig.getCustomMessagesConfig().getString("clear-name-success-title");
|
String clearNameTitle = DiscordWhitelister.customMessagesConfig.getFileConfiguration().getString("clear-name-success-title");
|
||||||
String clearNameMessage = CustomMessagesConfig.getCustomMessagesConfig().getString("clear-name-success-message");
|
String clearNameMessage = DiscordWhitelister.customMessagesConfig.getFileConfiguration().getString("clear-name-success-message");
|
||||||
|
|
||||||
clearNameMessage = clearNameMessage.replaceAll("\\{Sender}", author.getAsMention());
|
clearNameMessage = clearNameMessage.replaceAll("\\{Sender}", author.getAsMention());
|
||||||
clearNameMessage = clearNameMessage.replaceAll("\\{MinecraftUsername}", splitMessage[userNameIndex]);
|
clearNameMessage = clearNameMessage.replaceAll("\\{MinecraftUsername}", splitMessage[userNameIndex]);
|
||||||
|
@ -688,8 +688,8 @@ public class DiscordClient extends ListenerAdapter
|
||||||
(author.getAsMention() + ", could not find name " + splitMessage[userNameIndex] + " to clear in user list."), EmbedMessageType.FAILURE).build();
|
(author.getAsMention() + ", could not find name " + splitMessage[userNameIndex] + " to clear in user list."), EmbedMessageType.FAILURE).build();
|
||||||
QueueAndRemoveAfterSeconds(channel, messageEmbed);
|
QueueAndRemoveAfterSeconds(channel, messageEmbed);
|
||||||
} else {
|
} else {
|
||||||
String customTitle = CustomMessagesConfig.getCustomMessagesConfig().getString("clear-name-failure-title");
|
String customTitle = DiscordWhitelister.customMessagesConfig.getFileConfiguration().getString("clear-name-failure-title");
|
||||||
String customMessage = CustomMessagesConfig.getCustomMessagesConfig().getString("clear-name-failure-message");
|
String customMessage = DiscordWhitelister.customMessagesConfig.getFileConfiguration().getString("clear-name-failure-message");
|
||||||
customMessage = customMessage.replaceAll("\\{Sender}", author.getAsMention());
|
customMessage = customMessage.replaceAll("\\{Sender}", author.getAsMention());
|
||||||
customMessage = customMessage.replaceAll("\\{MinecraftUsername}", splitMessage[userNameIndex]);
|
customMessage = customMessage.replaceAll("\\{MinecraftUsername}", splitMessage[userNameIndex]);
|
||||||
customTitle = customTitle.replaceAll("\\{MinecraftUsername}", splitMessage[userNameIndex]);
|
customTitle = customTitle.replaceAll("\\{MinecraftUsername}", splitMessage[userNameIndex]);
|
||||||
|
@ -706,7 +706,7 @@ public class DiscordClient extends ListenerAdapter
|
||||||
// Clear whitelists for limited-whitelisters
|
// Clear whitelists for limited-whitelisters
|
||||||
else if (messageContents.toLowerCase().startsWith("!whitelist clear") && !DiscordWhitelister.getUseCustomPrefixes()
|
else if (messageContents.toLowerCase().startsWith("!whitelist clear") && !DiscordWhitelister.getUseCustomPrefixes()
|
||||||
|| DiscordWhitelister.getUseCustomPrefixes() && messageContents.toLowerCase().startsWith(customLimitedWhitelistClearPrefix)) {
|
|| DiscordWhitelister.getUseCustomPrefixes() && messageContents.toLowerCase().startsWith(customLimitedWhitelistClearPrefix)) {
|
||||||
if (!MainConfig.getMainConfig().getBoolean("allow-limited-whitelisters-to-unwhitelist-self"))
|
if (!DiscordWhitelister.mainConfig.getFileConfiguration().getBoolean("allow-limited-whitelisters-to-unwhitelist-self"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// just inform staff, can add custom messages later if really needed
|
// just inform staff, can add custom messages later if really needed
|
||||||
|
@ -767,7 +767,7 @@ public class DiscordClient extends ListenerAdapter
|
||||||
QueueAndRemoveAfterSeconds(channel, messageEmbed);
|
QueueAndRemoveAfterSeconds(channel, messageEmbed);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MainConfig.getMainConfig().getBoolean("whitelisted-role-auto-remove")) {
|
if (DiscordWhitelister.mainConfig.getFileConfiguration().getBoolean("whitelisted-role-auto-remove")) {
|
||||||
// Find all servers bot is in, remove whitelisted roles
|
// Find all servers bot is in, remove whitelisted roles
|
||||||
for (int i = 0; i < javaDiscordAPI.getGuilds().size(); i++) {
|
for (int i = 0; i < javaDiscordAPI.getGuilds().size(); i++) {
|
||||||
// Remove the whitelisted role(s)
|
// Remove the whitelisted role(s)
|
||||||
|
@ -881,8 +881,8 @@ public class DiscordClient extends ListenerAdapter
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
String customTitle = CustomMessagesConfig.getCustomMessagesConfig().getString("clear-ban-success-title");
|
String customTitle = DiscordWhitelister.customMessagesConfig.getFileConfiguration().getString("clear-ban-success-title");
|
||||||
String customMessage = CustomMessagesConfig.getCustomMessagesConfig().getString("clear-ban-success-message");
|
String customMessage = DiscordWhitelister.customMessagesConfig.getFileConfiguration().getString("clear-ban-success-message");
|
||||||
customMessage = customMessage.replaceAll("\\{Sender}", author.getAsMention());
|
customMessage = customMessage.replaceAll("\\{Sender}", author.getAsMention());
|
||||||
customMessage = customMessage.replaceAll("\\{MinecraftUsername}", targetName);
|
customMessage = customMessage.replaceAll("\\{MinecraftUsername}", targetName);
|
||||||
customTitle = customTitle.replaceAll("\\{MinecraftUsername}", targetName);
|
customTitle = customTitle.replaceAll("\\{MinecraftUsername}", targetName);
|
||||||
|
@ -904,8 +904,8 @@ public class DiscordClient extends ListenerAdapter
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
String customTitle = CustomMessagesConfig.getCustomMessagesConfig().getString("clear-ban-failure-title");
|
String customTitle = DiscordWhitelister.customMessagesConfig.getFileConfiguration().getString("clear-ban-failure-title");
|
||||||
String customMessage = CustomMessagesConfig.getCustomMessagesConfig().getString("clear-ban-failure-message");
|
String customMessage = DiscordWhitelister.customMessagesConfig.getFileConfiguration().getString("clear-ban-failure-message");
|
||||||
customMessage = customMessage.replaceAll("\\{Sender}", author.getAsMention());
|
customMessage = customMessage.replaceAll("\\{Sender}", author.getAsMention());
|
||||||
customMessage = customMessage.replaceAll("\\{MinecraftUsername}", targetName);
|
customMessage = customMessage.replaceAll("\\{MinecraftUsername}", targetName);
|
||||||
customTitle = customTitle.replaceAll("\\{MinecraftUsername}", targetName);
|
customTitle = customTitle.replaceAll("\\{MinecraftUsername}", targetName);
|
||||||
|
@ -943,7 +943,7 @@ public class DiscordClient extends ListenerAdapter
|
||||||
}
|
}
|
||||||
|
|
||||||
// Warn if enabled
|
// Warn if enabled
|
||||||
if(MainConfig.getMainConfig().getBoolean("show-warning-in-command-channel"))
|
if(DiscordWhitelister.mainConfig.getFileConfiguration().getBoolean("show-warning-in-command-channel"))
|
||||||
{
|
{
|
||||||
if(!DiscordWhitelister.useCustomMessages)
|
if(!DiscordWhitelister.useCustomMessages)
|
||||||
{
|
{
|
||||||
|
@ -968,7 +968,7 @@ public class DiscordClient extends ListenerAdapter
|
||||||
@Override
|
@Override
|
||||||
public void onGuildMemberRemove(@Nonnull GuildMemberRemoveEvent event)
|
public void onGuildMemberRemove(@Nonnull GuildMemberRemoveEvent event)
|
||||||
{
|
{
|
||||||
if(!MainConfig.getMainConfig().getBoolean("un-whitelist-on-server-leave"))
|
if(!DiscordWhitelister.mainConfig.getFileConfiguration().getBoolean("un-whitelist-on-server-leave"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
String discordUserToRemove = event.getMember().getId();
|
String discordUserToRemove = event.getMember().getId();
|
||||||
|
@ -1287,7 +1287,7 @@ public class DiscordClient extends ListenerAdapter
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ServerLeaveStartupCheck() {
|
public static void ServerLeaveStartupCheck() {
|
||||||
if (MainConfig.getMainConfig().getBoolean("un-whitelist-on-server-leave")) {
|
if (DiscordWhitelister.mainConfig.getFileConfiguration().getBoolean("un-whitelist-on-server-leave")) {
|
||||||
|
|
||||||
// Don't attempt to remove members if not connected
|
// Don't attempt to remove members if not connected
|
||||||
if (javaDiscordAPI.getStatus() != JDA.Status.CONNECTED)
|
if (javaDiscordAPI.getStatus() != JDA.Status.CONNECTED)
|
||||||
|
@ -1574,13 +1574,13 @@ public class DiscordClient extends ListenerAdapter
|
||||||
public static void AssignPerms(String targetPlayerName){
|
public static void AssignPerms(String targetPlayerName){
|
||||||
// For ultra perms:
|
// For ultra perms:
|
||||||
if(DiscordWhitelister.useLuckPerms){
|
if(DiscordWhitelister.useLuckPerms){
|
||||||
for (String s : PermissionsConfig.getPermissionsConfig().getStringList("perms-on-whitelist")) {
|
for (String s : DiscordWhitelister.customPrefixConfig.getFileConfiguration().getStringList("perms-on-whitelist")) {
|
||||||
DiscordClient.ExecuteServerCommand("lp user " + targetPlayerName + " permission set " + s);
|
DiscordClient.ExecuteServerCommand("lp user " + targetPlayerName + " permission set " + s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// For LuckPerms:
|
// For LuckPerms:
|
||||||
if(DiscordWhitelister.useUltraPerms){
|
if(DiscordWhitelister.useUltraPerms){
|
||||||
for (String s : PermissionsConfig.getPermissionsConfig().getStringList("perms-on-whitelist")) {
|
for (String s : DiscordWhitelister.customPrefixConfig.getFileConfiguration().getStringList("perms-on-whitelist")) {
|
||||||
DiscordClient.ExecuteServerCommand("upc addPlayerPermission " + targetPlayerName + " " + s);
|
DiscordClient.ExecuteServerCommand("upc addPlayerPermission " + targetPlayerName + " " + s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1589,13 +1589,13 @@ public class DiscordClient extends ListenerAdapter
|
||||||
public static void RemovePerms(String targetPlayerName){
|
public static void RemovePerms(String targetPlayerName){
|
||||||
// For ultra perms:
|
// For ultra perms:
|
||||||
if(DiscordWhitelister.useLuckPerms){
|
if(DiscordWhitelister.useLuckPerms){
|
||||||
for (String s : PermissionsConfig.getPermissionsConfig().getStringList("perms-on-whitelist")) {
|
for (String s : DiscordWhitelister.customPrefixConfig.getFileConfiguration().getStringList("perms-on-whitelist")) {
|
||||||
DiscordClient.ExecuteServerCommand("lp user " + targetPlayerName + " permission unset " + s);
|
DiscordClient.ExecuteServerCommand("lp user " + targetPlayerName + " permission unset " + s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// For LuckPerms:
|
// For LuckPerms:
|
||||||
if(DiscordWhitelister.useUltraPerms){
|
if(DiscordWhitelister.useUltraPerms){
|
||||||
for (String s : PermissionsConfig.getPermissionsConfig().getStringList("perms-on-whitelist")) {
|
for (String s : DiscordWhitelister.customPrefixConfig.getFileConfiguration().getStringList("perms-on-whitelist")) {
|
||||||
DiscordClient.ExecuteServerCommand("upc removePlayerPermission " + targetPlayerName + " " + s);
|
DiscordClient.ExecuteServerCommand("upc removePlayerPermission " + targetPlayerName + " " + s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,14 @@ public class DiscordWhitelister extends JavaPlugin
|
||||||
|
|
||||||
public static int removeMessageWaitTime = 5;
|
public static int removeMessageWaitTime = 5;
|
||||||
|
|
||||||
|
public static MainConfig mainConfig;
|
||||||
|
|
||||||
|
public static CustomPrefixConfig customPrefixConfig;
|
||||||
|
public static CustomMessagesConfig customMessagesConfig;
|
||||||
|
public static PermissionsConfig permissionsConfig;
|
||||||
|
public static OnWhitelistCommandsConfig onWhitelistCommandsConfig;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable()
|
public void onEnable()
|
||||||
{
|
{
|
||||||
|
@ -89,7 +97,7 @@ public class DiscordWhitelister extends JavaPlugin
|
||||||
return thisPlugin;
|
return thisPlugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FileConfiguration getCustomMessagesConfig() { return CustomMessagesConfig.getCustomMessagesConfig(); }
|
public static FileConfiguration getCustomMessagesConfig() { return customMessagesConfig.getFileConfiguration(); }
|
||||||
|
|
||||||
public static Logger getPluginLogger() { return pluginLogger; }
|
public static Logger getPluginLogger() { return pluginLogger; }
|
||||||
|
|
||||||
|
@ -110,59 +118,59 @@ public class DiscordWhitelister extends JavaPlugin
|
||||||
|
|
||||||
ConfigSetup();
|
ConfigSetup();
|
||||||
|
|
||||||
botToken = MainConfig.getMainConfig().getString("discord-bot-token");
|
botToken = mainConfig.getFileConfiguration().getString("discord-bot-token");
|
||||||
botEnabled = MainConfig.getMainConfig().getBoolean("bot-enabled");
|
botEnabled = mainConfig.getFileConfiguration().getBoolean("bot-enabled");
|
||||||
showPlayerSkin = MainConfig.getMainConfig().getBoolean("show-player-skin-on-whitelist");
|
showPlayerSkin = mainConfig.getFileConfiguration().getBoolean("show-player-skin-on-whitelist");
|
||||||
configCreated = MainConfig.configCreated;
|
configCreated = mainConfig.fileCreated;
|
||||||
showVanishedPlayersInCount = MainConfig.getMainConfig().getBoolean("show-vanished-players-in-player-count");
|
showVanishedPlayersInCount = mainConfig.getFileConfiguration().getBoolean("show-vanished-players-in-player-count");
|
||||||
useInGameAddRemoves = MainConfig.getMainConfig().getBoolean("add-in-game-adds-and-removes-to-list");
|
useInGameAddRemoves = mainConfig.getFileConfiguration().getBoolean("add-in-game-adds-and-removes-to-list");
|
||||||
useOnBanEvents = MainConfig.getMainConfig().getBoolean("use-on-ban-events");
|
useOnBanEvents = mainConfig.getFileConfiguration().getBoolean("use-on-ban-events");
|
||||||
removeUnnecessaryMessages = MainConfig.getMainConfig().getBoolean("remove-unnecessary-messages-from-whitelist-channel");
|
removeUnnecessaryMessages = mainConfig.getFileConfiguration().getBoolean("remove-unnecessary-messages-from-whitelist-channel");
|
||||||
removeMessageWaitTime = MainConfig.getMainConfig().getInt("seconds-to-remove-message-from-whitelist-channel");
|
removeMessageWaitTime = mainConfig.getFileConfiguration().getInt("seconds-to-remove-message-from-whitelist-channel");
|
||||||
useOnWhitelistCommands = MainConfig.getMainConfig().getBoolean("use-on-whitelist-commands");
|
useOnWhitelistCommands = mainConfig.getFileConfiguration().getBoolean("use-on-whitelist-commands");
|
||||||
|
|
||||||
// Check for LuckPerms first
|
// Check for LuckPerms first
|
||||||
if(MainConfig.getMainConfig().getBoolean("assign-perms-with-luck-perms"))
|
if(mainConfig.getFileConfiguration().getBoolean("assign-perms-with-luck-perms"))
|
||||||
{
|
{
|
||||||
if(DiscordWhitelister.getPlugin().getServer().getPluginManager().getPlugin("LuckPerms") != null)
|
if(getPlugin().getServer().getPluginManager().getPlugin("LuckPerms") != null)
|
||||||
{
|
{
|
||||||
useLuckPerms = true;
|
useLuckPerms = true;
|
||||||
DiscordWhitelister.getPluginLogger().info("LuckPerms found!");
|
getPluginLogger().info("LuckPerms found!");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DiscordWhitelister.getPluginLogger().warning("LuckPerms was not found but is enabled in the config. Doing nothing...");
|
getPluginLogger().warning("LuckPerms was not found but is enabled in the config. Doing nothing...");
|
||||||
useLuckPerms = false;
|
useLuckPerms = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(MainConfig.getMainConfig().getBoolean("assign-perms-with-ultra-perms"))
|
if(mainConfig.getFileConfiguration().getBoolean("assign-perms-with-ultra-perms"))
|
||||||
{
|
{
|
||||||
if(DiscordWhitelister.getPlugin().getServer().getPluginManager().getPlugin("UltraPermissions") != null)
|
if(getPlugin().getServer().getPluginManager().getPlugin("UltraPermissions") != null)
|
||||||
{
|
{
|
||||||
useUltraPerms = true;
|
useUltraPerms = true;
|
||||||
DiscordWhitelister.getPluginLogger().info("Ultra Permissions found!");
|
getPluginLogger().info("Ultra Permissions found!");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DiscordWhitelister.getPluginLogger().warning("Ultra Permissions was not found but is enabled in the config. Doing nothing...");
|
getPluginLogger().warning("Ultra Permissions was not found but is enabled in the config. Doing nothing...");
|
||||||
useUltraPerms = false;
|
useUltraPerms = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove in favour of split versions
|
// TODO: remove in favour of split versions
|
||||||
DiscordClient.customWhitelistAddPrefix = CustomPrefixConfig.getCustomPrefixesConfig().getString("whitelist-add-prefix").toLowerCase();
|
DiscordClient.customWhitelistAddPrefix = customPrefixConfig.getFileConfiguration().getString("whitelist-add-prefix").toLowerCase();
|
||||||
DiscordClient.customWhitelistRemovePrefix = CustomPrefixConfig.getCustomPrefixesConfig().getString("whitelist-remove-prefix").toLowerCase();
|
DiscordClient.customWhitelistRemovePrefix = customPrefixConfig.getFileConfiguration().getString("whitelist-remove-prefix").toLowerCase();
|
||||||
DiscordClient.customClearNamePrefix = CustomPrefixConfig.getCustomPrefixesConfig().getString("clear-name-prefix").toLowerCase();
|
DiscordClient.customClearNamePrefix = customPrefixConfig.getFileConfiguration().getString("clear-name-prefix").toLowerCase();
|
||||||
DiscordClient.customLimitedWhitelistClearPrefix = CustomPrefixConfig.getCustomPrefixesConfig().getString("limited-whitelist-clear-prefix").toLowerCase();
|
DiscordClient.customLimitedWhitelistClearPrefix = customPrefixConfig.getFileConfiguration().getString("limited-whitelist-clear-prefix").toLowerCase();
|
||||||
DiscordClient.customClearBanPrefix = CustomPrefixConfig.getCustomPrefixesConfig().getString("clear-ban-prefix").toLowerCase();
|
DiscordClient.customClearBanPrefix = customPrefixConfig.getFileConfiguration().getString("clear-ban-prefix").toLowerCase();
|
||||||
|
|
||||||
// Split versions
|
// Split versions
|
||||||
DiscordClient.customWhitelistAddPrefixSplit = CustomPrefixConfig.getCustomPrefixesConfig().getString("whitelist-add-prefix").toLowerCase().trim().split(" ");
|
DiscordClient.customWhitelistAddPrefixSplit = customPrefixConfig.getFileConfiguration().getString("whitelist-add-prefix").toLowerCase().trim().split(" ");
|
||||||
DiscordClient.customWhitelistRemovePrefixSplit = CustomPrefixConfig.getCustomPrefixesConfig().getString("whitelist-remove-prefix").toLowerCase().trim().split(" ");
|
DiscordClient.customWhitelistRemovePrefixSplit = customPrefixConfig.getFileConfiguration().getString("whitelist-remove-prefix").toLowerCase().trim().split(" ");
|
||||||
DiscordClient.customClearNamePrefixSplit = CustomPrefixConfig.getCustomPrefixesConfig().getString("clear-name-prefix").toLowerCase().trim().split(" ");
|
DiscordClient.customClearNamePrefixSplit = customPrefixConfig.getFileConfiguration().getString("clear-name-prefix").toLowerCase().trim().split(" ");
|
||||||
DiscordClient.customLimitedWhitelistClearPrefixSplit = CustomPrefixConfig.getCustomPrefixesConfig().getString("limited-whitelist-clear-prefix").toLowerCase().trim().split(" ");
|
DiscordClient.customLimitedWhitelistClearPrefixSplit = customPrefixConfig.getFileConfiguration().getString("limited-whitelist-clear-prefix").toLowerCase().trim().split(" ");
|
||||||
DiscordClient.customClearBanPrefixSplit = CustomPrefixConfig.getCustomPrefixesConfig().getString("clear-ban-prefix").toLowerCase().trim().split(" ");
|
DiscordClient.customClearBanPrefixSplit = customPrefixConfig.getFileConfiguration().getString("clear-ban-prefix").toLowerCase().trim().split(" ");
|
||||||
DiscordClient.customWhoIsPrefix = CustomPrefixConfig.getCustomPrefixesConfig().getString("whitelist-whois-prefix").toLowerCase().trim().split(" ");
|
DiscordClient.customWhoIsPrefix = customPrefixConfig.getFileConfiguration().getString("whitelist-whois-prefix").toLowerCase().trim().split(" ");
|
||||||
|
|
||||||
if(!botEnabled)
|
if(!botEnabled)
|
||||||
{
|
{
|
||||||
|
@ -177,33 +185,33 @@ public class DiscordWhitelister extends JavaPlugin
|
||||||
pluginLogger.info("Initializing Discord client...");
|
pluginLogger.info("Initializing Discord client...");
|
||||||
|
|
||||||
// TODO: below role section could be moved to DiscordClient class
|
// TODO: below role section could be moved to DiscordClient class
|
||||||
useIdForRoles = MainConfig.getMainConfig().getBoolean("use-id-for-roles");
|
useIdForRoles = mainConfig.getFileConfiguration().getBoolean("use-id-for-roles");
|
||||||
|
|
||||||
// set add & remove roles
|
// set add & remove roles
|
||||||
DiscordClient.allowedToAddRemoveRoles = new String[MainConfig.getMainConfig().getList("add-remove-roles").size()];
|
DiscordClient.allowedToAddRemoveRoles = new String[mainConfig.getFileConfiguration().getList("add-remove-roles").size()];
|
||||||
for(int roles = 0; roles < DiscordClient.allowedToAddRemoveRoles.length; ++roles)
|
for(int roles = 0; roles < DiscordClient.allowedToAddRemoveRoles.length; ++roles)
|
||||||
{
|
{
|
||||||
DiscordClient.allowedToAddRemoveRoles[roles] = MainConfig.getMainConfig().getList("add-remove-roles").get(roles).toString();
|
DiscordClient.allowedToAddRemoveRoles[roles] = mainConfig.getFileConfiguration().getList("add-remove-roles").get(roles).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// set add roles
|
// set add roles
|
||||||
DiscordClient.allowedToAddRoles = new String[MainConfig.getMainConfig().getList("add-roles").size()];
|
DiscordClient.allowedToAddRoles = new String[mainConfig.getFileConfiguration().getList("add-roles").size()];
|
||||||
for(int roles = 0; roles < DiscordClient.allowedToAddRoles.length; ++roles)
|
for(int roles = 0; roles < DiscordClient.allowedToAddRoles.length; ++roles)
|
||||||
{
|
{
|
||||||
DiscordClient.allowedToAddRoles[roles] = MainConfig.getMainConfig().getList("add-roles").get(roles).toString();
|
DiscordClient.allowedToAddRoles[roles] = mainConfig.getFileConfiguration().getList("add-roles").get(roles).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// set limited add roles
|
// set limited add roles
|
||||||
DiscordClient.allowedToAddLimitedRoles = new String[MainConfig.getMainConfig().getList("limited-add-roles").size()];
|
DiscordClient.allowedToAddLimitedRoles = new String[mainConfig.getFileConfiguration().getList("limited-add-roles").size()];
|
||||||
for(int roles = 0; roles < DiscordClient.allowedToAddLimitedRoles.length; ++roles)
|
for(int roles = 0; roles < DiscordClient.allowedToAddLimitedRoles.length; ++roles)
|
||||||
{
|
{
|
||||||
DiscordClient.allowedToAddLimitedRoles[roles] = MainConfig.getMainConfig().getList("limited-add-roles").get(roles).toString();
|
DiscordClient.allowedToAddLimitedRoles[roles] = mainConfig.getFileConfiguration().getList("limited-add-roles").get(roles).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get banned roles
|
// Get banned roles
|
||||||
if(useOnBanEvents)
|
if(useOnBanEvents)
|
||||||
{
|
{
|
||||||
List<String> tempBannedRoles = MainConfig.getMainConfig().getStringList("banned-roles");
|
List<String> tempBannedRoles = mainConfig.getFileConfiguration().getStringList("banned-roles");
|
||||||
bannedRoles = new String[tempBannedRoles.size()];
|
bannedRoles = new String[tempBannedRoles.size()];
|
||||||
for(int i = 0; i < tempBannedRoles.size(); i++)
|
for(int i = 0; i < tempBannedRoles.size(); i++)
|
||||||
{
|
{
|
||||||
|
@ -212,10 +220,10 @@ public class DiscordWhitelister extends JavaPlugin
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allowed to clear name roles
|
// Allowed to clear name roles
|
||||||
DiscordClient.allowedToClearNamesRoles = new String[MainConfig.getMainConfig().getStringList("clear-command-roles").size()];
|
DiscordClient.allowedToClearNamesRoles = new String[mainConfig.getFileConfiguration().getStringList("clear-command-roles").size()];
|
||||||
for(int roles = 0; roles < DiscordClient.allowedToClearNamesRoles.length; roles++)
|
for(int roles = 0; roles < DiscordClient.allowedToClearNamesRoles.length; roles++)
|
||||||
{
|
{
|
||||||
DiscordClient.allowedToClearNamesRoles[roles] = MainConfig.getMainConfig().getStringList("clear-command-roles").get(roles);
|
DiscordClient.allowedToClearNamesRoles[roles] = mainConfig.getFileConfiguration().getStringList("clear-command-roles").get(roles);
|
||||||
}
|
}
|
||||||
|
|
||||||
// All roles combined for role check
|
// All roles combined for role check
|
||||||
|
@ -224,8 +232,8 @@ public class DiscordWhitelister extends JavaPlugin
|
||||||
.flatMap(Stream::of).toArray(String[]::new);
|
.flatMap(Stream::of).toArray(String[]::new);
|
||||||
|
|
||||||
// Custom messages check
|
// Custom messages check
|
||||||
useCustomMessages = MainConfig.getMainConfig().getBoolean("use-custom-messages");
|
useCustomMessages = mainConfig.getFileConfiguration().getBoolean("use-custom-messages");
|
||||||
useCustomPrefixes = MainConfig.getMainConfig().getBoolean("use-custom-prefixes");
|
useCustomPrefixes = mainConfig.getFileConfiguration().getBoolean("use-custom-prefixes");
|
||||||
|
|
||||||
int initSuccess = DiscordClient.InitializeClient(botToken);
|
int initSuccess = DiscordClient.InitializeClient(botToken);
|
||||||
|
|
||||||
|
@ -235,7 +243,7 @@ public class DiscordWhitelister extends JavaPlugin
|
||||||
|
|
||||||
// No need for an if here statement anymore as this code will not run if the client has not been initialized
|
// No need for an if here statement anymore as this code will not run if the client has not been initialized
|
||||||
// Only attempt to set player count if the bot successfully initialized
|
// Only attempt to set player count if the bot successfully initialized
|
||||||
if(MainConfig.getMainConfig().getBoolean("show-player-count"))
|
if(mainConfig.getFileConfiguration().getBoolean("show-player-count"))
|
||||||
{
|
{
|
||||||
// Register events if enabled
|
// Register events if enabled
|
||||||
thisServer.getPluginManager().registerEvents(new JoinLeaveEvents(), thisPlugin);
|
thisServer.getPluginManager().registerEvents(new JoinLeaveEvents(), thisPlugin);
|
||||||
|
@ -260,13 +268,18 @@ public class DiscordWhitelister extends JavaPlugin
|
||||||
|
|
||||||
public static void ConfigSetup()
|
public static void ConfigSetup()
|
||||||
{
|
{
|
||||||
// Run this first, as it creates the root folder if it does not exist
|
mainConfig = new MainConfig();
|
||||||
MainConfig.ConfigSetup();
|
customPrefixConfig = new CustomPrefixConfig();
|
||||||
|
customMessagesConfig = new CustomMessagesConfig();
|
||||||
|
permissionsConfig = new PermissionsConfig();
|
||||||
|
onWhitelistCommandsConfig = new OnWhitelistCommandsConfig();
|
||||||
|
|
||||||
CustomPrefixConfig.ConfigSetup();
|
// Run this first, as it creates the root folder if it does not exist
|
||||||
CustomMessagesConfig.ConfigSetup();
|
mainConfig.ConfigSetup();
|
||||||
PermissionsConfig.ConfigSetup();
|
customPrefixConfig.ConfigSetup();
|
||||||
OnWhitelistCommandsConfig.ConfigSetup();
|
customMessagesConfig.ConfigSetup();
|
||||||
|
permissionsConfig.ConfigSetup();
|
||||||
|
onWhitelistCommandsConfig.ConfigSetup();
|
||||||
|
|
||||||
// Init Stores
|
// Init Stores
|
||||||
UserList.StoreSetup();
|
UserList.StoreSetup();
|
||||||
|
|
|
@ -6,9 +6,6 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
import uk.co.angrybee.joe.AuthorPermissions;
|
import uk.co.angrybee.joe.AuthorPermissions;
|
||||||
import uk.co.angrybee.joe.DiscordClient;
|
import uk.co.angrybee.joe.DiscordClient;
|
||||||
import uk.co.angrybee.joe.DiscordWhitelister;
|
import uk.co.angrybee.joe.DiscordWhitelister;
|
||||||
import uk.co.angrybee.joe.configs.MainConfig;
|
|
||||||
import uk.co.angrybee.joe.configs.OnWhitelistCommandsConfig;
|
|
||||||
import uk.co.angrybee.joe.configs.PermissionsConfig;
|
|
||||||
import uk.co.angrybee.joe.stores.InGameRemovedList;
|
import uk.co.angrybee.joe.stores.InGameRemovedList;
|
||||||
import uk.co.angrybee.joe.stores.RemovedList;
|
import uk.co.angrybee.joe.stores.RemovedList;
|
||||||
import uk.co.angrybee.joe.stores.UserList;
|
import uk.co.angrybee.joe.stores.UserList;
|
||||||
|
@ -17,7 +14,6 @@ import uk.co.angrybee.joe.stores.WhitelistedPlayers;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Queue;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
@ -438,7 +434,7 @@ public class CommandAdd
|
||||||
|
|
||||||
if(DiscordWhitelister.showPlayerSkin)
|
if(DiscordWhitelister.showPlayerSkin)
|
||||||
{
|
{
|
||||||
if(!MainConfig.getMainConfig().getBoolean("use-crafatar-for-avatars"))
|
if(!DiscordWhitelister.mainConfig.getFileConfiguration().getBoolean("use-crafatar-for-avatars"))
|
||||||
embedBuilderWhitelistSuccess.setThumbnail("https://minotar.net/armor/bust/" + playerUUID + "/100.png");
|
embedBuilderWhitelistSuccess.setThumbnail("https://minotar.net/armor/bust/" + playerUUID + "/100.png");
|
||||||
else
|
else
|
||||||
embedBuilderWhitelistSuccess.setThumbnail("https://crafatar.com/avatars/" + playerUUID + "?size=100&default=MHF_Steve&overlay.png");
|
embedBuilderWhitelistSuccess.setThumbnail("https://crafatar.com/avatars/" + playerUUID + "?size=100&default=MHF_Steve&overlay.png");
|
||||||
|
@ -474,7 +470,7 @@ public class CommandAdd
|
||||||
|
|
||||||
if (!WhitelistedPlayers.usingEasyWhitelist && authorPermissions.isUserCanUseCommand())
|
if (!WhitelistedPlayers.usingEasyWhitelist && authorPermissions.isUserCanUseCommand())
|
||||||
DiscordClient.ExecuteServerCommand("whitelist add " + finalNameToAdd);
|
DiscordClient.ExecuteServerCommand("whitelist add " + finalNameToAdd);
|
||||||
if(MainConfig.getMainConfig().getBoolean("use-geyser/floodgate-compatibility")) {
|
if(DiscordWhitelister.mainConfig.getFileConfiguration().getBoolean("use-geyser/floodgate-compatibility")) {
|
||||||
addBedrockUser(finalNameToAdd);
|
addBedrockUser(finalNameToAdd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -497,7 +493,7 @@ public class CommandAdd
|
||||||
|
|
||||||
if(DiscordWhitelister.useOnWhitelistCommands)
|
if(DiscordWhitelister.useOnWhitelistCommands)
|
||||||
{
|
{
|
||||||
List<String> commandsToExecute = OnWhitelistCommandsConfig.getPermissionsConfig().getStringList("on-whitelist-commands");
|
List<String> commandsToExecute = DiscordWhitelister.onWhitelistCommandsConfig.getFileConfiguration().getStringList("on-whitelist-commands");
|
||||||
for (String command : commandsToExecute)
|
for (String command : commandsToExecute)
|
||||||
{
|
{
|
||||||
DiscordClient.CheckAndExecuteCommand(command, finalNameToAdd);
|
DiscordClient.CheckAndExecuteCommand(command, finalNameToAdd);
|
||||||
|
@ -558,15 +554,15 @@ public class CommandAdd
|
||||||
// Instructional message
|
// Instructional message
|
||||||
if(successfulWhitelist.get())
|
if(successfulWhitelist.get())
|
||||||
{
|
{
|
||||||
if(MainConfig.getMainConfig().getBoolean("send-instructional-message-on-whitelist"))
|
if(DiscordWhitelister.mainConfig.getFileConfiguration().getBoolean("send-instructional-message-on-whitelist"))
|
||||||
{
|
{
|
||||||
if(!MainConfig.getMainConfig().getBoolean("use-timer-for-instructional-message"))
|
if(!DiscordWhitelister.mainConfig.getFileConfiguration().getBoolean("use-timer-for-instructional-message"))
|
||||||
{
|
{
|
||||||
channel.sendMessage(DiscordClient.CreateInstructionalMessage()).queue();
|
channel.sendMessage(DiscordClient.CreateInstructionalMessage()).queue();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int waitTime = MainConfig.getMainConfig().getInt("timer-wait-time-in-seconds");
|
int waitTime = DiscordWhitelister.mainConfig.getFileConfiguration().getInt("timer-wait-time-in-seconds");
|
||||||
|
|
||||||
// Run on a new thread to not block main thread
|
// Run on a new thread to not block main thread
|
||||||
Thread whitelisterTimerThread = new Thread(() ->
|
Thread whitelisterTimerThread = new Thread(() ->
|
||||||
|
@ -618,7 +614,7 @@ public class CommandAdd
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addBedrockUser(String finalNameToAdd) {
|
private static void addBedrockUser(String finalNameToAdd) {
|
||||||
String bedrockPrefix = MainConfig.getMainConfig().getString("geyser/floodgate prefix");
|
String bedrockPrefix = DiscordWhitelister.mainConfig.getFileConfiguration().getString("geyser/floodgate prefix");
|
||||||
String bedrockName = bedrockPrefix + finalNameToAdd;
|
String bedrockName = bedrockPrefix + finalNameToAdd;
|
||||||
if(bedrockName.length() > 16) {
|
if(bedrockName.length() > 16) {
|
||||||
bedrockName = bedrockName.substring(0, 16);
|
bedrockName = bedrockName.substring(0, 16);
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
package uk.co.angrybee.joe.configs;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import uk.co.angrybee.joe.DiscordWhitelister;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class Config {
|
||||||
|
|
||||||
|
protected String fileName;
|
||||||
|
protected File file;
|
||||||
|
protected FileConfiguration fileConfiguration;
|
||||||
|
protected boolean fileCreated = false;
|
||||||
|
|
||||||
|
public FileConfiguration getFileConfiguration() { return fileConfiguration; }
|
||||||
|
|
||||||
|
|
||||||
|
protected void CreateConfig()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
file.createNewFile();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
DiscordWhitelister.getPluginLogger().info("Created file " + fileName);
|
||||||
|
fileCreated = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void LoadConfigFile()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
fileConfiguration.load(file);
|
||||||
|
}
|
||||||
|
catch (IOException | InvalidConfigurationException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void SaveConfig()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
fileConfiguration.save(file.getPath());
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CheckEntry(String entryName, Object passedValue)
|
||||||
|
{
|
||||||
|
if(fileConfiguration.get(entryName) == null)
|
||||||
|
{
|
||||||
|
fileConfiguration.set(entryName, passedValue);
|
||||||
|
|
||||||
|
if(!fileCreated)
|
||||||
|
DiscordWhitelister.getPluginLogger().warning("Entry '" + entryName + "' was not found, adding it to "+fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,29 +1,22 @@
|
||||||
package uk.co.angrybee.joe.configs;
|
package uk.co.angrybee.joe.configs;
|
||||||
|
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import uk.co.angrybee.joe.DiscordWhitelister;
|
import uk.co.angrybee.joe.DiscordWhitelister;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
// custom-messages.yml
|
// custom-messages.yml
|
||||||
public class CustomMessagesConfig
|
public class CustomMessagesConfig extends Config
|
||||||
{
|
{
|
||||||
private static File customMessagesFile;
|
public CustomMessagesConfig(){
|
||||||
private static FileConfiguration customMessagesConfig;
|
fileName = "custom-messages.yml";
|
||||||
|
file = new File(DiscordWhitelister.getPlugin().getDataFolder(), fileName);
|
||||||
|
fileConfiguration = new YamlConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
public static FileConfiguration getCustomMessagesConfig() { return customMessagesConfig; }
|
public void ConfigSetup()
|
||||||
|
|
||||||
private static boolean customMessagesFileCreated = false;
|
|
||||||
|
|
||||||
public static void ConfigSetup()
|
|
||||||
{
|
{
|
||||||
customMessagesFile = new File(DiscordWhitelister.getPlugin().getDataFolder(), "custom-messages.yml");
|
if(!file.exists())
|
||||||
customMessagesConfig = new YamlConfiguration();
|
|
||||||
|
|
||||||
if(!customMessagesFile.exists())
|
|
||||||
CreateConfig();
|
CreateConfig();
|
||||||
|
|
||||||
LoadConfigFile();
|
LoadConfigFile();
|
||||||
|
@ -31,34 +24,7 @@ public class CustomMessagesConfig
|
||||||
SaveConfig();
|
SaveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void CreateConfig()
|
private void CheckEntries()
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
customMessagesFile.createNewFile();
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
DiscordWhitelister.getPluginLogger().info("Custom messages file created at: " + customMessagesFile.getPath());
|
|
||||||
customMessagesFileCreated = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void LoadConfigFile()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
customMessagesConfig.load(customMessagesFile);
|
|
||||||
}
|
|
||||||
catch (IOException | InvalidConfigurationException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void CheckEntries()
|
|
||||||
{
|
{
|
||||||
/* TODO: add a YAML comment (#) explaining the config file params
|
/* TODO: add a YAML comment (#) explaining the config file params
|
||||||
NOTE: only {params} in the original messages will be evaluated. For example: using {MaxWhitelistAmount} in the "insufficient-permissions" String will not work as it was never in the original message.
|
NOTE: only {params} in the original messages will be evaluated. For example: using {MaxWhitelistAmount} in the "insufficient-permissions" String will not work as it was never in the original message.
|
||||||
|
@ -66,7 +32,7 @@ public class CustomMessagesConfig
|
||||||
{MinecraftUsername} == finalNameToAdd/Remove, {StaffMember} == DiscordWhitelister.getRemovedList().get(finalNameToAdd), {AddRemoveRoles} = DiscordWhitelister.getWhitelisterBotConfig().getList("add-remove-roles")
|
{MinecraftUsername} == finalNameToAdd/Remove, {StaffMember} == DiscordWhitelister.getRemovedList().get(finalNameToAdd), {AddRemoveRoles} = DiscordWhitelister.getWhitelisterBotConfig().getList("add-remove-roles")
|
||||||
Internal error messages & info messages will remain uneditable. No need to add custom remove failure messages as it should never happen */
|
Internal error messages & info messages will remain uneditable. No need to add custom remove failure messages as it should never happen */
|
||||||
|
|
||||||
if(customMessagesFile.exists())
|
if(file.exists())
|
||||||
{
|
{
|
||||||
CheckEntry("insufficient-permissions-title", "Insufficient Permissions");
|
CheckEntry("insufficient-permissions-title", "Insufficient Permissions");
|
||||||
CheckEntry("insufficient-permissions", "{Sender}, you do not have permission to use this command.");
|
CheckEntry("insufficient-permissions", "{Sender}, you do not have permission to use this command.");
|
||||||
|
@ -135,27 +101,4 @@ public class CustomMessagesConfig
|
||||||
CheckEntry("command-channel-message", "{Sender}, this channel is for commands only, please use another channel.");
|
CheckEntry("command-channel-message", "{Sender}, this channel is for commands only, please use another channel.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SaveConfig()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
customMessagesConfig.save(customMessagesFile.getPath());
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void CheckEntry(String entryName, Object passedValue)
|
|
||||||
{
|
|
||||||
if(customMessagesConfig.get(entryName) == null)
|
|
||||||
{
|
|
||||||
customMessagesConfig.set(entryName, passedValue);
|
|
||||||
|
|
||||||
if(!customMessagesFileCreated)
|
|
||||||
DiscordWhitelister.getPluginLogger().warning("Entry '" + entryName + "' was not found, adding it to custom-messages.yml...");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package uk.co.angrybee.joe.configs;
|
package uk.co.angrybee.joe.configs;
|
||||||
|
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import uk.co.angrybee.joe.DiscordWhitelister;
|
import uk.co.angrybee.joe.DiscordWhitelister;
|
||||||
|
|
||||||
|
@ -9,21 +8,18 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
// custom-prefixes.yml
|
// custom-prefixes.yml
|
||||||
public class CustomPrefixConfig
|
public class CustomPrefixConfig extends Config
|
||||||
{
|
{
|
||||||
private static File customPrefixesFile;
|
public CustomPrefixConfig() {
|
||||||
private static FileConfiguration customPrefixesConfig;
|
file = new File(DiscordWhitelister.getPlugin().getDataFolder(), "custom-prefixes.yml");
|
||||||
|
fileConfiguration = new YamlConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
public static FileConfiguration getCustomPrefixesConfig() { return customPrefixesConfig; }
|
public void ConfigSetup()
|
||||||
|
|
||||||
private static boolean customPrefixesFileCreated = false;
|
|
||||||
|
|
||||||
public static void ConfigSetup()
|
|
||||||
{
|
{
|
||||||
customPrefixesFile = new File(DiscordWhitelister.getPlugin().getDataFolder(), "custom-prefixes.yml");
|
|
||||||
customPrefixesConfig = new YamlConfiguration();
|
|
||||||
|
|
||||||
if(!customPrefixesFile.exists())
|
|
||||||
|
if(!file.exists())
|
||||||
CreateConfig();
|
CreateConfig();
|
||||||
|
|
||||||
LoadConfigFile();
|
LoadConfigFile();
|
||||||
|
@ -31,36 +27,9 @@ public class CustomPrefixConfig
|
||||||
SaveConfig();
|
SaveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void CreateConfig()
|
private void CheckEntries()
|
||||||
{
|
{
|
||||||
try
|
if(file.exists())
|
||||||
{
|
|
||||||
customPrefixesFile.createNewFile();
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
DiscordWhitelister.getPluginLogger().info("Custom Prefixes file created at: " + customPrefixesFile.getPath());
|
|
||||||
customPrefixesFileCreated = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void LoadConfigFile()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
customPrefixesConfig.load(customPrefixesFile);
|
|
||||||
}
|
|
||||||
catch (IOException | InvalidConfigurationException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void CheckEntries()
|
|
||||||
{
|
|
||||||
if(customPrefixesFile.exists())
|
|
||||||
{
|
{
|
||||||
CheckEntry("whitelist-add-prefix", "!whitelist add");
|
CheckEntry("whitelist-add-prefix", "!whitelist add");
|
||||||
|
|
||||||
|
@ -75,27 +44,4 @@ public class CustomPrefixConfig
|
||||||
CheckEntry("whitelist-whois-prefix", "!whitelist whois");
|
CheckEntry("whitelist-whois-prefix", "!whitelist whois");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SaveConfig()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
customPrefixesConfig.save(customPrefixesFile.getPath());
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void CheckEntry(String entryName, Object passedValue)
|
|
||||||
{
|
|
||||||
if(customPrefixesConfig.get(entryName) == null)
|
|
||||||
{
|
|
||||||
customPrefixesConfig.set(entryName, passedValue);
|
|
||||||
|
|
||||||
if(!customPrefixesFileCreated)
|
|
||||||
DiscordWhitelister.getPluginLogger().warning("Entry '" + entryName + "' was not found, adding it to custom-prefixes.yml...");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package uk.co.angrybee.joe.configs;
|
package uk.co.angrybee.joe.configs;
|
||||||
|
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import uk.co.angrybee.joe.DiscordWhitelister;
|
import uk.co.angrybee.joe.DiscordWhitelister;
|
||||||
|
@ -11,66 +10,42 @@ import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
// discord-whitelister.yml
|
// discord-whitelister.yml
|
||||||
public class MainConfig
|
public class MainConfig extends Config {
|
||||||
{
|
public MainConfig() {
|
||||||
private static File whitelisterBotConfigFile;
|
fileName = "discord-whitelister.yml";
|
||||||
private static FileConfiguration whitelisterBotConfig;
|
file = new File(DiscordWhitelister.getPlugin().getDataFolder(), fileName);
|
||||||
|
fileConfiguration = new YamlConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
public static FileConfiguration getMainConfig() { return whitelisterBotConfig; }
|
public FileConfiguration getFileConfiguration() {
|
||||||
|
return fileConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean configCreated = false;
|
public boolean fileCreated = false;
|
||||||
|
|
||||||
|
public void ConfigSetup() {
|
||||||
|
|
||||||
public static void ConfigSetup()
|
|
||||||
{
|
|
||||||
whitelisterBotConfigFile = new File(DiscordWhitelister.getPlugin().getDataFolder(), "discord-whitelister.yml");
|
|
||||||
whitelisterBotConfig = new YamlConfiguration();
|
|
||||||
|
|
||||||
// Create root folder for configs if it does not exist
|
// Create root folder for configs if it does not exist
|
||||||
if(!whitelisterBotConfigFile.getParentFile().exists())
|
if (!file.getParentFile().exists())
|
||||||
whitelisterBotConfigFile.getParentFile().mkdirs();
|
file.getParentFile().mkdirs();
|
||||||
|
|
||||||
if(!whitelisterBotConfigFile.exists())
|
if (!file.exists()) {
|
||||||
CreateConfig();
|
CreateConfig();
|
||||||
|
DiscordWhitelister.getPluginLogger().info("Configuration file created at: " + file.getPath() +
|
||||||
|
", please edit this else the plugin will not work!");
|
||||||
|
}
|
||||||
LoadConfigFile();
|
LoadConfigFile();
|
||||||
CheckEntries();
|
CheckEntries();
|
||||||
SaveConfig();
|
SaveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void CreateConfig()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
whitelisterBotConfigFile.createNewFile();
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
DiscordWhitelister.getPluginLogger().info("Configuration file created at: " + whitelisterBotConfigFile.getPath() +
|
private void CheckEntries() {
|
||||||
", please edit this else the plugin will not work!");
|
|
||||||
configCreated = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void LoadConfigFile()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
whitelisterBotConfig.load(whitelisterBotConfigFile);
|
|
||||||
}
|
|
||||||
catch (IOException | InvalidConfigurationException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void CheckEntries()
|
|
||||||
{
|
|
||||||
CheckEntry("bot-enabled", true);
|
CheckEntry("bot-enabled", true);
|
||||||
|
|
||||||
CheckEntry("discord-bot-token",
|
CheckEntry("discord-bot-token",
|
||||||
"Discord bot token goes here, you can find it here: https://discordapp.com/developers/applications/" );
|
"Discord bot token goes here, you can find it here: https://discordapp.com/developers/applications/");
|
||||||
|
|
||||||
CheckEntry("use-id-for-roles", false);
|
CheckEntry("use-id-for-roles", false);
|
||||||
|
|
||||||
|
@ -168,45 +143,20 @@ public class MainConfig
|
||||||
CheckEntry("role-to-check-for", "Twitch Subscriber");
|
CheckEntry("role-to-check-for", "Twitch Subscriber");
|
||||||
|
|
||||||
// Remove old role entry if found, move role to new array (for people with v1.3.6 or below)
|
// Remove old role entry if found, move role to new array (for people with v1.3.6 or below)
|
||||||
if(whitelisterBotConfig.get("whitelisted-role") != null)
|
if (fileConfiguration.get("whitelisted-role") != null) {
|
||||||
{
|
|
||||||
DiscordWhitelister.getPluginLogger().warning("Found whitelisted-role entry, moving over to whitelisted-roles. Please check your config to make sure the change is correct");
|
DiscordWhitelister.getPluginLogger().warning("Found whitelisted-role entry, moving over to whitelisted-roles. Please check your config to make sure the change is correct");
|
||||||
// Get the role from the old entry
|
// Get the role from the old entry
|
||||||
String whitelistedRoleTemp = whitelisterBotConfig.getString("whitelisted-role");
|
String whitelistedRoleTemp = fileConfiguration.getString("whitelisted-role");
|
||||||
// Assign role from old entry to new entry as a list
|
// Assign role from old entry to new entry as a list
|
||||||
whitelisterBotConfig.set("whitelisted-roles", Collections.singletonList(whitelistedRoleTemp));
|
fileConfiguration.set("whitelisted-roles", Collections.singletonList(whitelistedRoleTemp));
|
||||||
|
|
||||||
// Remove now un-used entry
|
// Remove now un-used entry
|
||||||
whitelisterBotConfig.set("whitelisted-role", null);
|
fileConfiguration.set("whitelisted-role", null);
|
||||||
|
|
||||||
// Note to users that id for roles now affects the new entry
|
// Note to users that id for roles now affects the new entry
|
||||||
if(whitelisterBotConfig.getBoolean("use-id-for-roles"))
|
if (fileConfiguration.getBoolean("use-id-for-roles")) {
|
||||||
{
|
|
||||||
DiscordWhitelister.getPluginLogger().severe("You have 'use-id-for-roles' enabled please change the whitelisted-roles to ids as they now follow this setting");
|
DiscordWhitelister.getPluginLogger().severe("You have 'use-id-for-roles' enabled please change the whitelisted-roles to ids as they now follow this setting");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SaveConfig()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
whitelisterBotConfig.save(whitelisterBotConfigFile.getPath());
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void CheckEntry(String entryName, Object passedValue)
|
|
||||||
{
|
|
||||||
if(whitelisterBotConfig.get(entryName) == null)
|
|
||||||
{
|
|
||||||
whitelisterBotConfig.set(entryName, passedValue);
|
|
||||||
|
|
||||||
if(!configCreated)
|
|
||||||
DiscordWhitelister.getPluginLogger().warning("Entry '" + entryName + "' was not found, adding it to the config...");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
package uk.co.angrybee.joe.configs;
|
package uk.co.angrybee.joe.configs;
|
||||||
|
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import uk.co.angrybee.joe.DiscordWhitelister;
|
import uk.co.angrybee.joe.DiscordWhitelister;
|
||||||
|
|
||||||
|
@ -10,21 +7,15 @@ import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class OnWhitelistCommandsConfig
|
public class OnWhitelistCommandsConfig extends Config {
|
||||||
{
|
public OnWhitelistCommandsConfig() {
|
||||||
private static File onWhitelistCommandsConfigFile;
|
fileName = "on-whitelist-commands.yml";
|
||||||
private static FileConfiguration onWhitelistCommandsConfig;
|
file = new File(DiscordWhitelister.getPlugin().getDataFolder(), fileName);
|
||||||
|
fileConfiguration = new YamlConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
public static FileConfiguration getPermissionsConfig() { return onWhitelistCommandsConfig; }
|
public void ConfigSetup() {
|
||||||
|
if (!file.exists())
|
||||||
private static boolean onWhitelistCommandsFileCreated = false;
|
|
||||||
|
|
||||||
public static void ConfigSetup()
|
|
||||||
{
|
|
||||||
onWhitelistCommandsConfigFile = new File(DiscordWhitelister.getPlugin().getDataFolder(), "on-whitelist-commands.yml");
|
|
||||||
onWhitelistCommandsConfig = new YamlConfiguration();
|
|
||||||
|
|
||||||
if(!onWhitelistCommandsConfigFile.exists())
|
|
||||||
CreateConfig();
|
CreateConfig();
|
||||||
|
|
||||||
LoadConfigFile();
|
LoadConfigFile();
|
||||||
|
@ -32,53 +23,20 @@ public class OnWhitelistCommandsConfig
|
||||||
SaveConfig();
|
SaveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void CreateConfig()
|
private void CheckEntries() {
|
||||||
{
|
if (file.exists()) {
|
||||||
try
|
|
||||||
{
|
|
||||||
onWhitelistCommandsConfigFile.createNewFile();
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
DiscordWhitelister.getPluginLogger().info("on whitelist commands file created at: " + onWhitelistCommandsConfigFile.getPath());
|
|
||||||
onWhitelistCommandsFileCreated = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void LoadConfigFile()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
onWhitelistCommandsConfig.load(onWhitelistCommandsConfigFile);
|
|
||||||
}
|
|
||||||
catch (IOException | InvalidConfigurationException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void CheckEntries()
|
|
||||||
{
|
|
||||||
if(onWhitelistCommandsConfigFile.exists())
|
|
||||||
{
|
|
||||||
// Write comments
|
// Write comments
|
||||||
if(onWhitelistCommandsFileCreated)
|
if (fileCreated) {
|
||||||
{
|
|
||||||
SaveConfig(); // save and load again
|
SaveConfig(); // save and load again
|
||||||
try
|
try {
|
||||||
{
|
FileWriter fileWriter = new FileWriter(file);
|
||||||
FileWriter fileWriter = new FileWriter(onWhitelistCommandsConfigFile);
|
|
||||||
fileWriter.write("# The list of commands that will be dispatched when a player gets whitelisted. (Use the following syntax: \n"
|
fileWriter.write("# The list of commands that will be dispatched when a player gets whitelisted. (Use the following syntax: \n"
|
||||||
+ "# \"%TYPE%:%COMMAND%\", being %TYPE% whether 'CONSOLE' or 'PLAYER' and the command without the slash (/)\n"
|
+ "# \"%TYPE%:%COMMAND%\", being %TYPE% whether 'CONSOLE' or 'PLAYER' and the command without the slash (/)\n"
|
||||||
+ "# placeholder %PLAYER% is supported here).\n"
|
+ "# placeholder %PLAYER% is supported here).\n"
|
||||||
+ "# NOTE: The 'PLAYER' type will only work if the target whitelisted player is in the server at the time of command dispatch.");
|
+ "# NOTE: The 'PLAYER' type will only work if the target whitelisted player is in the server at the time of command dispatch.");
|
||||||
|
|
||||||
fileWriter.close();
|
fileWriter.close();
|
||||||
}
|
} catch (IOException e) {
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
LoadConfigFile();
|
LoadConfigFile();
|
||||||
|
@ -87,27 +45,4 @@ public class OnWhitelistCommandsConfig
|
||||||
CheckEntry("on-whitelist-commands", Arrays.asList("CONSOLE:gamemode adventure %PLAYER%", "CONSOLE:say hello testing"));
|
CheckEntry("on-whitelist-commands", Arrays.asList("CONSOLE:gamemode adventure %PLAYER%", "CONSOLE:say hello testing"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SaveConfig()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
onWhitelistCommandsConfig.save(onWhitelistCommandsConfigFile.getPath());
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void CheckEntry(String entryName, Object passedValue)
|
|
||||||
{
|
|
||||||
if(onWhitelistCommandsConfig.get(entryName) == null)
|
|
||||||
{
|
|
||||||
onWhitelistCommandsConfig.set(entryName, passedValue);
|
|
||||||
|
|
||||||
if(!onWhitelistCommandsFileCreated)
|
|
||||||
DiscordWhitelister.getPluginLogger().warning("Entry '" + entryName + "' was not found, adding it to on-whitelist-permissions.yml...");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,29 +1,19 @@
|
||||||
package uk.co.angrybee.joe.configs;
|
package uk.co.angrybee.joe.configs;
|
||||||
|
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import uk.co.angrybee.joe.DiscordWhitelister;
|
import uk.co.angrybee.joe.DiscordWhitelister;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
public class PermissionsConfig
|
public class PermissionsConfig extends Config {
|
||||||
{
|
public PermissionsConfig() {
|
||||||
private static File permissionsConfigFile;
|
fileName = "on-whitelist-permissions.yml";
|
||||||
private static FileConfiguration permissionsConfig;
|
file = new File(DiscordWhitelister.getPlugin().getDataFolder(), fileName);
|
||||||
|
fileConfiguration = new YamlConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
public static FileConfiguration getPermissionsConfig() { return permissionsConfig; }
|
public void ConfigSetup() {
|
||||||
|
if (!file.exists())
|
||||||
private static boolean permissionsFileCreated = false;
|
|
||||||
|
|
||||||
public static void ConfigSetup()
|
|
||||||
{
|
|
||||||
permissionsConfigFile = new File(DiscordWhitelister.getPlugin().getDataFolder(), "on-whitelist-permissions.yml");
|
|
||||||
permissionsConfig = new YamlConfiguration();
|
|
||||||
|
|
||||||
if(!permissionsConfigFile.exists())
|
|
||||||
CreateConfig();
|
CreateConfig();
|
||||||
|
|
||||||
LoadConfigFile();
|
LoadConfigFile();
|
||||||
|
@ -31,62 +21,10 @@ public class PermissionsConfig
|
||||||
SaveConfig();
|
SaveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void CreateConfig()
|
private void CheckEntries() {
|
||||||
{
|
if (file.exists()) {
|
||||||
try
|
|
||||||
{
|
|
||||||
permissionsConfigFile.createNewFile();
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
DiscordWhitelister.getPluginLogger().info("on whitelist permissions file created at: " + permissionsConfigFile.getPath());
|
|
||||||
permissionsFileCreated = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void LoadConfigFile()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
permissionsConfig.load(permissionsConfigFile);
|
|
||||||
}
|
|
||||||
catch (IOException | InvalidConfigurationException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void CheckEntries()
|
|
||||||
{
|
|
||||||
if(permissionsConfigFile.exists())
|
|
||||||
{
|
|
||||||
// test permission
|
// test permission
|
||||||
CheckEntry("perms-on-whitelist", Collections.singletonList("bukkit.command.tps"));
|
CheckEntry("perms-on-whitelist", Collections.singletonList("bukkit.command.tps"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SaveConfig()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
permissionsConfig.save(permissionsConfigFile.getPath());
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void CheckEntry(String entryName, Object passedValue)
|
|
||||||
{
|
|
||||||
if(permissionsConfig.get(entryName) == null)
|
|
||||||
{
|
|
||||||
permissionsConfig.set(entryName, passedValue);
|
|
||||||
|
|
||||||
if(!permissionsFileCreated)
|
|
||||||
DiscordWhitelister.getPluginLogger().warning("Entry '" + entryName + "' was not found, adding it to on-whitelist-permissions.yml...");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,7 +120,7 @@ public class OnBanEvent implements Listener
|
||||||
// Remove the whitelisted role(s)
|
// Remove the whitelisted role(s)
|
||||||
DiscordClient.RemoveRolesFromUser(guild, discordId, Arrays.asList(DiscordClient.whitelistedRoleNames));
|
DiscordClient.RemoveRolesFromUser(guild, discordId, Arrays.asList(DiscordClient.whitelistedRoleNames));
|
||||||
// Add the banned role(s)
|
// Add the banned role(s)
|
||||||
DiscordClient.AssignRolesToUser(guild, discordId, (List<String>) MainConfig.getMainConfig().get("banned-roles"));
|
DiscordClient.AssignRolesToUser(guild, discordId, (List<String>) DiscordWhitelister.mainConfig.getFileConfiguration().get("banned-roles"));
|
||||||
}
|
}
|
||||||
idFound = true;
|
idFound = true;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class WhitelistedPlayers
|
||||||
public static void Setup()
|
public static void Setup()
|
||||||
{
|
{
|
||||||
// Check if we are using EasyWhitelist
|
// Check if we are using EasyWhitelist
|
||||||
if(MainConfig.getMainConfig().getBoolean("use-easy-whitelist"))
|
if(DiscordWhitelister.mainConfig.getFileConfiguration().getBoolean("use-easy-whitelist"))
|
||||||
GetEasyWhitelist();
|
GetEasyWhitelist();
|
||||||
|
|
||||||
if(usingEasyWhitelist)
|
if(usingEasyWhitelist)
|
||||||
|
|
Loading…
Reference in New Issue