Merge pull request #36 from Xyntexx/feature/Luckperms

feat: Added support for LuckPerms
This commit is contained in:
Joe Shimell 2021-03-04 21:53:50 +00:00 committed by GitHub
commit 0d6ad6705d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 7 deletions

View File

@ -480,9 +480,14 @@ public class DiscordClient extends ListenerAdapter
channel.sendMessage(embedBuilderSuccess.build()).queue();
TempRemoveOriginalMessageAfterSeconds(messageReceivedEvent);
if(DiscordWhitelister.useLuckPerms)
{
LpRemovePermsFromUser(finalNameToRemove, PermissionsConfig.getPermissionsConfig().getStringList("perms-on-whitelist"));
}
if(DiscordWhitelister.useUltraPerms)
{
RemovePermsFromUser(finalNameToRemove, PermissionsConfig.getPermissionsConfig().getStringList("perms-on-whitelist"));
UpRemovePermsFromUser(finalNameToRemove, PermissionsConfig.getPermissionsConfig().getStringList("perms-on-whitelist"));
}
if(whitelistedRoleAutoRemove)
@ -730,8 +735,11 @@ public class DiscordClient extends ListenerAdapter
}
// Clear permissions
// Clear permissions
if(DiscordWhitelister.useLuckPerms)
DiscordClient.LpRemovePermsFromUser(splitMessage[userNameIndex], PermissionsConfig.getPermissionsConfig().getStringList("perms-on-whitelist"));
if(DiscordWhitelister.useUltraPerms)
DiscordClient.RemovePermsFromUser(splitMessage[userNameIndex], PermissionsConfig.getPermissionsConfig().getStringList("perms-on-whitelist"));
DiscordClient.UpRemovePermsFromUser(splitMessage[userNameIndex], PermissionsConfig.getPermissionsConfig().getStringList("perms-on-whitelist"));
}
// Success message
@ -1425,6 +1433,23 @@ public class DiscordClient extends ListenerAdapter
}
}
}
// TODO: improve, not go through console commands
// For ultra perms
public static void LpAssignPermsToUser(String targetPlayerName, List<String> permsToAssign)
{
for(int i = 0; i < permsToAssign.size(); i++)
{
DiscordClient.ExecuteServerCommand("lp user " + targetPlayerName + " permission set " + permsToAssign.get(i));
}
}
public static void LpRemovePermsFromUser(String targetPlayerName, List<String> permsToRemove)
{
for(int i = 0; i < permsToRemove.size(); i++)
{
DiscordClient.ExecuteServerCommand("lp user " + targetPlayerName + " permission unset " + permsToRemove.get(i));
}
}
public static void RemoveMessageAfterSeconds(MessageReceivedEvent messageReceivedEvent, Integer timeToWait)
{
@ -1460,7 +1485,7 @@ public class DiscordClient extends ListenerAdapter
// TODO: improve, not go through console commands
// For ultra perms
public static void AssignPermsToUser(String targetPlayerName, List<String> permsToAssign)
public static void UpAssignPermsToUser(String targetPlayerName, List<String> permsToAssign)
{
for(int i = 0; i < permsToAssign.size(); i++)
{
@ -1468,7 +1493,7 @@ public class DiscordClient extends ListenerAdapter
}
}
public static void RemovePermsFromUser(String targetPlayerName, List<String> permsToRemove)
public static void UpRemovePermsFromUser(String targetPlayerName, List<String> permsToRemove)
{
for(int i = 0; i < permsToRemove.size(); i++)
{

View File

@ -33,6 +33,7 @@ public class DiscordWhitelister extends JavaPlugin
public static boolean useInGameAddRemoves = true;
public static boolean useOnBanEvents = true;
public static boolean useUltraPerms = false;
public static boolean useLuckPerms = false;
public static boolean useOnWhitelistCommands = false;
public static boolean removeUnnecessaryMessages = false;
@ -128,7 +129,20 @@ public class DiscordWhitelister extends JavaPlugin
removeMessageWaitTime = MainConfig.getMainConfig().getInt("seconds-to-remove-message-from-whitelist-channel");
// Check for UltraPerms first
// Check for LuckPerms first
if(MainConfig.getMainConfig().getBoolean("assign-perms-with-luck-perms"))
{
if(DiscordWhitelister.getPlugin().getServer().getPluginManager().getPlugin("LuckPerms") != null)
{
useLuckPerms = true;
DiscordWhitelister.getPluginLogger().info("LuckPerms found!");
}
else
{
DiscordWhitelister.getPluginLogger().warning("LuckPerms was not found but is enabled in the config. Doing nothing...");
useLuckPerms = false;
}
}
if(MainConfig.getMainConfig().getBoolean("assign-perms-with-ultra-perms"))
{
if(DiscordWhitelister.getPlugin().getServer().getPluginManager().getPlugin("UltraPermissions") != null)

View File

@ -488,8 +488,11 @@ public class CommandAdd
// For instructional message
successfulWhitelist.set(true);
if(DiscordWhitelister.useLuckPerms)
DiscordClient.LpAssignPermsToUser(finalNameToAdd, PermissionsConfig.getPermissionsConfig().getStringList("perms-on-whitelist"));
if(DiscordWhitelister.useUltraPerms)
DiscordClient.AssignPermsToUser(finalNameToAdd, PermissionsConfig.getPermissionsConfig().getStringList("perms-on-whitelist"));
DiscordClient.UpAssignPermsToUser(finalNameToAdd, PermissionsConfig.getPermissionsConfig().getStringList("perms-on-whitelist"));
if(DiscordWhitelister.useOnWhitelistCommands)
{

View File

@ -133,6 +133,8 @@ public class MainConfig
CheckEntry("assign-perms-with-ultra-perms", false);
CheckEntry("assign-perms-with-luck-perms", false);
CheckEntry("use-on-whitelist-commands", false);
CheckEntry("send-instructional-message-on-whitelist", false);

View File

@ -145,8 +145,11 @@ public class OnBanEvent implements Listener
UserList.getUserList().set(targetDiscordId, null);
// Remove perms on ban if enabled
if(DiscordWhitelister.useLuckPerms)
DiscordClient.LpRemovePermsFromUser(banTarget, PermissionsConfig.getPermissionsConfig().getStringList("perms-on-whitelist"));
if(DiscordWhitelister.useUltraPerms)
DiscordClient.RemovePermsFromUser(banTarget, PermissionsConfig.getPermissionsConfig().getStringList("perms-on-whitelist"));
DiscordClient.UpRemovePermsFromUser(banTarget, PermissionsConfig.getPermissionsConfig().getStringList("perms-on-whitelist"));
UserList.SaveStore();