Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discord Module #3844

Merged
merged 182 commits into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from 117 commits
Commits
Show all changes
182 commits
Select commit Hold shift + click to select a range
e509082
Third time's a charm?
JRoy Dec 19, 2020
043e82c
Few events, extremely alpha!
JRoy Dec 19, 2020
c25ee44
Merge branch '2.x' into module/discord
JRoy Dec 24, 2020
ec07584
Add EssentialsDiscord to Commandessentials version mismatch checker
JRoy Dec 24, 2020
091423b
Add net.essentialsx to checkstyle suppression filter
JRoy Dec 24, 2020
8d0afca
Fix codestyle comment violations
JRoy Dec 24, 2020
fe444dc
Exclude opus from JDA
JRoy Dec 24, 2020
0d55dce
Add support for competing activity type
JRoy Dec 24, 2020
912cc62
Fix build setup
JRoy Dec 24, 2020
756e925
Strip formatting from messages sent to Discord
JRoy Dec 24, 2020
4c992b6
Strip formatting before sending DiscordMessageEvent
JRoy Dec 24, 2020
9503345
Progress n' docs (It works)
JRoy Dec 25, 2020
66a8cb9
Rename messages to message-types in config
JRoy Dec 26, 2020
b708041
Rework presence config + parsing
JRoy Dec 27, 2020
8692937
Initial start at custom message system
JRoy Dec 28, 2020
eb81fe0
Parse attachment links in game
JRoy Dec 29, 2020
2b8d93d
Add proper emoji parsing
JRoy Dec 29, 2020
8078599
Allow color codes to be sent from discord by certain roles
JRoy Dec 29, 2020
9bc710b
Filter role/here/everyone mentions from chat
JRoy Dec 29, 2020
a9747aa
Move DiscordMessageEvent to net.essentialsx.api.v2.discord.events
JRoy Dec 29, 2020
8d2af67
Add format for mc->discord
JRoy Dec 30, 2020
027fece
Add format for mutes
JRoy Dec 30, 2020
be0d7da
Finish remainder of bukkit messages
JRoy Dec 30, 2020
3ae1e04
Add metrics
JRoy Dec 30, 2020
eace9bf
Add console logger
JRoy Dec 31, 2020
c56b807
Add framework for sending console commands
JRoy Dec 31, 2020
680312e
Merge branch '2.x' into module/discord
JRoy Dec 31, 2020
96b20cc
Add config option for webhook name
JRoy Dec 31, 2020
5fb7e04
Sanitize discord markdown from chat messages
JRoy Dec 31, 2020
8d1c6f8
Add `essentials.discord.markdown` permission to bypass markdown filter
JRoy Dec 31, 2020
a329615
Delay join messages to allow user data to load correctly
JRoy Jan 2, 2021
82b4e46
Move blank message check down
JRoy Jan 2, 2021
a28a271
Add setting to restrict max discord message length
JRoy Jan 2, 2021
9dd38c2
Filter newlines from discord
JRoy Jan 2, 2021
585c3ca
Check permissions before sending messages
JRoy Jan 3, 2021
6c8046c
Add slash command support (#3918)
JRoy Jan 18, 2021
4816754
Docs LOL
JRoy Jan 18, 2021
55237fc
Discord Markdown :/
JRoy Jan 18, 2021
126830e
Finish initial setup docs
JRoy Jan 21, 2021
5b1123d
Console Relay Docs
JRoy Jan 21, 2021
6172163
Merge branch '2.x' into module/discord
JRoy Jan 21, 2021
d26d1a2
Fix message format for console message not being respected
JRoy Jan 21, 2021
9665b7b
Make discord administrators have all role permissions
JRoy Jan 21, 2021
ccc966f
Finish Console Docs
JRoy Jan 21, 2021
d4ce304
Configuring Messages Docs
JRoy Jan 22, 2021
bf78c6e
You do not know what you're doing, I know what you're doing and I wil…
JRoy Jan 22, 2021
ad77680
ahaha i need to stash this away
JRoy Jan 23, 2021
8c1d989
Merge branch '2.x' into module/discord
JRoy Jan 26, 2021
fe9ddc4
Discord commands config docs
JRoy Jan 26, 2021
38504c1
Finished Docs PagMan
JRoy Jan 26, 2021
2585607
Newline
JRoy Jan 26, 2021
86f2000
Run isPermissionSet check for receiving chat messages
JRoy Jan 26, 2021
8991636
Add error for missing command scope
JRoy Jan 26, 2021
49825e5
Add error for deleted console webhook
JRoy Jan 26, 2021
f27b984
Merge branch '2.x' into module/discord
JRoy Feb 15, 2021
c6c77fb
Merge branch '2.x' into module/discord
JRoy Feb 21, 2021
bccb261
Change default mc->discord message
JRoy Feb 24, 2021
0a842dc
Merge branch '2.x' into module/discord
JRoy Mar 4, 2021
0c09bfb
Prevent use of custom status as they are no supported for bots
JRoy Mar 4, 2021
6618299
Merge branch '2.x' into module/discord
JRoy Mar 6, 2021
e8841f7
Use AsyncUserDataLoadEvent to send join messages
JRoy Mar 7, 2021
1494ad2
Make AsyncUserDataLoadEvent use the actual join message (or none in s…
JRoy Mar 7, 2021
d435cc9
Respect silent quit messages
JRoy Mar 7, 2021
6634014
Merge branch '2.x' into module/discord
JRoy Mar 8, 2021
0f53879
Add link to discord authorization page
JRoy Mar 9, 2021
499dbf0
Add option for permission-less environments to always receive primary…
JRoy Mar 9, 2021
1b2841b
Merge branch '2.x' into module/discord
JRoy Mar 19, 2021
169615e
Merge branch '2.x' into module/discord
JRoy Mar 24, 2021
859c14c
Implement discord interaction changes (#4040)
JRoy Mar 24, 2021
87124b6
Strip Essentials format from prefix & suffix
JRoy Mar 25, 2021
c2b73c7
Move webhook fetcher to a future based system
JRoy Mar 25, 2021
6d5a9df
Improve performance of console sending
JRoy Mar 25, 2021
7db58ee
Add plugin name to console message
JRoy Mar 25, 2021
a7e5873
Add config options to show avatar and name for chat messages
JRoy Mar 25, 2021
efaa409
Fix console webhook not surviving /ess reload
JRoy Mar 25, 2021
f91b3fe
Allow all player-related message types to use advanced avatar/name
JRoy Mar 25, 2021
b6d5df5
Add reply support for mc->discord
JRoy Mar 25, 2021
c033162
Bump JDA + Move to their maven repo
JRoy Mar 26, 2021
9c3d77e
Fix broken jackson annotation relocation
JRoy Mar 26, 2021
d17c035
Bump JDA
JRoy Mar 30, 2021
5c8a64a
Add DiscordSRV to plugin version fetcher
JRoy Mar 30, 2021
3dfc723
Dilute pineapple
JRoy Mar 30, 2021
6056650
Merge branch '2.x' into module/discord
JRoy Apr 8, 2021
0bf8b47
Sanitize usernames/display names
JRoy Apr 8, 2021
73d86c2
Allow third-party type creation for DiscordMessageEvent
JRoy Apr 9, 2021
9ede481
Add command registration api
JRoy Apr 9, 2021
9fa1a4e
Vastly improve the provided APIs
JRoy Apr 10, 2021
724507e
Add PAPI Support
JRoy Apr 11, 2021
6502aae
Fix incorrect death format key
JRoy Apr 11, 2021
df74f23
Fix NPE when PAPI was enabled and a format was not in the config
JRoy Apr 11, 2021
fc40c22
Don't send chat messages which are not seen by all people on discord
JRoy Apr 11, 2021
f1a7fc9
Make config punctuation consistent
JRoy Apr 11, 2021
a15e568
Add config option to filter discord messages
JRoy Apr 11, 2021
e2aafb1
Shade slf4j
JRoy Apr 15, 2021
4fa940b
Fix unnecessary sanitization or usernames
JRoy Apr 15, 2021
11c7a42
Fix channels not being resolved to the correct definition at all
JRoy Apr 16, 2021
81dba0c
Merge branch '2.x' into module/discord
JRoy Apr 16, 2021
70e24e1
Fix raw channel ids not resolving
JRoy Apr 16, 2021
a253c95
Add some more debugs in DiscordListener
JRoy Apr 16, 2021
fbd5c55
Add AFK message types
JRoy Apr 27, 2021
da7b2c5
Downsample RGB role colors on versions < 1.16
JRoy Apr 27, 2021
024b2e8
Add log level config option
JRoy Apr 27, 2021
0d303c9
Merge branch '2.x' into module/discord
JRoy Apr 29, 2021
122cc0b
Merge remote-tracking branch 'origin/2.x' into module/discord
JRoy May 1, 2021
a1957f0
Add EssentialsDiscord to javadocs deploy
JRoy May 1, 2021
e62a1af
Add way to get JDA instance through API
JRoy May 1, 2021
0110a30
Fix JDA scope
JRoy May 1, 2021
9c87288
Bump JDA
JRoy May 1, 2021
6f28fda
Better support null argument sets
JRoy May 3, 2021
ba1b3a9
Remove InteractionCommand#addArgument
JRoy May 3, 2021
bb23cde
Remove InteractionCommand#getAdminSnowflakes
JRoy May 3, 2021
4e1726b
Only run startup during initial plugin load
JRoy May 3, 2021
37375c0
Merge branch '2.x' into module/discord
JRoy May 6, 2021
2cd7a8e
Remove 1.16+ note from color config option
JRoy May 6, 2021
0ce6a1c
Merge branch '2.x' into module/discord
JRoy May 10, 2021
44356d0
Fix checkstyle
JRoy May 10, 2021
e0c9c75
Merge branch '2.x' into module/discord
JRoy May 10, 2021
1c92c33
Include full Kyori license
JRoy May 10, 2021
4fc0387
a b c d e f g h i j k l m n o p q r s t u v w x y z
JRoy May 10, 2021
26a3b03
Merge remote-tracking branch 'upstream/module/discord' into module/di…
JRoy May 10, 2021
7ce531c
Merge branch '2.x' into module/discord
JRoy May 13, 2021
9ce2c61
Merge branch '2.x' into module/discord
JRoy May 15, 2021
e77c02b
Merge branch '2.x' into module/discord
JRoy May 19, 2021
f61b1a6
Register commands in bulk to avoid rate limit
JRoy May 20, 2021
755ce10
Support more argument types
JRoy May 24, 2021
4386e6f
Merge branch '2.x' into module/discord
JRoy May 24, 2021
259776b
Remove unneeded null checks
JRoy May 24, 2021
2338f3f
Delete commands in bulk to avoid rate limits
JRoy May 24, 2021
d30c864
Only respond to command interactions
JRoy May 26, 2021
c95cdb2
Fix numbers in README.md
JRoy May 31, 2021
c90db0f
Add UUID param to DiscordMessageEvent
JRoy Jun 1, 2021
6d2395d
Merge branch '2.x' into module/discord
JRoy Jun 3, 2021
a5d1312
Switch to JDA Slash Commands
JRoy Jun 4, 2021
34292eb
Properally handle null arguments
JRoy Jun 4, 2021
c701a70
Fix typo in DiscordMessageEvent constructor
JRoy Jun 7, 2021
2f82912
Developer API Stub
JRoy Jun 7, 2021
cf176f6
Merge remote-tracking branch 'origin/2.x' into module/discord
JRoy Jun 7, 2021
183ec5f
Merge branch '2.x' into module/discord
JRoy Jun 7, 2021
c0d5a77
Merge branch '2.x' into module/discord
JRoy Jun 8, 2021
50f33da
Merge branch '2.x' into module/discord
JRoy Jun 10, 2021
57600f3
Add DiscordChatMessageEvent
JRoy Jun 10, 2021
c3bfe4d
Merge branch '2.x' into module/discord
JRoy Jun 11, 2021
b743d86
Add docs for sending message via default channels
JRoy Jun 11, 2021
369f0a2
Prevent disabled commands from being executed even when registering
JRoy Jun 11, 2021
766887d
Add convenience constructor for DiscordMessageEvent
JRoy Jun 11, 2021
8ef49d3
Add developer documentation
JRoy Jun 11, 2021
aa05266
Bump JDA to 4.3.0
JRoy Jun 11, 2021
07d03a5
Merge branch '2.x' into module/discord
JRoy Jun 12, 2021
4898693
Merge branch '2.x' into module/discord
JRoy Jun 14, 2021
99a4b3a
Merge branch '2.x' into module/discord
JRoy Jun 18, 2021
e204522
Merge branch '2.x' into module/discord
JRoy Jun 26, 2021
4edd62e
Apply suggestions from code review
JRoy Jun 26, 2021
938c9f6
lul
JRoy Jun 27, 2021
de58a35
Improve indentation of config message variables
JRoy Jun 27, 2021
d60b8be
messages.properties changes
JRoy Jun 27, 2021
7a96843
Group mention changes
JRoy Jun 27, 2021
1f6bfbc
Rename EssentialsDiscordAPI to DiscordService
JRoy Jun 27, 2021
b596b70
Clarify InteractionEvent#reply javadoc
JRoy Jun 27, 2021
1c7bdb3
Add InteractionMember#getNickname
JRoy Jun 27, 2021
a95e8ce
Translations for message command
JRoy Jun 27, 2021
3a06039
Use crafthead over crafatar
JRoy Jun 27, 2021
f878989
Add DiscordService#sendMessage
JRoy Jun 27, 2021
74c73d5
Add DiscordService#registerMessageType
JRoy Jun 27, 2021
9ba4410
Allow for console command relay to be configured without restarting
JRoy Jun 27, 2021
474d9d4
Improve shutdown logic
JRoy Jun 27, 2021
242ed0c
Add TownyChat hook example
JRoy Jun 27, 2021
99fe047
md missed this :o
JRoy Jun 27, 2021
651d216
Add debug print for explicit-set check
JRoy Jun 27, 2021
9242e1a
Apply suggestions from code review
JRoy Jun 28, 2021
dd4411c
Pop message changes
JRoy Jun 28, 2021
25bdc8a
Fix regression in msg replies from 9fa1a4e596383d2c85c1947fcd95cddccc…
JRoy Jun 28, 2021
490839a
Add show-bot-messages & show-webhook-messages options
JRoy Jun 28, 2021
ea815a0
Merge remote-tracking branch 'upstream/module/discord' into module/di…
JRoy Jun 28, 2021
7592eb8
Add application id for clarity
JRoy Jun 28, 2021
7d98351
pepeW
JRoy Jun 28, 2021
6b8bad1
Fix component forwarding with DiscordCommandSender
JRoy Jun 28, 2021
567b980
Update EssentialsDiscord/src/main/java/net/essentialsx/api/v2/events/…
mdcfe Jun 29, 2021
1f99ed5
Apply suggestions from code review
JRoy Jun 29, 2021
0209e26
Validate message type key on constructor creation
JRoy Jun 29, 2021
17533c8
Merge remote-tracking branch 'upstream/module/discord' into module/di…
JRoy Jun 29, 2021
54d4876
Merge branch '2.x' into module/discord
JRoy Jun 29, 2021
dfa0ecd
Update tutorial link
JRoy Jul 1, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .checkstyle/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
<suppressions>
<suppress files=".*[\\/]test[\\/]java[\\/].*" checks="RequireExplicitVisibilityModifier"/>
<!-- TODO: don't suppress I-prefixed API interfaces under com.earth2me.essentials -->
<suppress files="(com[\\/]earth2me[\\/]essentials[\\/]|net[\\/]ess3[\\/])(?:[^\\/]+$|(?!api)[^\\/]+[\\/])" checks="MissingJavadoc(Method|Type)"/>
<suppress files="(com[\\/]earth2me[\\/]essentials[\\/]|net[\\/]ess3[\\/]|net[\\/]essentialsx[\\/])(?:[^\\/]+$|(?!api)[^\\/]+[\\/])" checks="MissingJavadoc(Method|Type)"/>
</suppressions>
1 change: 1 addition & 0 deletions .github/workflows/build-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
mv Essentials/build/docs/javadoc/ javadocs/
cp -r EssentialsAntiBuild/build/docs/javadoc/ javadocs/EssentialsAntiBuild/
cp -r EssentialsChat/build/docs/javadoc/ javadocs/EssentialsChat/
cp -r EssentialsDiscord/build/docs/javadoc/ javadocs/EssentialsDiscord/
cp -r EssentialsGeoIP/build/docs/javadoc/ javadocs/EssentialsGeoIP/
cp -r EssentialsProtect/build/docs/javadoc/ javadocs/EssentialsProtect/
cp -r EssentialsSpawn/build/docs/javadoc/ javadocs/EssentialsSpawn/
Expand Down
91 changes: 91 additions & 0 deletions Essentials/src/main/java/com/earth2me/essentials/Essentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.earth2me.essentials.commands.IEssentialsCommand;
import com.earth2me.essentials.commands.NoChargeException;
import com.earth2me.essentials.commands.NotEnoughArgumentsException;
import com.earth2me.essentials.commands.PlayerNotFoundException;
import com.earth2me.essentials.commands.QuietAbortException;
import com.earth2me.essentials.economy.EconomyLayers;
import com.earth2me.essentials.economy.vault.VaultEconomyProvider;
Expand All @@ -38,6 +39,7 @@
import com.earth2me.essentials.textreader.KeywordReplacer;
import com.earth2me.essentials.textreader.SimpleTextInput;
import com.earth2me.essentials.updatecheck.UpdateChecker;
import com.earth2me.essentials.utils.FormatUtil;
import com.earth2me.essentials.utils.VersionUtil;
import io.papermc.lib.PaperLib;
import net.ess3.api.Economy;
Expand Down Expand Up @@ -114,6 +116,7 @@
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
Expand Down Expand Up @@ -887,6 +890,94 @@ public User getOfflineUser(final String name) {
return user;
}

@Override
public User matchUser(final Server server, final User sourceUser, final String searchTerm, final Boolean getHidden, final boolean getOffline) throws PlayerNotFoundException {
final User user;
Player exPlayer;

try {
exPlayer = server.getPlayer(UUID.fromString(searchTerm));
} catch (final IllegalArgumentException ex) {
if (getOffline) {
exPlayer = server.getPlayerExact(searchTerm);
} else {
exPlayer = server.getPlayer(searchTerm);
}
}

if (exPlayer != null) {
user = getUser(exPlayer);
} else {
user = getUser(searchTerm);
}

if (user != null) {
if (!getOffline && !user.getBase().isOnline()) {
throw new PlayerNotFoundException();
}

if (getHidden || canInteractWith(sourceUser, user)) {
return user;
} else { // not looking for hidden and cannot interact (i.e is hidden)
if (getOffline && user.getName().equalsIgnoreCase(searchTerm)) { // if looking for offline and got an exact match
return user;
}
}
throw new PlayerNotFoundException();
}
final List<Player> matches = server.matchPlayer(searchTerm);

if (matches.isEmpty()) {
final String matchText = searchTerm.toLowerCase(Locale.ENGLISH);
for (final User userMatch : getOnlineUsers()) {
if (getHidden || canInteractWith(sourceUser, userMatch)) {
final String displayName = FormatUtil.stripFormat(userMatch.getDisplayName()).toLowerCase(Locale.ENGLISH);
if (displayName.contains(matchText)) {
return userMatch;
}
}
}
} else {
for (final Player player : matches) {
final User userMatch = getUser(player);
if (userMatch.getDisplayName().startsWith(searchTerm) && (getHidden || canInteractWith(sourceUser, userMatch))) {
return userMatch;
}
}
final User userMatch = getUser(matches.get(0));
if (getHidden || canInteractWith(sourceUser, userMatch)) {
return userMatch;
}
}
throw new PlayerNotFoundException();
}

@Override
public boolean canInteractWith(final CommandSource interactor, final User interactee) {
if (interactor == null) {
return !interactee.isHidden();
}

if (interactor.isPlayer()) {
return canInteractWith(getUser(interactor.getPlayer()), interactee);
}

return true; // console
}

@Override
public boolean canInteractWith(final User interactor, final User interactee) {
if (interactor == null) {
return !interactee.isHidden();
}

if (interactor.equals(interactee)) {
return true;
}

return interactor.getBase().canSee(interactee.getBase());
}

//This will create a new user if there is not a match.
@Override
public User getUser(final Player base) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,6 @@ public void run() {
user.setDisplayNick();
updateCompass(user);

ess.runTaskAsynchronously(() -> ess.getServer().getPluginManager().callEvent(new AsyncUserDataLoadEvent(user)));

if (!ess.getVanishedPlayersNew().isEmpty() && !user.isAuthorized("essentials.vanish.see")) {
for (final String p : ess.getVanishedPlayersNew()) {
final Player toVanish = ess.getServer().getPlayerExact(p);
Expand All @@ -325,12 +323,14 @@ public void run() {
user.getBase().setSleepingIgnored(true);
}

final String effectiveMessage;
if (ess.getSettings().allowSilentJoinQuit() && (user.isAuthorized("essentials.silentjoin") || user.isAuthorized("essentials.silentjoin.vanish"))) {
if (user.isAuthorized("essentials.silentjoin.vanish")) {
user.setVanished(true);
}
effectiveMessage = null;
} else if (message == null || hideJoinQuitMessages()) {
//NOOP
effectiveMessage = null;
} else if (ess.getSettings().isCustomJoinMessage()) {
final String msg = ess.getSettings().getCustomJoinMessage()
.replace("{PLAYER}", player.getDisplayName()).replace("{USERNAME}", player.getName())
Expand All @@ -340,10 +340,16 @@ public void run() {
if (!msg.isEmpty()) {
ess.getServer().broadcastMessage(msg);
}
effectiveMessage = msg.isEmpty() ? null : msg;
} else if (ess.getSettings().allowSilentJoinQuit()) {
ess.getServer().broadcastMessage(message);
effectiveMessage = message;
} else {
effectiveMessage = message;
}

ess.runTaskAsynchronously(() -> ess.getServer().getPluginManager().callEvent(new AsyncUserDataLoadEvent(user, effectiveMessage)));

final int motdDelay = ess.getSettings().getMotdDelay() / 50;
final DelayMotdTask motdTask = new DelayMotdTask(user);
if (motdDelay > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.earth2me.essentials.api.IJails;
import com.earth2me.essentials.api.IWarps;
import com.earth2me.essentials.commands.IEssentialsCommand;
import com.earth2me.essentials.commands.PlayerNotFoundException;
import com.earth2me.essentials.perm.PermissionsHandler;
import com.earth2me.essentials.updatecheck.UpdateChecker;
import net.ess3.provider.MaterialTagProvider;
Expand All @@ -15,6 +16,7 @@
import net.ess3.provider.SpawnerItemProvider;
import net.ess3.provider.SyncCommandsProvider;
import net.essentialsx.api.v2.services.BalanceTop;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -50,6 +52,12 @@ public interface IEssentials extends Plugin {

User getUser(Player base);

User matchUser(Server server, User sourceUser, String searchTerm, Boolean getHidden, boolean getOffline) throws PlayerNotFoundException;

boolean canInteractWith(CommandSource interactor, User interactee);

boolean canInteractWith(User interactor, User interactee);

I18n getI18n();

User getOfflineUser(String name);
Expand Down
86 changes: 86 additions & 0 deletions Essentials/src/main/java/com/earth2me/essentials/PlayerList.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.earth2me.essentials;

import com.earth2me.essentials.utils.FormatUtil;
import com.earth2me.essentials.utils.NumberUtil;
import org.bukkit.ChatColor;
import org.bukkit.Server;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -127,4 +129,88 @@ public static String outputFormat(final String group, final String message) {
return tl("listGroupTag", FormatUtil.replaceFormat(group)) +
message;
}

public static List<String> prepareGroupedList(final IEssentials ess, final String commandLabel, final Map<String, List<User>> playerList) {
final List<String> output = new ArrayList<>();

final Set<String> configGroups = ess.getSettings().getListGroupConfig().keySet();
final List<String> asterisk = new ArrayList<>();

// Loop through the custom defined groups and display them
for (final String oConfigGroup : configGroups) {
final String groupValue = ess.getSettings().getListGroupConfig().get(oConfigGroup).toString().trim();
final String configGroup = oConfigGroup.toLowerCase();

// If the group value is an asterisk, then skip it, and handle it later
if (groupValue.equals("*")) {
asterisk.add(oConfigGroup);
continue;
}

// If the group value is hidden, we don't need to display it
if (groupValue.equalsIgnoreCase("hidden")) {
playerList.remove(configGroup);
continue;
}

final List<User> outputUserList;
final List<User> matchedList = playerList.get(configGroup);

// If the group value is an int, then we might need to truncate it
if (NumberUtil.isInt(groupValue)) {
if (matchedList != null && !matchedList.isEmpty()) {
playerList.remove(configGroup);
outputUserList = new ArrayList<>(matchedList);
final int limit = Integer.parseInt(groupValue);
if (matchedList.size() > limit) {
output.add(outputFormat(oConfigGroup, tl("groupNumber", matchedList.size(), commandLabel, FormatUtil.stripFormat(configGroup))));
} else {
output.add(outputFormat(oConfigGroup, listUsers(ess, outputUserList, ", ")));
}
continue;
}
}

outputUserList = getMergedList(ess, playerList, configGroup);

// If we have no users, than we don't need to continue parsing this group
if (outputUserList.isEmpty()) {
continue;
}

output.add(outputFormat(oConfigGroup, listUsers(ess, outputUserList, ", ")));
}

final Set<String> var = playerList.keySet();
String[] onlineGroups = var.toArray(new String[0]);
Arrays.sort(onlineGroups, String.CASE_INSENSITIVE_ORDER);

// If we have an asterisk group, then merge all remaining groups
if (!asterisk.isEmpty()) {
final List<User> asteriskUsers = new ArrayList<>();
for (final String onlineGroup : onlineGroups) {
asteriskUsers.addAll(playerList.get(onlineGroup));
}
for (final String key : asterisk) {
playerList.put(key, asteriskUsers);
}
onlineGroups = asterisk.toArray(new String[0]);
}

// If we have any groups remaining after the custom groups loop through and display them
for (final String onlineGroup : onlineGroups) {
final List<User> users = playerList.get(onlineGroup);
String groupName = asterisk.isEmpty() ? users.get(0).getGroup() : onlineGroup;

if (ess.getPermissionsHandler().getName().equals("ConfigPermissions")) {
groupName = tl("connectedPlayers");
}
if (users == null || users.isEmpty()) {
continue;
}

output.add(outputFormat(groupName, listUsers(ess, users, ", ")));
}
return output;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,17 @@ public class Commandessentials extends EssentialsCommand {
"UltraPermissions",
"PermissionsEx", // permissions (unsupported)
"GroupManager", // permissions (unsupported)
"bPermissions" // permissions (unsupported)
"bPermissions", // permissions (unsupported)
"DiscordSRV" // potential for issues if EssentialsXDiscord is installed
);
private static final List<String> officialPlugins = Arrays.asList(
"EssentialsAntiBuild",
"EssentialsChat",
"EssentialsGeoIP",
"EssentialsProtect",
"EssentialsSpawn",
"EssentialsXMPP"
"EssentialsXMPP",
"EssentialsDiscord"
JRoy marked this conversation as resolved.
Show resolved Hide resolved
);
private static final List<String> warnPlugins = Arrays.asList(
"PermissionsEx",
Expand Down
Loading