Merge a1e8578b79
into 049507c32c
This commit is contained in:
commit
ecfca1c1b4
|
@ -89,6 +89,9 @@ public class CustomMessagesConfig
|
|||
CheckEntry("user-was-removed-title", "This user was previously removed by a staff member");
|
||||
CheckEntry("user-was-removed", "{Sender}, this user was previously removed by a staff member ({StaffMember}). Please ask a user with higher permissions to add this user.");
|
||||
|
||||
CheckEntry("user-was-removed-in-game-title", "This user was previously removed by a staff member");
|
||||
CheckEntry("user-was-removed-in-game", "{Sender}, this user was previously removed by a staff member in-game ({StaffMember}). Please ask a user with higher permissions to add this user.");
|
||||
|
||||
CheckEntry("whitelists-remaining-title", "Whitelists Remaining");
|
||||
CheckEntry("whitelists-remaining", "You have **{RemainingWhitelists} out of {MaxWhitelistAmount}** whitelists remaining.");
|
||||
|
||||
|
|
|
@ -107,6 +107,8 @@ public class MainConfig
|
|||
|
||||
CheckEntry("removed-list-enabled", true);
|
||||
|
||||
CheckEntry("add-in-game-adds-and-removes-to-list", true);
|
||||
|
||||
CheckEntry("use-custom-messages", false);
|
||||
|
||||
CheckEntry("use-custom-prefixes", false);
|
||||
|
@ -117,6 +119,9 @@ public class MainConfig
|
|||
|
||||
CheckEntry("show-vanished-players-in-player-count", false);
|
||||
|
||||
// Disable checking if username exists
|
||||
CheckEntry("offline-mode", false);
|
||||
|
||||
// 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)
|
||||
{
|
||||
|
|
|
@ -8,15 +8,12 @@ import net.dv8tion.jda.api.entities.*;
|
|||
import net.dv8tion.jda.api.events.guild.member.GuildMemberLeaveEvent;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.JSONValue;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
import uk.co.angrybee.joe.Configs.CustomPrefixConfig;
|
||||
import uk.co.angrybee.joe.Stores.InGameRemovedList;
|
||||
import uk.co.angrybee.joe.Stores.RemovedList;
|
||||
import uk.co.angrybee.joe.Stores.WhitelistedPlayers;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.security.auth.login.LoginException;
|
||||
|
@ -45,6 +42,7 @@ public class DiscordClient extends ListenerAdapter
|
|||
|
||||
private static boolean limitedWhitelistEnabled;
|
||||
private static boolean usernameValidation;
|
||||
private static boolean offlineMode;
|
||||
|
||||
private static boolean whitelistedRoleAutoAdd;
|
||||
private static boolean whitelistedRoleAutoRemove;
|
||||
|
@ -53,7 +51,7 @@ public class DiscordClient extends ListenerAdapter
|
|||
private final char[] validCharacters = {'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'a', 's', 'd', 'f', 'g', 'h',
|
||||
'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '_'};
|
||||
|
||||
private static JDA javaDiscordAPI;
|
||||
public static JDA javaDiscordAPI;
|
||||
|
||||
public static int InitializeClient(String clientToken)
|
||||
{
|
||||
|
@ -92,6 +90,7 @@ public class DiscordClient extends ListenerAdapter
|
|||
maxWhitelistAmount = DiscordWhitelister.getWhitelisterBotConfig().getInt("max-whitelist-amount");
|
||||
limitedWhitelistEnabled = DiscordWhitelister.getWhitelisterBotConfig().getBoolean("limited-whitelist-enabled");
|
||||
usernameValidation = DiscordWhitelister.getWhitelisterBotConfig().getBoolean("username-validation");
|
||||
offlineMode = DiscordWhitelister.getWhitelisterBotConfig().getBoolean("offline-mode");
|
||||
|
||||
// Set the name of the role to add/remove to/from the user after they have been added/removed to/from the whitelist and if this feature is enabled
|
||||
whitelistedRoleAutoAdd = DiscordWhitelister.getWhitelisterBotConfig().getBoolean("whitelisted-role-auto-add");
|
||||
|
@ -410,44 +409,22 @@ public class DiscordClient extends ListenerAdapter
|
|||
}
|
||||
}
|
||||
|
||||
// EasyWhitelist username store
|
||||
FileConfiguration tempFileConfiguration = new YamlConfiguration();
|
||||
// Default Minecraft username store
|
||||
File whitelistJSON = (new File(".", "whitelist.json"));
|
||||
|
||||
if (onlyHasLimitedAdd) {
|
||||
DiscordWhitelister.getPlugin().getLogger().info(author.getName() + "(" + author.getId() + ") attempted to whitelist: " + finalNameToAdd + ", " + (maxWhitelistAmount - timesWhitelisted) + " whitelists remaining");
|
||||
} else {
|
||||
DiscordWhitelister.getPlugin().getLogger().info(author.getName() + "(" + author.getId() + ") attempted to whitelist: " + finalNameToAdd);
|
||||
}
|
||||
|
||||
if (DiscordWhitelister.useEasyWhitelist)
|
||||
{
|
||||
try
|
||||
{
|
||||
tempFileConfiguration.load(new File(DiscordWhitelister.easyWhitelist.getDataFolder(), "config.yml"));
|
||||
}
|
||||
catch (IOException | InvalidConfigurationException e)
|
||||
{
|
||||
EmbedBuilder failure = new EmbedBuilder();
|
||||
failure.setColor(new Color(231, 76, 60));
|
||||
failure.addField("Internal Error", (author.getAsMention() + ", something went wrong while accessing EasyWhitelist file. Please contact a staff member."), false);
|
||||
channel.sendMessage(failure.build()).queue();
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
boolean alreadyOnWhitelist = false;
|
||||
|
||||
if(DiscordWhitelister.useEasyWhitelist)
|
||||
if(WhitelistedPlayers.usingEasyWhitelist)
|
||||
{
|
||||
if (tempFileConfiguration.getStringList("whitelisted").contains(finalNameToAdd))
|
||||
if (WhitelistedPlayers.CheckForPlayerEasyWhitelist(finalNameToAdd))
|
||||
{
|
||||
alreadyOnWhitelist = true;
|
||||
}
|
||||
}
|
||||
else if (checkWhitelistJSON(whitelistJSON, finalNameToAdd))
|
||||
else if (WhitelistedPlayers.CheckForPlayer(finalNameToAdd))
|
||||
{
|
||||
alreadyOnWhitelist = true;
|
||||
}
|
||||
|
@ -475,7 +452,7 @@ public class DiscordClient extends ListenerAdapter
|
|||
return;
|
||||
}
|
||||
|
||||
if (DiscordWhitelister.getRemovedList().get(finalNameToAdd) != null) // If the user has been removed before
|
||||
if (RemovedList.CheckStoreForPlayer(finalNameToAdd)) // If the user has been removed before
|
||||
{
|
||||
if (onlyHasLimitedAdd)
|
||||
{
|
||||
|
@ -484,7 +461,7 @@ public class DiscordClient extends ListenerAdapter
|
|||
|
||||
if(!DiscordWhitelister.useCustomMessages)
|
||||
{
|
||||
embedBuilderRemovedByStaff.addField("This user was previously removed by a staff member", (author.getAsMention() + ", this user was previously removed by a staff member (<@" + DiscordWhitelister.getRemovedList().get(finalNameToAdd) + ">)."
|
||||
embedBuilderRemovedByStaff.addField("This user was previously removed by a staff member", (author.getAsMention() + ", this user was previously removed by a staff member (<@" + RemovedList.getRemovedPlayers().get(finalNameToAdd) + ">)."
|
||||
+ System.lineSeparator() + "Please ask a user with higher permissions to add this user." + System.lineSeparator()), false);
|
||||
embedBuilderRemovedByStaff.addField("Whitelists Remaining", ("You have **" + (maxWhitelistAmount - timesWhitelisted)
|
||||
+ " out of " + DiscordWhitelister.getWhitelisterBotConfig().getString("max-whitelist-amount") + "** whitelists remaining."), false);
|
||||
|
@ -494,7 +471,7 @@ public class DiscordClient extends ListenerAdapter
|
|||
String customTitle = DiscordWhitelister.getCustomMessagesConfig().getString("user-was-removed-title");
|
||||
String customMessage = DiscordWhitelister.getCustomMessagesConfig().getString("user-was-removed");
|
||||
String customWhitelistsRemaining = DiscordWhitelister.getCustomMessagesConfig().getString("whitelists-remaining");
|
||||
String staffMemberMention = "<@" + DiscordWhitelister.getRemovedList().get(finalNameToAdd) + ">";
|
||||
String staffMemberMention = "<@" + RemovedList.getRemovedPlayers().get(finalNameToAdd) + ">";
|
||||
|
||||
customMessage = customMessage.replaceAll("\\{Sender}", author.getAsMention());
|
||||
customMessage = customMessage.replaceAll("\\{StaffMember}", staffMemberMention);
|
||||
|
@ -510,21 +487,60 @@ public class DiscordClient extends ListenerAdapter
|
|||
}
|
||||
else // Remove from removed list
|
||||
{
|
||||
DiscordWhitelister.getRemovedList().set(finalNameToAdd, null);
|
||||
|
||||
try
|
||||
{
|
||||
DiscordWhitelister.getRemovedList().save(DiscordWhitelister.getRemovedListFile().getPath());
|
||||
} catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
RemovedList.getRemovedPlayers().set(finalNameToAdd, null);
|
||||
RemovedList.SaveStore();
|
||||
|
||||
DiscordWhitelister.getPlugin().getLogger().info(finalNameToAdd + " has been removed from the removed list by " + author.getName()
|
||||
+ "(" + author.getId() + ")");
|
||||
}
|
||||
}
|
||||
|
||||
// In-game list check
|
||||
if(DiscordWhitelister.useInGameAddRemoves)
|
||||
{
|
||||
if(InGameRemovedList.CheckStoreForPlayer(finalNameToAdd))
|
||||
{
|
||||
if(onlyHasLimitedAdd)
|
||||
{
|
||||
EmbedBuilder embedBuilderRemovedByStaff = new EmbedBuilder();
|
||||
embedBuilderRemovedByStaff.setColor(new Color(231, 76, 60));
|
||||
|
||||
if(!DiscordWhitelister.useCustomMessages)
|
||||
{
|
||||
embedBuilderRemovedByStaff.addField("This user was previously removed by a staff member", (author.getAsMention() + ", this user was previously removed by a staff member in-game (" + InGameRemovedList.getRemovedPlayers().get(finalNameToAdd) + ")."
|
||||
+ System.lineSeparator() + "Please ask a user with higher permissions to add this user." + System.lineSeparator()), false);
|
||||
embedBuilderRemovedByStaff.addField("Whitelists Remaining", ("You have **" + (maxWhitelistAmount - timesWhitelisted)
|
||||
+ " out of " + DiscordWhitelister.getWhitelisterBotConfig().getString("max-whitelist-amount") + "** whitelists remaining."), false);
|
||||
}
|
||||
else
|
||||
{
|
||||
String customTitle = DiscordWhitelister.getCustomMessagesConfig().getString("user-was-removed-in-game-title");
|
||||
String customMessage = DiscordWhitelister.getCustomMessagesConfig().getString("user-was-removed-in-game");
|
||||
String customWhitelistsRemaining = DiscordWhitelister.getCustomMessagesConfig().getString("whitelists-remaining");
|
||||
String inGameStaffMember = InGameRemovedList.getRemovedPlayers().getString(finalNameToAdd);
|
||||
|
||||
customMessage = customMessage.replaceAll("\\{Sender}", author.getAsMention());
|
||||
customMessage = customMessage.replaceAll("\\{StaffMember}", inGameStaffMember);
|
||||
|
||||
customWhitelistsRemaining = customWhitelistsRemaining.replaceAll("\\{RemainingWhitelists}", String.valueOf((maxWhitelistAmount - timesWhitelisted)));
|
||||
customWhitelistsRemaining = customWhitelistsRemaining.replaceAll("\\{MaxWhitelistAmount}", String.valueOf(maxWhitelistAmount));
|
||||
|
||||
embedBuilderRemovedByStaff.addField(customTitle, customMessage + " " + customWhitelistsRemaining, false);
|
||||
}
|
||||
|
||||
channel.sendMessage(embedBuilderRemovedByStaff.build()).queue();
|
||||
return;
|
||||
}
|
||||
else // Remove from in-game removed list
|
||||
{
|
||||
InGameRemovedList.RemoveUserFromStore(finalNameToAdd);
|
||||
|
||||
DiscordWhitelister.getPlugin().getLogger().info(finalNameToAdd + " has been removed from in-game-removed-list.yml by " + author.getName()
|
||||
+ "(" + author.getId() + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Do as much as possible off the main server thread.
|
||||
convert username into UUID to avoid depreciation and rate limits (according to https://minotar.net/) */
|
||||
String playerUUID = minecraftUsernameToUUID(finalNameToAdd);
|
||||
|
@ -534,7 +550,7 @@ public class DiscordClient extends ListenerAdapter
|
|||
this will run even if the message is never sent, but is a good trade off */
|
||||
EmbedBuilder embedBuilderWhitelistSuccess = new EmbedBuilder();
|
||||
embedBuilderWhitelistSuccess.setColor(new Color(46, 204, 113));
|
||||
if(DiscordWhitelister.showPlayerSkin)
|
||||
if(DiscordWhitelister.showPlayerSkin && !offlineMode)
|
||||
{
|
||||
embedBuilderWhitelistSuccess.setThumbnail("https://minotar.net/armor/bust/" + playerUUID + "/100.png");
|
||||
}
|
||||
|
@ -619,30 +635,25 @@ public class DiscordClient extends ListenerAdapter
|
|||
final int successfulTimesWhitelisted = maxWhitelistAmount - finalTimesWhitelisted;
|
||||
final int failedTimesWhitelisted = maxWhitelistAmount - timesWhitelisted;
|
||||
|
||||
if (!DiscordWhitelister.useEasyWhitelist) {
|
||||
if (authorPermissions.isUserCanUseCommand()) {
|
||||
if (!WhitelistedPlayers.usingEasyWhitelist)
|
||||
{
|
||||
if (authorPermissions.isUserCanUseCommand())
|
||||
executeServerCommand("whitelist add " + finalNameToAdd);
|
||||
}
|
||||
}
|
||||
|
||||
if (DiscordWhitelister.useEasyWhitelist) {
|
||||
if (!invalidMinecraftName) // have to do this else the easy whitelist plugin will add the name regardless of whether it is valid on not
|
||||
if (WhitelistedPlayers.usingEasyWhitelist)
|
||||
{
|
||||
if (!invalidMinecraftName || offlineMode) // have to do this else the easy whitelist plugin will add the name regardless of whether it is valid on not
|
||||
{
|
||||
if (authorPermissions.isUserCanUseCommand()) {
|
||||
if (authorPermissions.isUserCanUseCommand())
|
||||
executeServerCommand("easywl add " + finalNameToAdd);
|
||||
}
|
||||
}
|
||||
|
||||
// run through the server so that the check doesn't execute before the server has had a chance to run the whitelist command -- unsure if this is the best way of doing this, but it works
|
||||
DiscordWhitelister.getPlugin().getServer().getScheduler().callSyncMethod(DiscordWhitelister.getPlugin(), () ->
|
||||
{
|
||||
try {
|
||||
tempFileConfiguration.load(new File(DiscordWhitelister.easyWhitelist.getDataFolder(), "config.yml"));
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (!invalidMinecraftName && tempFileConfiguration.getStringList("whitelisted").contains(finalNameToAdd)) {
|
||||
if ((!invalidMinecraftName || offlineMode) && WhitelistedPlayers.CheckForPlayerEasyWhitelist(finalNameToAdd))
|
||||
{
|
||||
channel.sendMessage(embedBuilderWhitelistSuccess.build()).queue();
|
||||
|
||||
// Add role to user when they have been added to the whitelist if need be
|
||||
|
@ -697,10 +708,13 @@ public class DiscordClient extends ListenerAdapter
|
|||
}
|
||||
return null;
|
||||
});
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
DiscordWhitelister.getPlugin().getServer().getScheduler().callSyncMethod(DiscordWhitelister.getPlugin(), () ->
|
||||
{
|
||||
if (checkWhitelistJSON(whitelistJSON, finalNameToAdd)) {
|
||||
if (WhitelistedPlayers.CheckForPlayer(finalNameToAdd))
|
||||
{
|
||||
channel.sendMessage(embedBuilderWhitelistSuccess.build()).queue();
|
||||
|
||||
// Add role to user when they have been added to the whitelist if need be
|
||||
|
@ -780,30 +794,20 @@ public class DiscordClient extends ListenerAdapter
|
|||
|
||||
final String finalNameToRemove = messageContentsAfterCommand.replaceAll(" .*", ""); // The name is everything up to the first space
|
||||
|
||||
if (finalNameToRemove.isEmpty()) {
|
||||
if (finalNameToRemove.isEmpty())
|
||||
{
|
||||
channel.sendMessage(removeCommandInfo).queue();
|
||||
return;
|
||||
} else {
|
||||
// easy whitelist
|
||||
FileConfiguration tempFileConfiguration = new YamlConfiguration();
|
||||
// default whitelist
|
||||
File whitelistJSON = (new File(".", "whitelist.json"));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
DiscordWhitelister.getPlugin().getLogger().info(author.getName() + "(" + author.getId() + ") attempted to remove " + finalNameToRemove + " from the whitelist");
|
||||
|
||||
if (DiscordWhitelister.useEasyWhitelist) {
|
||||
try {
|
||||
tempFileConfiguration.load(new File(DiscordWhitelister.easyWhitelist.getDataFolder(), "config.yml"));
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
boolean notOnWhitelist = false;
|
||||
|
||||
if (DiscordWhitelister.useEasyWhitelist)
|
||||
if (WhitelistedPlayers.usingEasyWhitelist)
|
||||
{
|
||||
if (!tempFileConfiguration.getStringList("whitelisted").contains(finalNameToRemove))
|
||||
if (!WhitelistedPlayers.CheckForPlayerEasyWhitelist(finalNameToRemove))
|
||||
{
|
||||
notOnWhitelist = true;
|
||||
|
||||
|
@ -828,7 +832,7 @@ public class DiscordClient extends ListenerAdapter
|
|||
}
|
||||
}
|
||||
|
||||
if (!DiscordWhitelister.useEasyWhitelist && !checkWhitelistJSON(whitelistJSON, finalNameToRemove))
|
||||
if (!WhitelistedPlayers.usingEasyWhitelist && !WhitelistedPlayers.CheckForPlayer(finalNameToRemove))
|
||||
{
|
||||
notOnWhitelist = true;
|
||||
|
||||
|
@ -854,23 +858,10 @@ public class DiscordClient extends ListenerAdapter
|
|||
|
||||
if (!notOnWhitelist)
|
||||
{
|
||||
if (DiscordWhitelister.useEasyWhitelist)
|
||||
{
|
||||
try
|
||||
{
|
||||
tempFileConfiguration.load(new File(DiscordWhitelister.easyWhitelist.getDataFolder(), "config.yml"));
|
||||
}
|
||||
catch (IOException | InvalidConfigurationException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (WhitelistedPlayers.usingEasyWhitelist)
|
||||
executeServerCommand("easywl remove " + finalNameToRemove);
|
||||
}
|
||||
else
|
||||
{
|
||||
executeServerCommand("whitelist remove " + finalNameToRemove);
|
||||
}
|
||||
|
||||
// Configure message here instead of on the main thread - this means this will run even if the message is never sent, but is a good trade off (I think)
|
||||
EmbedBuilder embedBuilderSuccess = new EmbedBuilder();
|
||||
|
@ -900,16 +891,12 @@ public class DiscordClient extends ListenerAdapter
|
|||
"This should never happen, you may have to remove the player manually and report the issue."), false);
|
||||
|
||||
|
||||
if (DiscordWhitelister.useEasyWhitelist) {
|
||||
if (WhitelistedPlayers.usingEasyWhitelist)
|
||||
{
|
||||
DiscordWhitelister.getPlugin().getServer().getScheduler().callSyncMethod(DiscordWhitelister.getPlugin(), () ->
|
||||
{
|
||||
try {
|
||||
tempFileConfiguration.load(new File(DiscordWhitelister.easyWhitelist.getDataFolder(), "config.yml"));
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (!tempFileConfiguration.getStringList("whitelisted").contains(finalNameToRemove)) {
|
||||
if (!WhitelistedPlayers.CheckForPlayerEasyWhitelist(finalNameToRemove))
|
||||
{
|
||||
channel.sendMessage(embedBuilderSuccess.build()).queue();
|
||||
|
||||
// Remove role from user when they have been removed from the whitelist if need be
|
||||
|
@ -954,10 +941,10 @@ public class DiscordClient extends ListenerAdapter
|
|||
}
|
||||
|
||||
// if the name is not on the list
|
||||
if (DiscordWhitelister.getRemovedList().get(finalNameToRemove) == null)
|
||||
if (RemovedList.getRemovedPlayers().get(finalNameToRemove) == null)
|
||||
{
|
||||
DiscordWhitelister.getRemovedList().set(finalNameToRemove, author.getId());
|
||||
DiscordWhitelister.getRemovedList().save(DiscordWhitelister.getRemovedListFile().getPath());
|
||||
RemovedList.getRemovedPlayers().set(finalNameToRemove, author.getId());
|
||||
RemovedList.SaveStore();
|
||||
}
|
||||
} else {
|
||||
channel.sendMessage(embedBuilderFailure.build()).queue();
|
||||
|
@ -967,7 +954,7 @@ public class DiscordClient extends ListenerAdapter
|
|||
} else {
|
||||
DiscordWhitelister.getPlugin().getServer().getScheduler().callSyncMethod(DiscordWhitelister.getPlugin(), () ->
|
||||
{
|
||||
if (!checkWhitelistJSON(whitelistJSON, finalNameToRemove)) {
|
||||
if (!WhitelistedPlayers.CheckForPlayer(finalNameToRemove)) {
|
||||
channel.sendMessage(embedBuilderSuccess.build()).queue();
|
||||
|
||||
// Remove role from user when they have been removed from the whitelist if need be
|
||||
|
@ -1010,9 +997,10 @@ public class DiscordClient extends ListenerAdapter
|
|||
}
|
||||
|
||||
// if the name is not on the list
|
||||
if (DiscordWhitelister.getRemovedList().get(finalNameToRemove) == null) {
|
||||
DiscordWhitelister.getRemovedList().set(finalNameToRemove, author.getId());
|
||||
DiscordWhitelister.getRemovedList().save(DiscordWhitelister.getRemovedListFile().getPath());
|
||||
if (RemovedList.CheckStoreForPlayer(finalNameToRemove))
|
||||
{
|
||||
RemovedList.getRemovedPlayers().set(finalNameToRemove, author.getId());
|
||||
RemovedList.SaveStore();
|
||||
}
|
||||
} else {
|
||||
channel.sendMessage(embedBuilderFailure.build()).queue();
|
||||
|
@ -1082,11 +1070,12 @@ public class DiscordClient extends ListenerAdapter
|
|||
DiscordWhitelister.getPlugin().getLogger().info(discordUserToRemove + " left. Removing their whitelisted entries...");
|
||||
List<?> ls = DiscordWhitelister.getRegisteredUsers(discordUserToRemove);
|
||||
|
||||
if(ls != null) {
|
||||
|
||||
if(ls != null)
|
||||
{
|
||||
for (Object minecraftNameToRemove : ls) {
|
||||
DiscordWhitelister.getPlugin().getLogger().info(minecraftNameToRemove.toString() + " left. Removing their whitelisted entries.");
|
||||
if (DiscordWhitelister.useEasyWhitelist) {
|
||||
if (WhitelistedPlayers.usingEasyWhitelist)
|
||||
{
|
||||
executeServerCommand("easywl remove " + minecraftNameToRemove.toString());
|
||||
} else {
|
||||
executeServerCommand("whitelist remove " + minecraftNameToRemove.toString());
|
||||
|
@ -1099,37 +1088,13 @@ public class DiscordClient extends ListenerAdapter
|
|||
return;
|
||||
}
|
||||
DiscordWhitelister.getPlugin().getLogger().info(discordUserToRemove + " left. Successfully removed their whitelisted entries.");
|
||||
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
DiscordWhitelister.getPlugin().getLogger().warning(discordUserToRemove + " left. Could not removed their whitelisted entries as they did not whitelist through this plugin.");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkWhitelistJSON(File whitelistFile, String minecraftUsername) {
|
||||
boolean correctUsername = false;
|
||||
|
||||
try {
|
||||
JSONParser jsonParser = new JSONParser();
|
||||
JSONArray jsonArray = (JSONArray) jsonParser.parse(new FileReader(whitelistFile));
|
||||
|
||||
for (Object object : jsonArray) {
|
||||
JSONObject player = (JSONObject) object;
|
||||
|
||||
String userName = (String) player.get("name");
|
||||
userName = userName.toLowerCase();
|
||||
|
||||
if (userName.equals(minecraftUsername)) {
|
||||
correctUsername = true;
|
||||
}
|
||||
}
|
||||
} catch (IOException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return correctUsername;
|
||||
}
|
||||
|
||||
private String minecraftUsernameToUUID(String minecraftUsername)
|
||||
{
|
||||
URL playerURL;
|
||||
|
|
|
@ -4,7 +4,6 @@ import org.bukkit.Server;
|
|||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import uk.co.angrybee.joe.Commands.CommandAbout;
|
||||
import uk.co.angrybee.joe.Commands.CommandReload;
|
||||
|
@ -13,6 +12,10 @@ import uk.co.angrybee.joe.Configs.CustomMessagesConfig;
|
|||
import uk.co.angrybee.joe.Configs.CustomPrefixConfig;
|
||||
import uk.co.angrybee.joe.Configs.MainConfig;
|
||||
import uk.co.angrybee.joe.Events.JoinLeaveEvents;
|
||||
import uk.co.angrybee.joe.Events.OnWhitelistEvents;
|
||||
import uk.co.angrybee.joe.Stores.InGameRemovedList;
|
||||
import uk.co.angrybee.joe.Stores.RemovedList;
|
||||
import uk.co.angrybee.joe.Stores.WhitelistedPlayers;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -22,27 +25,20 @@ import java.util.logging.Logger;
|
|||
public class DiscordWhitelister extends JavaPlugin
|
||||
{
|
||||
private static File userListFile;
|
||||
private static File removedListFile;
|
||||
|
||||
private static FileConfiguration userList;
|
||||
private static FileConfiguration removedList;
|
||||
|
||||
// easy whitelist
|
||||
public static Plugin easyWhitelist;
|
||||
|
||||
public static String botToken;
|
||||
|
||||
private static boolean configCreated = false;
|
||||
private static boolean userListCreated = false;
|
||||
private static boolean removedListCreated = false;
|
||||
|
||||
public static boolean useEasyWhitelist = false;
|
||||
public static boolean useCustomMessages = false;
|
||||
public static boolean useIdForRoles = false;
|
||||
public static boolean useCustomPrefixes = false;
|
||||
public static boolean showPlayerSkin = true;
|
||||
public static boolean addInGameRemovesToList = true;
|
||||
public static boolean showVanishedPlayersInCount = false;
|
||||
public static boolean useInGameAddRemoves = true;
|
||||
|
||||
public static boolean botEnabled;
|
||||
|
||||
|
@ -76,6 +72,12 @@ public class DiscordWhitelister extends JavaPlugin
|
|||
this.getCommand("discordwhitelisterreload").setExecutor(new CommandReload());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
DiscordClient.javaDiscordAPI.shutdownNow();
|
||||
}
|
||||
|
||||
public static JavaPlugin getPlugin()
|
||||
{
|
||||
return thisPlugin;
|
||||
|
@ -93,13 +95,6 @@ public class DiscordWhitelister extends JavaPlugin
|
|||
return userListFile;
|
||||
}
|
||||
|
||||
public static FileConfiguration getRemovedList() { return removedList; }
|
||||
|
||||
public static File getRemovedListFile()
|
||||
{
|
||||
return removedListFile;
|
||||
}
|
||||
|
||||
public static FileConfiguration getCustomMessagesConfig() { return CustomMessagesConfig.getCustomMessagesConfig(); }
|
||||
|
||||
public static Logger getPluginLogger() { return pluginLogger; }
|
||||
|
@ -143,7 +138,6 @@ public class DiscordWhitelister extends JavaPlugin
|
|||
public static int InitBot(boolean firstInit)
|
||||
{
|
||||
userList = new YamlConfiguration();
|
||||
removedList = new YamlConfiguration();
|
||||
|
||||
if(firstInit)
|
||||
vanishedPlayersCount = 0;
|
||||
|
@ -155,6 +149,7 @@ public class DiscordWhitelister extends JavaPlugin
|
|||
showPlayerSkin = getWhitelisterBotConfig().getBoolean("show-player-skin-on-whitelist");
|
||||
configCreated = MainConfig.configCreated;
|
||||
showVanishedPlayersInCount = MainConfig.getMainConfig().getBoolean("show-vanished-players-in-player-count");
|
||||
useInGameAddRemoves = MainConfig.getMainConfig().getBoolean("add-in-game-adds-and-removes-to-list");
|
||||
|
||||
|
||||
DiscordClient.whitelistAddPrefix = CustomPrefixConfig.getCustomPrefixesConfig().getString("whitelist-add-prefix");
|
||||
|
@ -195,23 +190,6 @@ public class DiscordWhitelister extends JavaPlugin
|
|||
DiscordClient.allowedToAddLimitedRoles[roles] = getWhitelisterBotConfig().getList("limited-add-roles").get(roles).toString();
|
||||
}
|
||||
|
||||
// easy whitelist check
|
||||
if(getWhitelisterBotConfig().getBoolean("use-easy-whitelist"))
|
||||
{
|
||||
pluginLogger.info("Checking for Easy Whitelist...");
|
||||
if(thisServer.getPluginManager().getPlugin("EasyWhitelist") != null)
|
||||
{
|
||||
pluginLogger.info("Easy Whitelist found! Will use over default whitelist command.");
|
||||
easyWhitelist = thisServer.getPluginManager().getPlugin("EasyWhitelist");
|
||||
useEasyWhitelist = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
pluginLogger.warning("Easy Whitelist was not found but is enabled in the config. " +
|
||||
"Falling back to default whitelist command.");
|
||||
}
|
||||
}
|
||||
|
||||
// Custom messages check
|
||||
useCustomMessages = getWhitelisterBotConfig().getBoolean("use-custom-messages");
|
||||
useCustomPrefixes = getWhitelisterBotConfig().getBoolean("use-custom-prefixes");
|
||||
|
@ -221,6 +199,7 @@ public class DiscordWhitelister extends JavaPlugin
|
|||
if(initSuccess == 1)
|
||||
return 1;
|
||||
|
||||
|
||||
// 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
|
||||
if(getWhitelisterBotConfig().getBoolean("show-player-count"))
|
||||
|
@ -232,6 +211,10 @@ public class DiscordWhitelister extends JavaPlugin
|
|||
DiscordClient.SetPlayerCountStatus(getOnlineUsers());
|
||||
}
|
||||
|
||||
// Register whitelist events
|
||||
if(useInGameAddRemoves)
|
||||
thisServer.getPluginManager().registerEvents(new OnWhitelistEvents(), thisPlugin);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -248,8 +231,13 @@ public class DiscordWhitelister extends JavaPlugin
|
|||
CustomPrefixConfig.ConfigSetup();
|
||||
CustomMessagesConfig.ConfigSetup();
|
||||
|
||||
// Init Stores
|
||||
InGameRemovedList.StoreSetup();
|
||||
RemovedList.StoreSetup();
|
||||
|
||||
WhitelistedPlayers.Setup();
|
||||
|
||||
userListFile = new File(dataFolder, "user-list.yml");
|
||||
removedListFile = new File(dataFolder, "removed-list.yml");
|
||||
|
||||
if(!userListFile.exists())
|
||||
{
|
||||
|
@ -275,30 +263,6 @@ public class DiscordWhitelister extends JavaPlugin
|
|||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if(!removedListFile.exists())
|
||||
{
|
||||
try
|
||||
{
|
||||
removedListFile.createNewFile();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
pluginLogger.info("Removed list created at: " + removedListFile.getPath());
|
||||
removedListCreated = true;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
getRemovedList().load(removedListFile);
|
||||
}
|
||||
catch (IOException | InvalidConfigurationException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if(userListCreated)
|
||||
{
|
||||
try
|
||||
|
@ -310,18 +274,5 @@ public class DiscordWhitelister extends JavaPlugin
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if(removedListCreated)
|
||||
{
|
||||
//getRemovedList().set("minecraftUsername", "discordRemoverID");
|
||||
try
|
||||
{
|
||||
getRemovedList().save(removedListFile.getPath());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,26 +3,38 @@ package uk.co.angrybee.joe.Events;
|
|||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import uk.co.angrybee.joe.DiscordWhitelister;
|
||||
import uk.co.angrybee.joe.Stores.InGameRemovedList;
|
||||
import uk.co.angrybee.joe.Stores.RemovedList;
|
||||
import uk.co.angrybee.joe.Stores.WhitelistedPlayers;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
// Checks for whitelist removes in-game, so player's cannot use the bot to add them back without an admin/staff member with higher permissions
|
||||
public class OnWhitelistEvents implements Listener
|
||||
{
|
||||
private enum CommandContext { VANILLA_ADD, EASYWL_ADD, VANILLA_REMOVE, EASYWL_REMOVE }
|
||||
|
||||
// TODO: incorporate this into the checkWhitelistJSON function
|
||||
private static final File whitelistFile = (new File(".", "whitelist.json"));
|
||||
|
||||
@EventHandler
|
||||
public void PlayerCommandPreprocessEvent(Player commandCaller, String message)
|
||||
public void onCommandPreprocess(PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
// Initial check
|
||||
CommandContext commandContext;
|
||||
Player commandCaller = event.getPlayer();
|
||||
String message = event.getMessage();
|
||||
|
||||
if(message.startsWith("!whitelist add"))
|
||||
if(message.startsWith("/whitelist add"))
|
||||
commandContext = CommandContext.VANILLA_ADD;
|
||||
else if(message.startsWith("!easywl add"))
|
||||
else if(message.startsWith("/easywl add"))
|
||||
commandContext = CommandContext.EASYWL_ADD;
|
||||
else if(message.startsWith("!whitelist remove"))
|
||||
else if(message.startsWith("/whitelist remove"))
|
||||
commandContext = CommandContext.VANILLA_REMOVE;
|
||||
else if(message.startsWith("!easywl remove"))
|
||||
else if(message.startsWith("/easywl remove"))
|
||||
commandContext = CommandContext.EASYWL_REMOVE;
|
||||
else
|
||||
return;
|
||||
|
@ -39,27 +51,58 @@ public class OnWhitelistEvents implements Listener
|
|||
|
||||
// Determine what command to check
|
||||
|
||||
String targetName = "";
|
||||
|
||||
// Check for adds to remove player's off the removed list (if they are on it)
|
||||
if(commandContext.equals(CommandContext.VANILLA_ADD) && !DiscordWhitelister.useEasyWhitelist)
|
||||
if(commandContext.equals(CommandContext.VANILLA_ADD) && !WhitelistedPlayers.usingEasyWhitelist)
|
||||
{
|
||||
// TODO
|
||||
// Check removed-list.yml, remove username from there if it exists
|
||||
// Check in-game removed list when created and remove from there if it exists
|
||||
// Log removal of name from list if it existed
|
||||
targetName = message.substring("/whitelist add".length() + 1).toLowerCase();
|
||||
ClearPlayerFromRemovedLists(targetName, commandCaller);
|
||||
}
|
||||
else if(commandContext.equals(CommandContext.EASYWL_ADD) && DiscordWhitelister.useEasyWhitelist)
|
||||
else if(commandContext.equals(CommandContext.EASYWL_ADD) && WhitelistedPlayers.usingEasyWhitelist)
|
||||
{
|
||||
targetName = message.substring("/easywl add".length() + 1).toLowerCase();
|
||||
ClearPlayerFromRemovedLists(targetName, commandCaller);
|
||||
}
|
||||
else if(commandContext.equals(CommandContext.VANILLA_REMOVE) && !WhitelistedPlayers.usingEasyWhitelist)
|
||||
{
|
||||
targetName = message.substring("/whitelist remove".length() + 1).toLowerCase();
|
||||
|
||||
if(WhitelistedPlayers.CheckForPlayer(targetName))
|
||||
{
|
||||
InGameRemovedList.AddUserToStore(targetName, commandCaller.getName());
|
||||
DiscordWhitelister.getPluginLogger().info(commandCaller.getName() + " has added " + targetName + " to the in-game removed list");
|
||||
}
|
||||
}
|
||||
else if(commandContext.equals(CommandContext.VANILLA_REMOVE) && !DiscordWhitelister.useEasyWhitelist)
|
||||
{
|
||||
// TODO
|
||||
// Check if the player is in the whitelist as this runs before the command is executed
|
||||
// Add player to in-game removed list and the players' name that removed it
|
||||
}
|
||||
else if(commandContext.equals(CommandContext.EASYWL_REMOVE) && DiscordWhitelister.useEasyWhitelist)
|
||||
else if(commandContext.equals(CommandContext.EASYWL_REMOVE) && WhitelistedPlayers.usingEasyWhitelist)
|
||||
{
|
||||
targetName = message.substring("/easywl remove".length() + 1).toLowerCase();
|
||||
|
||||
if(WhitelistedPlayers.CheckForPlayerEasyWhitelist(targetName))
|
||||
{
|
||||
InGameRemovedList.AddUserToStore(targetName, commandCaller.getName());
|
||||
DiscordWhitelister.getPluginLogger().info(commandCaller.getName() + " has added " + targetName + " to the in-game removed list");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void ClearPlayerFromRemovedLists(String playerName, Player commandCaller)
|
||||
{
|
||||
if(RemovedList.CheckStoreForPlayer(playerName))
|
||||
{
|
||||
DiscordWhitelister.getPluginLogger().info(commandCaller.getName() + " is attempting to add " + playerName + ". Removing " + playerName +
|
||||
" from removed-list.yml");
|
||||
RemovedList.getRemovedPlayers().set(playerName, null);
|
||||
|
||||
// Save changes
|
||||
RemovedList.SaveStore();
|
||||
}
|
||||
|
||||
if(InGameRemovedList.CheckStoreForPlayer(playerName))
|
||||
{
|
||||
InGameRemovedList.RemoveUserFromStore(playerName);
|
||||
DiscordWhitelister.getPluginLogger().info(commandCaller.getName() + " is attempting to add " + playerName + ". Removing " + playerName +
|
||||
" from in-game-removed-list.yml");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
package uk.co.angrybee.joe.Stores;
|
||||
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import uk.co.angrybee.joe.DiscordWhitelister;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
// Stores removed players that were removed in-game
|
||||
// in-game-removed-list.yml
|
||||
public class InGameRemovedList
|
||||
{
|
||||
private static File removePlayersFile;
|
||||
private static FileConfiguration removedPlayersConfig;
|
||||
|
||||
public static FileConfiguration getRemovedPlayers() { return removedPlayersConfig; }
|
||||
|
||||
private static boolean storeCreated = false;
|
||||
|
||||
public static void StoreSetup()
|
||||
{
|
||||
removePlayersFile = new File(DiscordWhitelister.getPlugin().getDataFolder(), "in-game-removed-list.yml");
|
||||
removedPlayersConfig = new YamlConfiguration();
|
||||
|
||||
if(!removePlayersFile.exists())
|
||||
CreateStore();
|
||||
|
||||
LoadStore();
|
||||
SaveStore();
|
||||
}
|
||||
|
||||
private static void CreateStore()
|
||||
{
|
||||
try
|
||||
{
|
||||
removePlayersFile.createNewFile();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void LoadStore()
|
||||
{
|
||||
try
|
||||
{
|
||||
removedPlayersConfig.load(removePlayersFile);
|
||||
}
|
||||
catch (IOException | InvalidConfigurationException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void SaveStore()
|
||||
{
|
||||
try
|
||||
{
|
||||
removedPlayersConfig.save(removePlayersFile.getPath());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddUserToStore(String nameToAdd, String commandIssuer)
|
||||
{
|
||||
if(removedPlayersConfig.get(nameToAdd) != null)
|
||||
{
|
||||
// Already in store, notify in console and update commandIssuer
|
||||
String oldCommandIssuer = removedPlayersConfig.getString(nameToAdd);
|
||||
DiscordWhitelister.getPluginLogger().warning(nameToAdd + " is already in the in-game removed list. Updating commandIssuer from " +
|
||||
oldCommandIssuer + " to " + commandIssuer);
|
||||
}
|
||||
|
||||
removedPlayersConfig.set(nameToAdd, commandIssuer);
|
||||
SaveStore();
|
||||
}
|
||||
|
||||
public static void RemoveUserFromStore(String nameToRemove)
|
||||
{
|
||||
if(removedPlayersConfig.get(nameToRemove) != null)
|
||||
{
|
||||
removedPlayersConfig.set(nameToRemove, null);
|
||||
SaveStore();
|
||||
}
|
||||
else // Shouldn't ever happen
|
||||
{
|
||||
DiscordWhitelister.getPluginLogger().warning("Tried to remove " + nameToRemove + " from in-game-removed-list.yml, but " +
|
||||
nameToRemove + " could not be found, doing nothing...");
|
||||
}
|
||||
}
|
||||
|
||||
// Returns true if the player is in the store/list
|
||||
public static boolean CheckStoreForPlayer(String nameToCheck)
|
||||
{
|
||||
LoadStore();
|
||||
return removedPlayersConfig.get(nameToCheck) != null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package uk.co.angrybee.joe.Stores;
|
||||
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import uk.co.angrybee.joe.DiscordWhitelister;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
//getRemovedList().set("minecraftUsername", "discordRemoverID");
|
||||
|
||||
// Stores removed players that were removed through Discord
|
||||
// removed-list.yml
|
||||
public class RemovedList
|
||||
{
|
||||
private static File removePlayersFile;
|
||||
private static FileConfiguration removedPlayersConfig;
|
||||
|
||||
public static FileConfiguration getRemovedPlayers() { return removedPlayersConfig; }
|
||||
|
||||
public static void StoreSetup()
|
||||
{
|
||||
removePlayersFile = new File(DiscordWhitelister.getPlugin().getDataFolder(), "removed-list.yml");
|
||||
removedPlayersConfig = new YamlConfiguration();
|
||||
|
||||
if(!removePlayersFile.exists())
|
||||
CreateStore();
|
||||
|
||||
LoadStore();
|
||||
SaveStore();
|
||||
}
|
||||
|
||||
private static void CreateStore()
|
||||
{
|
||||
try
|
||||
{
|
||||
removePlayersFile.createNewFile();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void LoadStore()
|
||||
{
|
||||
try
|
||||
{
|
||||
removedPlayersConfig.load(removePlayersFile);
|
||||
}
|
||||
catch (IOException | InvalidConfigurationException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void SaveStore()
|
||||
{
|
||||
try
|
||||
{
|
||||
removedPlayersConfig.save(removePlayersFile.getPath());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// Returns true if the player is in the store/list
|
||||
public static boolean CheckStoreForPlayer(String nameToCheck)
|
||||
{
|
||||
LoadStore();
|
||||
return removedPlayersConfig.get(nameToCheck) != null;
|
||||
}
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
package uk.co.angrybee.joe.Stores;
|
||||
|
||||
// Stores removed players that were removed in-game
|
||||
public class RemovedPlayersStore
|
||||
{
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package uk.co.angrybee.joe.Stores;
|
||||
|
||||
// user-list.yml
|
||||
public class UserList
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
package uk.co.angrybee.joe.Stores;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import uk.co.angrybee.joe.Configs.MainConfig;
|
||||
import uk.co.angrybee.joe.DiscordWhitelister;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
// For accessing whitelisted players
|
||||
public class WhitelistedPlayers
|
||||
{
|
||||
private static Plugin easyWhitelist;
|
||||
private static FileConfiguration easyWhitelistPlayers;
|
||||
|
||||
private static final Server server = DiscordWhitelister.getPlugin().getServer();
|
||||
private static final PluginManager pluginManager = server.getPluginManager();
|
||||
private static final Logger pluginLogger = DiscordWhitelister.getPluginLogger();
|
||||
|
||||
public static boolean usingEasyWhitelist;
|
||||
|
||||
public static void Setup()
|
||||
{
|
||||
// Check if we are using EasyWhitelist
|
||||
if(MainConfig.getMainConfig().getBoolean("use-easy-whitelist"))
|
||||
GetEasyWhitelist();
|
||||
|
||||
if(usingEasyWhitelist)
|
||||
{
|
||||
try
|
||||
{
|
||||
easyWhitelistPlayers = new YamlConfiguration();
|
||||
easyWhitelistPlayers.load(new File(easyWhitelist.getDataFolder(), "config.yml"));
|
||||
}
|
||||
catch (IOException | InvalidConfigurationException e)
|
||||
{
|
||||
pluginLogger.severe("Failed to load the EasyWhitelist file, reverting back to vanilla whitelist command");
|
||||
usingEasyWhitelist = false;
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void GetEasyWhitelist()
|
||||
{
|
||||
if(pluginManager.getPlugin("EasyWhitelist") != null)
|
||||
{
|
||||
pluginLogger.info("Easy Whitelist found; will use over default whitelist command");
|
||||
easyWhitelist = pluginManager.getPlugin("EasyWhitelist");
|
||||
usingEasyWhitelist = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
usingEasyWhitelist = false; // Define this for config hot reloads
|
||||
pluginLogger.warning("Easy Whitelist was not found but is enabled in the config. " +
|
||||
"Falling back to default whitelist command");
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean CheckForPlayer(String playerName)
|
||||
{
|
||||
for(OfflinePlayer offlinePlayer : server.getWhitelistedPlayers())
|
||||
{
|
||||
if(offlinePlayer.getName().equalsIgnoreCase(playerName))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean CheckForPlayerEasyWhitelist(String playerName)
|
||||
{
|
||||
// Check just in case
|
||||
if(!usingEasyWhitelist)
|
||||
return false;
|
||||
|
||||
// Load changes
|
||||
try
|
||||
{
|
||||
easyWhitelistPlayers.load(new File(easyWhitelist.getDataFolder(), "config.yml"));
|
||||
}
|
||||
catch (IOException | InvalidConfigurationException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
for(String name : easyWhitelistPlayers.getStringList("whitelisted"))
|
||||
{
|
||||
if(name.equalsIgnoreCase(playerName))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue