Merge pull request #5 from zaanposni/feature/remove_on_guild_leave

[Feature] Autounlist on guild leave and version/info command
This commit is contained in:
Joe Shimell 2020-04-14 17:13:31 +01:00 committed by GitHub
commit fdfba50f86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 579 additions and 563 deletions

View File

@ -2,6 +2,13 @@
A simple spigot plugin which allows whitelisting through a discord text channel. This provides an easy way for users to whitelist without needing to be on the minecraft server.
### Backwards compatibility
Version 1.2.0 and greater are not compatible with version 1.1.x and lower.
The layout of the internal user-list.yml got updated.
You need to remove it manually and let the plugin on v1.2.x create a new one.
If you upgrade without knowing what you are doing. Registration will not work correctly.
### Features:
- 3 separate role groups:

View File

@ -1,5 +1,14 @@
name: DiscordWhitelister
version: 1.1.0
version: 1.2.0
author: Joe Shimell
main: uk.co.angrybee.joe.DiscordWhitelister
description: Discord whitelister bot.
description: Discord whitelister bot.
commands:
discordwhitelister:
description: See VersionInfo and Discord status
usage: /<command>
aliases: [dw]
discordwhitelisterabout:
description: See VersionInfo and Discord status
usage: /<command>
aliases: [dwabout]

View File

@ -0,0 +1,51 @@
package uk.co.angrybee.joe;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import java.util.Arrays;
public class AuthorPermissions {
private boolean userCanAddRemove = false;
private boolean userCanAdd = false;
private boolean userHasLimitedAdd = false;
public boolean isUserCanAddRemove() {
return userCanAddRemove;
}
public boolean isUserCanAdd() {
return userCanAdd;
}
public boolean isUserHasLimitedAdd() {
return userHasLimitedAdd;
}
public boolean isUserCanUseCommand() {
return userCanAdd || userCanAddRemove || userHasLimitedAdd;
}
public AuthorPermissions(MessageReceivedEvent event) {
for (Role role : event.getGuild().getMember(event.getAuthor()).getRoles()) {
if (Arrays.stream(DiscordClient.allowedToAddRemoveRoles).parallel().anyMatch(role.getName()::equalsIgnoreCase)) {
userCanAddRemove = true;
break;
}
}
for (Role role : event.getGuild().getMember(event.getAuthor()).getRoles()) {
if (Arrays.stream(DiscordClient.allowedToAddRoles).parallel().anyMatch(role.getName()::equalsIgnoreCase)) {
userCanAdd = true;
break;
}
}
for (Role role : event.getGuild().getMember(event.getAuthor()).getRoles()) {
if (Arrays.stream(DiscordClient.allowedToAddLimitedRoles).parallel().anyMatch(role.getName()::equalsIgnoreCase)) {
userHasLimitedAdd = true;
break;
}
}
}
}

View File

@ -0,0 +1,20 @@
package uk.co.angrybee.joe.Commands;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import uk.co.angrybee.joe.DiscordClient;
import uk.co.angrybee.joe.VersionInfo;
public class CommandAbout implements CommandExecutor {
// /dw
// version command
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
sender.sendMessage("[DW] DiscordWhiteLister by JoeShimell\nhttps://github.com/JoeShimell/DiscordWhitelisterSpigot");
return true;
}
}

View File

@ -0,0 +1,27 @@
package uk.co.angrybee.joe.Commands;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import uk.co.angrybee.joe.DiscordClient;
import uk.co.angrybee.joe.VersionInfo;
public class CommandStatus implements CommandExecutor {
// /dw
// version command
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
String discordOnlineStatus = DiscordClient.getOnlineStatus();
if (discordOnlineStatus.toLowerCase().equals("connected")) {
discordOnlineStatus = ChatColor.GREEN + discordOnlineStatus;
} else {
discordOnlineStatus = ChatColor.RED + discordOnlineStatus;
}
sender.sendMessage("[DW] DiscordWhiteLister runs on: " + VersionInfo.getLongVersion());
sender.sendMessage("[DW] Discord Bot: " + discordOnlineStatus);
return true;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -5,6 +5,8 @@ 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.CommandStatus;
import java.io.File;
import java.io.IOException;
@ -45,9 +47,11 @@ public class DiscordWhitelister extends JavaPlugin
ConfigSetup();
this.getCommand("discordwhitelister").setExecutor(new CommandStatus());
this.getCommand("discordwhitelisterabout").setExecutor(new CommandAbout());
botToken = getWhitelisterBotConfig().getString("discord-bot-token");
botEnabled = getWhitelisterBotConfig().getBoolean("bot-enabled");
if(!botEnabled)
{
getLogger().info("Bot is disabled as per the config, doing nothing");
@ -141,6 +145,32 @@ public class DiscordWhitelister extends JavaPlugin
return removedListFile;
}
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 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 void ConfigSetup()
{
whitelisterBotConfigFile = new File(getDataFolder(), "discord-whitelister.yml");

View File

@ -0,0 +1,13 @@
package uk.co.angrybee.joe;
public class VersionInfo {
public static String getVersion() {
return version;
}
public static String getLongVersion() {
return "v." + getVersion();
}
private static String version = "1.2.0";
}