mirror of
https://github.com/Shimeo98/DiscordWhitelisterSpigot.git
synced 2024-11-28 05:35:21 +01:00
moving premium version back over
This commit is contained in:
parent
9435d86106
commit
2b3fa31aeb
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,6 +1,8 @@
|
||||
out/
|
||||
target/
|
||||
.idea/
|
||||
classes/
|
||||
target/
|
||||
discordwhitelister.iml
|
||||
*.iml
|
||||
.attach_pid*
|
||||
dependency-reduced-pom.xml
|
||||
|
@ -1,124 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>uk.co.angrybee.joe</groupId>
|
||||
<artifactId>discord-whitelister</artifactId>
|
||||
<name>discord-whitelister</name>
|
||||
<version>1.3.8</version>
|
||||
<url>https://github.com/JoeShimell/DiscordWhitelisterSpigot</url>
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>3.0.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.0.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-install-plugin</artifactId>
|
||||
<version>2.5.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>2.8.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-site-plugin</artifactId>
|
||||
<version>3.7.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<finalName>${project.artifactId}-${project.version}</finalName>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<relocations />
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<version>1.8</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>install</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<tasks>
|
||||
<copy />
|
||||
</tasks>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
<id>bintray-dv8fromtheworld-maven</id>
|
||||
<name>bintray</name>
|
||||
<url>https://dl.bintray.com/dv8fromtheworld/maven</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.16.3-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
</project>
|
43
pom.xml
43
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>uk.co.angrybee.joe</groupId>
|
||||
<artifactId>discord-whitelister</artifactId>
|
||||
<version>1.3.8</version>
|
||||
<version>1.4.0</version>
|
||||
|
||||
<name>discord-whitelister</name>
|
||||
<url>https://github.com/JoeShimell/DiscordWhitelisterSpigot</url>
|
||||
@ -22,6 +22,7 @@
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
@ -40,6 +41,7 @@
|
||||
<version>1.16.3-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.dv8tion</groupId>
|
||||
<artifactId>JDA</artifactId>
|
||||
@ -51,76 +53,94 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-api</artifactId>
|
||||
<version>2.12.1</version>
|
||||
<version>2.13.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.13.2</version>
|
||||
<version>2.13.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
<version>2.12.1</version>
|
||||
<version>2.13.3</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-shade-plugin -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
<version>1.26</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<type>maven-plugin</type>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
|
||||
<plugin>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
</plugin>
|
||||
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>3.0.2</version>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.1</version>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.0.2</version>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-install-plugin</artifactId>
|
||||
<version>2.5.2</version>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>2.8.2</version>
|
||||
</plugin>
|
||||
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
|
||||
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-site-plugin</artifactId>
|
||||
<version>3.7.1</version>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
@ -146,7 +166,7 @@
|
||||
<version>1.8</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>install</phase>
|
||||
<phase>test</phase>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
@ -159,8 +179,8 @@
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
</pluginManagement>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
@ -177,5 +197,6 @@
|
||||
<version>3.2.4</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
</build>
|
||||
</project>
|
||||
|
@ -5,10 +5,13 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class AuthorPermissions {
|
||||
public class AuthorPermissions
|
||||
{
|
||||
private boolean userCanAddRemove = false;
|
||||
private boolean userCanAdd = false;
|
||||
private boolean userHasLimitedAdd = false;
|
||||
private boolean userIsBanned = false;
|
||||
private boolean userCanUseClear = false;
|
||||
|
||||
public boolean isUserCanAddRemove() {
|
||||
return userCanAddRemove;
|
||||
@ -27,8 +30,13 @@ public class AuthorPermissions {
|
||||
return userCanAdd || userCanAddRemove || userHasLimitedAdd;
|
||||
}
|
||||
|
||||
public boolean isUserIsBanned() { return userIsBanned; }
|
||||
|
||||
public boolean isUserCanUseClear() { return userCanUseClear; }
|
||||
|
||||
public AuthorPermissions(MessageReceivedEvent event)
|
||||
{
|
||||
// TODO: merge these all together? why calling more times than needed
|
||||
for (Role role : event.getGuild().getMember(event.getAuthor()).getRoles())
|
||||
{
|
||||
if(!DiscordWhitelister.useIdForRoles)
|
||||
@ -88,5 +96,48 @@ public class AuthorPermissions {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(DiscordWhitelister.useOnBanEvents)
|
||||
{
|
||||
for(Role role : event.getGuild().getMember(event.getAuthor()).getRoles())
|
||||
{
|
||||
if(!DiscordWhitelister.useIdForRoles)
|
||||
{
|
||||
if (Arrays.stream(DiscordWhitelister.bannedRoles).parallel().anyMatch(role.getName()::equalsIgnoreCase))
|
||||
{
|
||||
userIsBanned = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Arrays.stream(DiscordWhitelister.bannedRoles).parallel().anyMatch(role.getId()::equalsIgnoreCase))
|
||||
{
|
||||
userIsBanned = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(Role role : event.getGuild().getMember(event.getAuthor()).getRoles())
|
||||
{
|
||||
if(!DiscordWhitelister.useIdForRoles)
|
||||
{
|
||||
if(Arrays.stream(DiscordClient.allowedToClearNamesRoles).parallel().anyMatch(role.getName()::equalsIgnoreCase))
|
||||
{
|
||||
userCanUseClear = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(Arrays.stream(DiscordClient.allowedToClearNamesRoles).parallel().anyMatch(role.getId()::equalsIgnoreCase))
|
||||
{
|
||||
userCanUseClear = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,40 +0,0 @@
|
||||
package uk.co.angrybee.joe;
|
||||
|
||||
import net.dv8tion.jda.api.events.DisconnectEvent;
|
||||
import net.dv8tion.jda.api.events.ShutdownEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import net.dv8tion.jda.api.requests.CloseCode;
|
||||
import net.dv8tion.jda.api.requests.GatewayIntent;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
// Check for privileged intents on disconnect
|
||||
public class CheckIntents extends ListenerAdapter
|
||||
{
|
||||
@Override
|
||||
public void onShutdown(ShutdownEvent shutdownEvent)
|
||||
{
|
||||
CheckIntents(shutdownEvent.getCloseCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnect(DisconnectEvent disconnectEvent)
|
||||
{
|
||||
CheckIntents(disconnectEvent.getCloseCode());
|
||||
}
|
||||
|
||||
private void CheckIntents(CloseCode closeCode)
|
||||
{
|
||||
if(closeCode == null)
|
||||
return;
|
||||
|
||||
if(closeCode == CloseCode.DISALLOWED_INTENTS)
|
||||
{
|
||||
DiscordClient.ShutdownClient();
|
||||
|
||||
DiscordWhitelister.getPluginLogger().severe("[DiscordWhitelister] Cannot connect as this bot is not eligible to request the privileged intent 'GUILD_MEMBERS'");
|
||||
DiscordWhitelister.getPluginLogger().severe("[DiscordWhitelister] To correct this please go to your bot located at: https://discord.com/developers/applications and enable 'Server Members Intent'");
|
||||
}
|
||||
}
|
||||
}
|
@ -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.");
|
||||
|
||||
@ -103,6 +106,24 @@ public class CustomMessagesConfig
|
||||
|
||||
CheckEntry("remove-success-title", "{MinecraftUsername} has been removed");
|
||||
CheckEntry("remove-success", "{Sender} has removed {MinecraftUsername} from the whitelist");
|
||||
|
||||
CheckEntry("banned-title", "You have been banned!");
|
||||
CheckEntry("banned-message", "{Sender}, you cannot use this bot as you have been banned!");
|
||||
|
||||
CheckEntry("clear-name-success-title", "Successfully Cleared `{MinecraftUsername}`");
|
||||
CheckEntry("clear-name-success-message", "{Sender} successfully cleared username `{MinecraftUsername}` from {DiscordID}'s whitelisted users.");
|
||||
|
||||
CheckEntry("clear-name-failure-title", "{MinecraftUsername} not Found");
|
||||
CheckEntry("clear-name-failure-message", "{Sender}, could not find name `{MinecraftUsername}` to clear in user list.");
|
||||
|
||||
CheckEntry("clear-ban-success-title", "Successfully Cleared `{MinecraftUsername}`");
|
||||
CheckEntry("clear-ban-success-message", "{Sender} has successfully cleared `{MinecraftUsername}` from the removed list(s).");
|
||||
|
||||
CheckEntry("clear-ban-failure-title", "Failed to clear `{MinecraftUsername}`");
|
||||
CheckEntry("clear-ban-failure-message", "{Sender}, `{MinecraftUsername}` cannot be found in any of the removed lists!");
|
||||
|
||||
CheckEntry("instructional-message-title", "How to Whitelist");
|
||||
CheckEntry("instructional-message", "Use `!whitelist add <minecraftUsername>` to whitelist yourself. In the case of whitelisting an incorrect name, please contact a staff member to clear it from the whitelist.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,6 +65,10 @@ public class CustomPrefixConfig
|
||||
CheckEntry("whitelist-add-prefix", "!whitelist add");
|
||||
|
||||
CheckEntry("whitelist-remove-prefix", "!whitelist remove");
|
||||
|
||||
CheckEntry("clear-name-prefix", "!clearname");
|
||||
|
||||
CheckEntry("clear-ban-prefix", "!clearban");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,6 +86,11 @@ public class MainConfig
|
||||
// The roles to add/remove when whitelisted/removed
|
||||
CheckEntry("whitelisted-roles", Collections.singletonList("Whitelisted"));
|
||||
|
||||
CheckEntry("banned-roles", Collections.singletonList("Banned"));
|
||||
|
||||
// For clear name & ban commands
|
||||
CheckEntry("clear-command-roles", Collections.singletonList("Admin"));
|
||||
|
||||
CheckEntry("target-text-channels", Arrays.asList("000000000000000000", "111111111111111111"));
|
||||
|
||||
// EasyWhitelist support (https://www.spigotmc.org/resources/easywhitelist-name-based-whitelist.65222/)
|
||||
@ -100,6 +105,11 @@ public class MainConfig
|
||||
// If the limited whitelist feature should be enabled
|
||||
CheckEntry("limited-whitelist-enabled", true);
|
||||
|
||||
// Remove whitelisted role, assign to banned role, remove their whitelisted players
|
||||
CheckEntry("use-on-ban-events", false);
|
||||
|
||||
CheckEntry("unwhitelist-and-clear-perms-on-name-clear", true);
|
||||
|
||||
// The amount of times a non-staff user is allowed to whitelist
|
||||
CheckEntry("max-whitelist-amount", 3);
|
||||
|
||||
@ -107,6 +117,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 +129,18 @@ public class MainConfig
|
||||
|
||||
CheckEntry("show-vanished-players-in-player-count", false);
|
||||
|
||||
CheckEntry("assign-perms-with-ultra-perms", false);
|
||||
|
||||
CheckEntry("use-on-whitelist-commands", false);
|
||||
|
||||
CheckEntry("send-instructional-message-on-whitelist", false);
|
||||
|
||||
CheckEntry("use-timer-for-instructional-message", false);
|
||||
|
||||
CheckEntry("timer-wait-time-in-seconds", 5);
|
||||
|
||||
CheckEntry("un-whitelist-on-server-leave", true);
|
||||
|
||||
// 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)
|
||||
{
|
||||
|
@ -0,0 +1,114 @@
|
||||
package uk.co.angrybee.joe.Configs;
|
||||
|
||||
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.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
public class OnWhitelistCommandsConfig
|
||||
{
|
||||
private static File onWhitelistCommandsConfigFile;
|
||||
private static FileConfiguration onWhitelistCommandsConfig;
|
||||
|
||||
public static FileConfiguration getPermissionsConfig() { return onWhitelistCommandsConfig; }
|
||||
|
||||
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();
|
||||
|
||||
LoadConfigFile();
|
||||
CheckEntries();
|
||||
SaveConfig();
|
||||
}
|
||||
|
||||
private static void CreateConfig()
|
||||
{
|
||||
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
|
||||
if(onWhitelistCommandsFileCreated)
|
||||
{
|
||||
SaveConfig(); // save and load again
|
||||
try
|
||||
{
|
||||
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"
|
||||
+ "# \"%TYPE%:%COMMAND%\", being %TYPE% whether 'CONSOLE' or 'PLAYER' and the command without the slash (/)\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.");
|
||||
|
||||
fileWriter.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
LoadConfigFile();
|
||||
}
|
||||
|
||||
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...");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
package uk.co.angrybee.joe.Configs;
|
||||
|
||||
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;
|
||||
import java.util.Collections;
|
||||
|
||||
public class PermissionsConfig
|
||||
{
|
||||
private static File permissionsConfigFile;
|
||||
private static FileConfiguration permissionsConfig;
|
||||
|
||||
public static FileConfiguration getPermissionsConfig() { return permissionsConfig; }
|
||||
|
||||
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();
|
||||
|
||||
LoadConfigFile();
|
||||
CheckEntries();
|
||||
SaveConfig();
|
||||
}
|
||||
|
||||
private static void CreateConfig()
|
||||
{
|
||||
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
|
||||
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...");
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -4,48 +4,45 @@ 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;
|
||||
import uk.co.angrybee.joe.Commands.CommandStatus;
|
||||
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.Configs.*;
|
||||
import uk.co.angrybee.joe.Events.JoinLeaveEvents;
|
||||
import uk.co.angrybee.joe.Events.OnBanEvent;
|
||||
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.UserList;
|
||||
import uk.co.angrybee.joe.Stores.WhitelistedPlayers;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
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 useOnBanEvents = true;
|
||||
public static boolean useUltraPerms = false;
|
||||
public static boolean useOnWhitelistCommands = false;
|
||||
|
||||
public static boolean botEnabled;
|
||||
|
||||
public static String[] bannedRoles;
|
||||
|
||||
private static JavaPlugin thisPlugin;
|
||||
private static Server thisServer;
|
||||
private static Logger pluginLogger;
|
||||
@ -71,67 +68,41 @@ public class DiscordWhitelister extends JavaPlugin
|
||||
pluginLogger.severe("Discord Client failed to initialize, please check if your config file is valid");
|
||||
}
|
||||
|
||||
// Check for leavers if enabled
|
||||
if(MainConfig.getMainConfig().getBoolean("un-whitelist-on-server-leave"))
|
||||
{
|
||||
try
|
||||
{
|
||||
DiscordClient.StartUpMemberCheck();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
this.getCommand("discordwhitelister").setExecutor(new CommandStatus());
|
||||
this.getCommand("discordwhitelisterabout").setExecutor(new CommandAbout());
|
||||
this.getCommand("discordwhitelisterreload").setExecutor(new CommandReload());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
DiscordClient.javaDiscordAPI.shutdownNow();
|
||||
}
|
||||
|
||||
public static JavaPlugin getPlugin()
|
||||
{
|
||||
return thisPlugin;
|
||||
}
|
||||
|
||||
public static FileConfiguration getWhitelisterBotConfig() { return MainConfig.getMainConfig(); }
|
||||
|
||||
public static FileConfiguration getUserList()
|
||||
{
|
||||
return userList;
|
||||
}
|
||||
|
||||
public static File getUserListFile()
|
||||
{
|
||||
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; }
|
||||
|
||||
public static List<?> getRegisteredUsers(String userId) { return userList.getList(userId); }
|
||||
|
||||
public static int getRegisteredUsersCount(String userId) {
|
||||
try {
|
||||
return getRegisteredUsers(userId).size();
|
||||
} catch(NullPointerException ex) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean getUseCustomPrefixes() { return useCustomPrefixes; }
|
||||
|
||||
public static void addRegisteredUser(String userId, String userToAdd) throws IOException {
|
||||
List <?> x = getRegisteredUsers(userId);
|
||||
List <String> newList = new ArrayList<>();
|
||||
for (Object o: x) {
|
||||
newList.add(o.toString());
|
||||
}
|
||||
newList.add(userToAdd);
|
||||
getUserList().set(userId, newList);
|
||||
getUserList().save(getUserListFile().getPath());
|
||||
}
|
||||
|
||||
public static void resetRegisteredUsers(String userId) throws IOException {
|
||||
getUserList().set(userId, new ArrayList<>());
|
||||
getUserList().save(getUserListFile().getPath());
|
||||
}
|
||||
|
||||
public static void addVanishedPlayer() { vanishedPlayersCount++; }
|
||||
|
||||
public static void removeVanishedPlayer() { vanishedPlayersCount--; }
|
||||
@ -142,23 +113,41 @@ public class DiscordWhitelister extends JavaPlugin
|
||||
|
||||
public static int InitBot(boolean firstInit)
|
||||
{
|
||||
userList = new YamlConfiguration();
|
||||
removedList = new YamlConfiguration();
|
||||
|
||||
if(firstInit)
|
||||
vanishedPlayersCount = 0;
|
||||
|
||||
ConfigSetup();
|
||||
|
||||
botToken = getWhitelisterBotConfig().getString("discord-bot-token");
|
||||
botEnabled = getWhitelisterBotConfig().getBoolean("bot-enabled");
|
||||
showPlayerSkin = getWhitelisterBotConfig().getBoolean("show-player-skin-on-whitelist");
|
||||
botToken = MainConfig.getMainConfig().getString("discord-bot-token");
|
||||
botEnabled = MainConfig.getMainConfig().getBoolean("bot-enabled");
|
||||
showPlayerSkin = MainConfig.getMainConfig().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");
|
||||
useOnBanEvents = MainConfig.getMainConfig().getBoolean("use-on-ban-events");
|
||||
|
||||
// Check for UltraPerms first
|
||||
if(MainConfig.getMainConfig().getBoolean("assign-perms-with-ultra-perms"))
|
||||
{
|
||||
if(DiscordWhitelister.getPlugin().getServer().getPluginManager().getPlugin("UltraPermissions") != null)
|
||||
{
|
||||
useUltraPerms = true;
|
||||
DiscordWhitelister.getPluginLogger().info("Ultra Permissions found!");
|
||||
}
|
||||
else
|
||||
{
|
||||
DiscordWhitelister.getPluginLogger().warning("Ultra Permissions was not found but is enabled in the config. Doing nothing...");
|
||||
useUltraPerms = false;
|
||||
}
|
||||
}
|
||||
|
||||
DiscordClient.whitelistAddPrefix = CustomPrefixConfig.getCustomPrefixesConfig().getString("whitelist-add-prefix");
|
||||
DiscordClient.whitelistRemovePrefix = CustomPrefixConfig.getCustomPrefixesConfig().getString("whitelist-remove-prefix");
|
||||
if(MainConfig.getMainConfig().getBoolean("use-on-whitelist-commands"))
|
||||
useOnWhitelistCommands = true;
|
||||
|
||||
DiscordClient.whitelistAddPrefix = CustomPrefixConfig.getCustomPrefixesConfig().getString("whitelist-add-prefix").toLowerCase();
|
||||
DiscordClient.whitelistRemovePrefix = CustomPrefixConfig.getCustomPrefixesConfig().getString("whitelist-remove-prefix").toLowerCase();
|
||||
DiscordClient.clearNamePrefix = CustomPrefixConfig.getCustomPrefixesConfig().getString("clear-name-prefix").toLowerCase();
|
||||
DiscordClient.clearBanPrefix = CustomPrefixConfig.getCustomPrefixesConfig().getString("clear-ban-prefix").toLowerCase();
|
||||
|
||||
if(!botEnabled)
|
||||
{
|
||||
@ -172,58 +161,61 @@ public class DiscordWhitelister extends JavaPlugin
|
||||
{
|
||||
pluginLogger.info("Initializing Discord client...");
|
||||
|
||||
useIdForRoles = getWhitelisterBotConfig().getBoolean("use-id-for-roles");
|
||||
// TODO: below role section could be moved to DiscordClient class
|
||||
useIdForRoles = MainConfig.getMainConfig().getBoolean("use-id-for-roles");
|
||||
|
||||
// set add & remove roles
|
||||
DiscordClient.allowedToAddRemoveRoles = new String[getWhitelisterBotConfig().getList("add-remove-roles").size()];
|
||||
DiscordClient.allowedToAddRemoveRoles = new String[MainConfig.getMainConfig().getList("add-remove-roles").size()];
|
||||
for(int roles = 0; roles < DiscordClient.allowedToAddRemoveRoles.length; ++roles)
|
||||
{
|
||||
DiscordClient.allowedToAddRemoveRoles[roles] = getWhitelisterBotConfig().getList("add-remove-roles").get(roles).toString();
|
||||
DiscordClient.allowedToAddRemoveRoles[roles] = MainConfig.getMainConfig().getList("add-remove-roles").get(roles).toString();
|
||||
}
|
||||
|
||||
// set add roles
|
||||
DiscordClient.allowedToAddRoles = new String[getWhitelisterBotConfig().getList("add-roles").size()];
|
||||
DiscordClient.allowedToAddRoles = new String[MainConfig.getMainConfig().getList("add-roles").size()];
|
||||
for(int roles = 0; roles < DiscordClient.allowedToAddRoles.length; ++roles)
|
||||
{
|
||||
DiscordClient.allowedToAddRoles[roles] = getWhitelisterBotConfig().getList("add-roles").get(roles).toString();
|
||||
DiscordClient.allowedToAddRoles[roles] = MainConfig.getMainConfig().getList("add-roles").get(roles).toString();
|
||||
}
|
||||
|
||||
// set limited add roles
|
||||
DiscordClient.allowedToAddLimitedRoles = new String[getWhitelisterBotConfig().getList("limited-add-roles").size()];
|
||||
DiscordClient.allowedToAddLimitedRoles = new String[MainConfig.getMainConfig().getList("limited-add-roles").size()];
|
||||
for(int roles = 0; roles < DiscordClient.allowedToAddLimitedRoles.length; ++roles)
|
||||
{
|
||||
DiscordClient.allowedToAddLimitedRoles[roles] = getWhitelisterBotConfig().getList("limited-add-roles").get(roles).toString();
|
||||
DiscordClient.allowedToAddLimitedRoles[roles] = MainConfig.getMainConfig().getList("limited-add-roles").get(roles).toString();
|
||||
}
|
||||
|
||||
// easy whitelist check
|
||||
if(getWhitelisterBotConfig().getBoolean("use-easy-whitelist"))
|
||||
// Get banned roles
|
||||
if(useOnBanEvents)
|
||||
{
|
||||
pluginLogger.info("Checking for Easy Whitelist...");
|
||||
if(thisServer.getPluginManager().getPlugin("EasyWhitelist") != null)
|
||||
List<String> tempBannedRoles = MainConfig.getMainConfig().getStringList("banned-roles");
|
||||
bannedRoles = new String[tempBannedRoles.size()];
|
||||
for(int i = 0; i < tempBannedRoles.size(); i++)
|
||||
{
|
||||
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.");
|
||||
bannedRoles[i] = tempBannedRoles.get(i);
|
||||
}
|
||||
}
|
||||
|
||||
// Allowed to clear name roles
|
||||
DiscordClient.allowedToClearNamesRoles = new String[MainConfig.getMainConfig().getStringList("clear-command-roles").size()];
|
||||
for(int roles = 0; roles < DiscordClient.allowedToClearNamesRoles.length; roles++)
|
||||
{
|
||||
DiscordClient.allowedToClearNamesRoles[roles] = MainConfig.getMainConfig().getStringList("clear-command-roles").get(roles);
|
||||
}
|
||||
|
||||
// Custom messages check
|
||||
useCustomMessages = getWhitelisterBotConfig().getBoolean("use-custom-messages");
|
||||
useCustomPrefixes = getWhitelisterBotConfig().getBoolean("use-custom-prefixes");
|
||||
useCustomMessages = MainConfig.getMainConfig().getBoolean("use-custom-messages");
|
||||
useCustomPrefixes = MainConfig.getMainConfig().getBoolean("use-custom-prefixes");
|
||||
|
||||
int initSuccess = DiscordClient.InitializeClient(botToken);
|
||||
|
||||
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"))
|
||||
if(MainConfig.getMainConfig().getBoolean("show-player-count"))
|
||||
{
|
||||
// Register events if enabled
|
||||
thisServer.getPluginManager().registerEvents(new JoinLeaveEvents(), thisPlugin);
|
||||
@ -232,6 +224,14 @@ public class DiscordWhitelister extends JavaPlugin
|
||||
DiscordClient.SetPlayerCountStatus(getOnlineUsers());
|
||||
}
|
||||
|
||||
// Register whitelist events if enabled
|
||||
if(useInGameAddRemoves)
|
||||
thisServer.getPluginManager().registerEvents(new OnWhitelistEvents(), thisPlugin);
|
||||
|
||||
// Register ban events if enabled
|
||||
if(useOnBanEvents)
|
||||
thisServer.getPluginManager().registerEvents(new OnBanEvent(), thisPlugin);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -240,88 +240,19 @@ public class DiscordWhitelister extends JavaPlugin
|
||||
|
||||
public static void ConfigSetup()
|
||||
{
|
||||
File dataFolder = thisPlugin.getDataFolder();
|
||||
Logger pluginLogger = thisPlugin.getLogger();
|
||||
|
||||
// Run this first, as it creates the root folder if it does not exist
|
||||
MainConfig.ConfigSetup();
|
||||
|
||||
CustomPrefixConfig.ConfigSetup();
|
||||
CustomMessagesConfig.ConfigSetup();
|
||||
PermissionsConfig.ConfigSetup();
|
||||
OnWhitelistCommandsConfig.ConfigSetup();
|
||||
|
||||
userListFile = new File(dataFolder, "user-list.yml");
|
||||
removedListFile = new File(dataFolder, "removed-list.yml");
|
||||
// Init Stores
|
||||
UserList.StoreSetup();
|
||||
InGameRemovedList.StoreSetup();
|
||||
RemovedList.StoreSetup();
|
||||
|
||||
if(!userListFile.exists())
|
||||
{
|
||||
try
|
||||
{
|
||||
userListFile.createNewFile();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
pluginLogger.info("User list created at: " + userListFile.getPath());
|
||||
userListCreated = true;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
getUserList().load(userListFile);
|
||||
}
|
||||
catch (IOException | InvalidConfigurationException e)
|
||||
{
|
||||
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
|
||||
{
|
||||
getUserList().save(userListFile.getPath());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if(removedListCreated)
|
||||
{
|
||||
//getRemovedList().set("minecraftUsername", "discordRemoverID");
|
||||
try
|
||||
{
|
||||
getRemovedList().save(removedListFile.getPath());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
WhitelistedPlayers.Setup();
|
||||
}
|
||||
}
|
||||
|
149
src/main/java/uk/co/angrybee/joe/Events/OnBanEvent.java
Normal file
149
src/main/java/uk/co/angrybee/joe/Events/OnBanEvent.java
Normal file
@ -0,0 +1,149 @@
|
||||
package uk.co.angrybee.joe.Events;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import uk.co.angrybee.joe.Configs.MainConfig;
|
||||
import uk.co.angrybee.joe.Configs.PermissionsConfig;
|
||||
import uk.co.angrybee.joe.DiscordClient;
|
||||
import uk.co.angrybee.joe.DiscordWhitelister;
|
||||
import uk.co.angrybee.joe.Stores.InGameRemovedList;
|
||||
import uk.co.angrybee.joe.Stores.UserList;
|
||||
import uk.co.angrybee.joe.Stores.WhitelistedPlayers;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class OnBanEvent implements Listener
|
||||
{
|
||||
@EventHandler
|
||||
public void onCommandBan(PlayerCommandPreprocessEvent e) throws IOException
|
||||
{
|
||||
// Context
|
||||
Player commandCaller = e.getPlayer();
|
||||
String message = e.getMessage().toLowerCase();
|
||||
|
||||
// // Check just in case?
|
||||
// if(!DiscordWhitelister.useOnBanEvents)
|
||||
// return;
|
||||
|
||||
// Check if player is using the ban command
|
||||
if(!message.startsWith("/ban"))
|
||||
return;
|
||||
|
||||
// Check if the player has permission to use the ban command before proceeding
|
||||
// Do not bother checking if the player can ban ips as we get no useful information from it
|
||||
if(!commandCaller.hasPermission("bukkit.command.ban.player"))
|
||||
return;
|
||||
|
||||
String banTarget = message.substring("/ban".length() + 1).toLowerCase();
|
||||
// Remove ban reason if there is one
|
||||
if(banTarget.contains(" "))
|
||||
{
|
||||
banTarget = banTarget.substring(0, banTarget.indexOf(" "));
|
||||
}
|
||||
|
||||
// Check if there is a name to query
|
||||
if(banTarget.equals(""))
|
||||
return;
|
||||
|
||||
// Check if the player has ever joined the server or is on the whitelist
|
||||
Server server = DiscordWhitelister.getPlugin().getServer();
|
||||
if(!server.getOnlinePlayers().contains(banTarget) || !server.getOnlinePlayers().contains(banTarget))
|
||||
{
|
||||
if(!WhitelistedPlayers.usingEasyWhitelist && !WhitelistedPlayers.CheckForPlayer(banTarget)
|
||||
|| WhitelistedPlayers.usingEasyWhitelist && !WhitelistedPlayers.CheckForPlayerEasyWhitelist(banTarget))
|
||||
{
|
||||
DiscordWhitelister.getPluginLogger().info(commandCaller.getName() + " is attempting to ban player with the name " + banTarget
|
||||
+ " but the user is not on the whitelist nor have they joined the server; doing nothing...");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Assign initial ban target to in-game removed list
|
||||
InGameRemovedList.AddUserToStore(banTarget, commandCaller.getDisplayName());
|
||||
|
||||
// Check if the player is whitelisted
|
||||
if(!WhitelistedPlayers.usingEasyWhitelist && WhitelistedPlayers.CheckForPlayer(banTarget)
|
||||
|| WhitelistedPlayers.usingEasyWhitelist && WhitelistedPlayers.CheckForPlayerEasyWhitelist(banTarget))
|
||||
{
|
||||
Boolean idFound = false;
|
||||
String targetDiscordId = "";
|
||||
List<String> targetWhitelistedPlayers = Collections.emptyList();
|
||||
|
||||
// Find the Discord Id linked to the whitelisted player
|
||||
Yaml userYaml = new Yaml();
|
||||
|
||||
InputStream inputStream = new FileInputStream(UserList.getUserListFile());
|
||||
|
||||
Map<String, List<String>> testObject = userYaml.load(inputStream);
|
||||
|
||||
for(Map.Entry<String, List<String>> entry : testObject.entrySet())
|
||||
{
|
||||
for(int i = 0; i < entry.getValue().size(); i++)
|
||||
{
|
||||
if(entry.getValue().get(i).equals(banTarget))
|
||||
{
|
||||
// Found the ban target, assign the corresponding Discord id
|
||||
targetDiscordId = entry.getKey();
|
||||
targetWhitelistedPlayers = entry.getValue();
|
||||
idFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(idFound)
|
||||
{
|
||||
// Remove whitelisted players associated with the discord id
|
||||
for(int i = 0; i < targetWhitelistedPlayers.size(); i++)
|
||||
{
|
||||
if(!WhitelistedPlayers.usingEasyWhitelist)
|
||||
{
|
||||
DiscordClient.ExecuteServerCommand("whitelist remove " + targetWhitelistedPlayers.get(i));
|
||||
}
|
||||
else
|
||||
{
|
||||
DiscordClient.ExecuteServerCommand("easywl remove " + targetWhitelistedPlayers.get(i));
|
||||
}
|
||||
|
||||
DiscordWhitelister.getPluginLogger().info("Removed " + targetWhitelistedPlayers.get(i)
|
||||
+ " from the whitelist as they were added by Discord Id: " + targetDiscordId);
|
||||
|
||||
// Add username to the in-game removed list
|
||||
InGameRemovedList.AddUserToStore(targetWhitelistedPlayers.get(i), commandCaller.getDisplayName());
|
||||
}
|
||||
|
||||
// Remove the users whitelisted players from the list
|
||||
UserList.getUserList().set(targetDiscordId, null);
|
||||
|
||||
// Remove perms on ban if enabled
|
||||
if(DiscordWhitelister.useUltraPerms)
|
||||
DiscordClient.RemovePermsFromUser(banTarget, PermissionsConfig.getPermissionsConfig().getStringList("perms-on-whitelist"));
|
||||
|
||||
UserList.SaveStore();
|
||||
|
||||
// Find all servers bot is in, assign & remove roles
|
||||
for(int i = 0; i < DiscordClient.javaDiscordAPI.getGuilds().size(); i++)
|
||||
{
|
||||
// Remove the whitelisted role(s)
|
||||
DiscordClient.RemoveRolesFromUser(DiscordClient.javaDiscordAPI.getGuilds().get(i), targetDiscordId, Arrays.asList(DiscordClient.whitelistedRoleNames));
|
||||
// Add the banned role(s)
|
||||
DiscordClient.AssignRolesToUser(DiscordClient.javaDiscordAPI.getGuilds().get(i), targetDiscordId, (List<String>) MainConfig.getMainConfig().get("banned-roles"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DiscordWhitelister.getPluginLogger().warning(banTarget + " does not have a linked Discord Id; cannot assign roles!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -3,26 +3,37 @@ 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;
|
||||
|
||||
// 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 +50,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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
30
src/main/java/uk/co/angrybee/joe/Events/ShutdownEvents.java
Normal file
30
src/main/java/uk/co/angrybee/joe/Events/ShutdownEvents.java
Normal file
@ -0,0 +1,30 @@
|
||||
package uk.co.angrybee.joe.Events;
|
||||
|
||||
import net.dv8tion.jda.api.events.ShutdownEvent;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import net.dv8tion.jda.api.requests.CloseCode;
|
||||
import uk.co.angrybee.joe.DiscordClient;
|
||||
import uk.co.angrybee.joe.DiscordWhitelister;
|
||||
|
||||
public class ShutdownEvents extends ListenerAdapter
|
||||
{
|
||||
@Override
|
||||
public void onShutdown(ShutdownEvent shutdownEvent)
|
||||
{
|
||||
CheckIntents(shutdownEvent.getCloseCode());
|
||||
}
|
||||
|
||||
// Check for the 'SERVER MEMBERS INTENT' and inform users if not enabled
|
||||
private void CheckIntents(CloseCode closeCode)
|
||||
{
|
||||
if(closeCode == null)
|
||||
return;
|
||||
|
||||
if(closeCode == CloseCode.DISALLOWED_INTENTS)
|
||||
{
|
||||
DiscordWhitelister.getPluginLogger().severe("\u001B[31m" + "Cannot connect as this bot is not eligible to request the privileged intent 'GUILD_MEMBERS'" + "\u001B[0m");
|
||||
DiscordWhitelister.getPluginLogger().severe( "\u001B[31m" + "To fix this, please enable 'SERVER MEMBERS INTENT' located " +
|
||||
"at https://discord.com/developers/applications -> the application you're using to run this bot -> the button called 'bot' on the left" + "\u001B[0m");
|
||||
}
|
||||
}
|
||||
}
|
104
src/main/java/uk/co/angrybee/joe/Stores/InGameRemovedList.java
Normal file
104
src/main/java/uk/co/angrybee/joe/Stores/InGameRemovedList.java
Normal file
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
public 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;
|
||||
}
|
||||
}
|
76
src/main/java/uk/co/angrybee/joe/Stores/RemovedList.java
Normal file
76
src/main/java/uk/co/angrybee/joe/Stores/RemovedList.java
Normal file
@ -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
|
||||
{
|
||||
}
|
106
src/main/java/uk/co/angrybee/joe/Stores/UserList.java
Normal file
106
src/main/java/uk/co/angrybee/joe/Stores/UserList.java
Normal file
@ -0,0 +1,106 @@
|
||||
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;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
// user-list.yml
|
||||
public class UserList
|
||||
{
|
||||
private static File userListFile;
|
||||
private static FileConfiguration userList;
|
||||
|
||||
public static File getUserListFile() { return userListFile; }
|
||||
public static FileConfiguration getUserList()
|
||||
{
|
||||
return userList;
|
||||
}
|
||||
public static List<?> getRegisteredUsers(String userId) { return userList.getList(userId); }
|
||||
|
||||
public static void StoreSetup()
|
||||
{
|
||||
userListFile = new File(DiscordWhitelister.getPlugin().getDataFolder(), "user-list.yml");
|
||||
userList = new YamlConfiguration();
|
||||
|
||||
if(!userListFile.exists())
|
||||
CreateStore();
|
||||
|
||||
LoadStore();
|
||||
SaveStore();
|
||||
}
|
||||
|
||||
private static void CreateStore()
|
||||
{
|
||||
try
|
||||
{
|
||||
userListFile.createNewFile();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void LoadStore()
|
||||
{
|
||||
try
|
||||
{
|
||||
userList.load(userListFile);
|
||||
}
|
||||
catch (IOException | InvalidConfigurationException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void SaveStore()
|
||||
{
|
||||
try
|
||||
{
|
||||
userList.save(userListFile.getPath());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static int getRegisteredUsersCount(String userId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return getRegisteredUsers(userId).size();
|
||||
}
|
||||
catch(NullPointerException e)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static void addRegisteredUser(String userId, String userToAdd) throws IOException
|
||||
{
|
||||
List <?> x = getRegisteredUsers(userId);
|
||||
List <String> newList = new ArrayList<>();
|
||||
|
||||
for (Object o: x)
|
||||
{
|
||||
newList.add(o.toString());
|
||||
}
|
||||
|
||||
newList.add(userToAdd);
|
||||
userList.set(userId, newList);
|
||||
SaveStore();
|
||||
}
|
||||
|
||||
public static void resetRegisteredUsers(String userId) throws IOException
|
||||
{
|
||||
getUserList().set(userId, null);
|
||||
SaveStore();
|
||||
}
|
||||
}
|
100
src/main/java/uk/co/angrybee/joe/Stores/WhitelistedPlayers.java
Normal file
100
src/main/java/uk/co/angrybee/joe/Stores/WhitelistedPlayers.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
@ -10,5 +10,5 @@ public class VersionInfo
|
||||
return "v." + getVersion();
|
||||
}
|
||||
|
||||
private static String version = "1.3.8";
|
||||
private static String version = "1.4.0";
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
name: DiscordWhitelister
|
||||
version: 1.3.8
|
||||
version: 1.4.0
|
||||
author: Joe Shimell
|
||||
main: uk.co.angrybee.joe.DiscordWhitelister
|
||||
description: Discord whitelister bot.
|
||||
description: Discord Whitelister.
|
||||
commands:
|
||||
discordwhitelister:
|
||||
description: See info about this plugin
|
||||
|
Loading…
Reference in New Issue
Block a user