@@ -44,6 +44,7 @@ public class DiscordClient extends ListenerAdapter
4444 public static String whitelistAddPrefix ;
4545 public static String whitelistRemovePrefix ;
4646 public static String clearNamePrefix ;
47+ public static String limitedWhitelistClearPrefix ;
4748 public static String clearBanPrefix ;
4849
4950 private static MessageEmbed botInfo ;
@@ -1474,13 +1475,156 @@ convert username into UUID to avoid depreciation and rate limits (according to h
14741475 }
14751476 }
14761477
1478+ // Clear whitelists for limited-whitelisters
1479+ if (messageContents .toLowerCase ().startsWith ("!whitelist clear" ) && !DiscordWhitelister .getUseCustomPrefixes ()
1480+ || DiscordWhitelister .getUseCustomPrefixes () && messageContents .toLowerCase ().startsWith (limitedWhitelistClearPrefix ))
1481+ {
1482+ if (!MainConfig .getMainConfig ().getBoolean ("allow-limited-whitelisters-to-unwhitelist-self" ))
1483+ return ;
1484+
1485+ // just inform staff, can add custom messages later if really needed
1486+ if (authorPermissions .isUserCanAddRemove () && !authorPermissions .isUserIsBanned () || authorPermissions .isUserCanAdd () && !authorPermissions .isUserIsBanned ())
1487+ {
1488+ EmbedBuilder onlyForLimitedWhitelisters = new EmbedBuilder ();
1489+ onlyForLimitedWhitelisters .addField ("This Command is Only Available for Limited Whitelister Roles" ,
1490+ "If staff members need to clear a name from the whitelist please use `!clearname <mcName>`." , false );
1491+ onlyForLimitedWhitelisters .setColor (new Color (104 , 109 , 224 ));
1492+ channel .sendMessage (onlyForLimitedWhitelisters .build ()).queue ();
1493+ return ;
1494+ }
1495+
1496+ if (authorPermissions .isUserHasLimitedAdd () && !authorPermissions .isUserIsBanned ())
1497+ {
1498+ List <?> ls = UserList .getRegisteredUsers (author .getId ());
1499+
1500+ // check for names whitelisted
1501+ if (ls != null )
1502+ {
1503+ for (Object minecraftNameToRemove : ls )
1504+ {
1505+ if (WhitelistedPlayers .usingEasyWhitelist )
1506+ {
1507+ ExecuteServerCommand ("easywl remove " + minecraftNameToRemove .toString ());
1508+ }
1509+ else
1510+ {
1511+ ExecuteServerCommand ("whitelist remove " + minecraftNameToRemove .toString ());
1512+ }
1513+ }
1514+
1515+ try
1516+ {
1517+ UserList .resetRegisteredUsers (author .getId ());
1518+ }
1519+ catch (IOException e )
1520+ {
1521+ DiscordWhitelister .getPluginLogger ().severe ("Failed to remove" + author .getId () + "'s entries." );
1522+ e .printStackTrace ();
1523+ return ;
1524+ }
1525+
1526+ DiscordWhitelister .getPlugin ().getLogger ().info ( author .getName () + "(" + author .getId () + ") triggered whitelist clear. " +
1527+ "Successfully removed their whitelisted entries from the user list." );
1528+
1529+ // Log in Discord channel
1530+ EmbedBuilder clearSuccess = new EmbedBuilder ();
1531+ clearSuccess .setColor (new Color (46 , 204 , 113 ));
1532+ if (!DiscordWhitelister .useCustomMessages )
1533+ {
1534+ String message = author .getAsMention () + " successfully removed the following users from the whitelist: \n " ;
1535+ for (Object minercaftName : ls )
1536+ {
1537+ message += "- " + minercaftName .toString () + "\n " ;
1538+ }
1539+ message += "\n You now have **" + maxWhitelistAmount + " whitelist(s) remaining**." ;
1540+
1541+ clearSuccess .addField ("Successfully Removed " + author .getName () + "'s Whitelisted Entries" ,
1542+ message , false );
1543+ }
1544+ else
1545+ {
1546+ String customTitle = DiscordWhitelister .getCustomMessagesConfig ().getString ("whitelist-clear-success-title" );
1547+ customTitle = customTitle .replaceAll ("\\ {Sender}" , author .getName ());
1548+
1549+ String removedNames = "" ;
1550+ for (Object minercaftName : ls )
1551+ {
1552+ removedNames += "- " + minercaftName .toString () + "\n " ;
1553+ }
1554+
1555+ String customMessage = DiscordWhitelister .getCustomMessagesConfig ().getString ("whitelist-clear-success-message" );
1556+ customMessage = customMessage .replaceAll ("\\ {Sender}" , author .getAsMention ());
1557+ customMessage = customMessage .replaceAll ("\\ {RemovedEntries}" , removedNames );
1558+ customMessage = customMessage .replaceAll ("\\ {MaxWhitelistAmount}" , String .valueOf (maxWhitelistAmount ));
1559+
1560+ clearSuccess .addField (customTitle , customMessage , false );
1561+ }
1562+
1563+ channel .sendMessage (clearSuccess .build ()).queue ();
1564+
1565+ if (MainConfig .getMainConfig ().getBoolean ("whitelisted-role-auto-remove" ))
1566+ {
1567+ // Find all servers bot is in, remove whitelisted roles
1568+ for (int i = 0 ; i < javaDiscordAPI .getGuilds ().size (); i ++)
1569+ {
1570+ // Remove the whitelisted role(s)
1571+ RemoveRolesFromUser (javaDiscordAPI .getGuilds ().get (i ), author .getId (), Arrays .asList (whitelistedRoleNames ));
1572+ }
1573+ }
1574+ }
1575+ else
1576+ {
1577+ DiscordWhitelister .getPlugin ().getLogger ().info ( author .getName () + "(" + author .getId () + ") triggered whitelist clear. " +
1578+ "Could not remove any whitelisted entries as they do not have any." );
1579+
1580+ // Log in Discord channel
1581+ EmbedBuilder noEntries = new EmbedBuilder ();
1582+ noEntries .setColor (new Color (231 , 76 , 60 ));
1583+ if (!DiscordWhitelister .useCustomMessages )
1584+ {
1585+ noEntries .addField ("No Entries to Remove" , (author .getAsMention () + ", you do not have any whitelisted entries to remove." ), false );
1586+ }
1587+ else
1588+ {
1589+ String customTitle = DiscordWhitelister .getCustomMessagesConfig ().getString ("whitelist-clear-failure-title" );
1590+ String customMessage = DiscordWhitelister .getCustomMessagesConfig ().getString ("whitelist-clear-failure-message" );
1591+ customMessage = customMessage .replaceAll ("\\ {Sender}" , author .getAsMention ());
1592+
1593+ noEntries .addField (customTitle , customMessage , false );
1594+ }
1595+
1596+ channel .sendMessage (noEntries .build ()).queue ();
1597+ }
1598+ }
1599+
1600+ if (!authorPermissions .isUserCanAddRemove () && !authorPermissions .isUserCanAdd () && !authorPermissions .isUserHasLimitedAdd () || authorPermissions .isUserIsBanned ())
1601+ {
1602+ EmbedBuilder insufficientPermission = new EmbedBuilder ();
1603+ insufficientPermission .setColor (new Color (231 , 76 , 60 ));
1604+
1605+ if (!DiscordWhitelister .useCustomMessages )
1606+ {
1607+ insufficientPermission .addField ("Insufficient Permissions" , (author .getAsMention () + ", you do not have permission to use this command." ), false );
1608+ }
1609+ else
1610+ {
1611+ String customTitle = DiscordWhitelister .getCustomMessagesConfig ().getString ("insufficient-permissions-title" );
1612+ String customMessage = DiscordWhitelister .getCustomMessagesConfig ().getString ("insufficient-permissions" );
1613+ customMessage = customMessage .replaceAll ("\\ {Sender}" , author .getAsMention ()); // Only checking for {Sender}
1614+
1615+ insufficientPermission .addField (customTitle , customMessage , false );
1616+ }
1617+
1618+ channel .sendMessage (insufficientPermission .build ()).queue ();
1619+ return ;
1620+ }
1621+ }
1622+
14771623 if (messageContents .toLowerCase ().startsWith ("!clearban" ) && !DiscordWhitelister .getUseCustomPrefixes ()
14781624 || DiscordWhitelister .getUseCustomPrefixes () && messageContents .toLowerCase ().startsWith (clearBanPrefix ))
14791625 {
14801626 if (authorPermissions .isUserCanUseClear ())
14811627 {
1482-
1483-
14841628 // Check if empty command
14851629 if (messageContents .toLowerCase ().trim ().equals ("!clearban" ) && !DiscordWhitelister .getUseCustomPrefixes ()
14861630 || messageContents .toLowerCase ().trim ().equals (clearBanPrefix ) && DiscordWhitelister .getUseCustomPrefixes ())
@@ -1641,7 +1785,7 @@ public void onGuildMemberRemove(@Nonnull GuildMemberRemoveEvent event)
16411785 }
16421786 else
16431787 {
1644- DiscordWhitelister .getPlugin ().getLogger ().warning (discordUserToRemove + " left. Could not removed their whitelisted entries as they did not whitelist through this plugin." );
1788+ DiscordWhitelister .getPlugin ().getLogger ().warning (discordUserToRemove + " left. Could not remove any whitelisted entries as they did not whitelist through this plugin." );
16451789 }
16461790 }
16471791
0 commit comments