Update to Discord4J v3.1.1

It wasn't as complicated as I expected
This commit is contained in:
Norbi Peti 2020-10-07 22:27:20 +02:00
parent 7cebb74835
commit 56d13ebf9f
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
28 changed files with 111 additions and 142 deletions

View file

@ -155,7 +155,7 @@
<dependency> <dependency>
<groupId>com.discord4j</groupId> <groupId>com.discord4j</groupId>
<artifactId>discord4j-core</artifactId> <artifactId>discord4j-core</artifactId>
<version>3.0.15</version> <version>3.1.1</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-jdk14 --> <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-jdk14 -->
<dependency> <dependency>
@ -217,11 +217,6 @@
<artifactId>mockito-core</artifactId> <artifactId>mockito-core</artifactId>
<version>3.5.13</version> <version>3.5.13</version>
</dependency> </dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>3.5.10</version>
</dependency>
</dependencies> </dependencies>
<profiles> <profiles>

View file

@ -2,7 +2,7 @@ package buttondevteam.discordplugin;
import buttondevteam.discordplugin.mcchat.MCChatUtils; import buttondevteam.discordplugin.mcchat.MCChatUtils;
import discord4j.core.object.entity.Message; import discord4j.core.object.entity.Message;
import discord4j.core.object.entity.MessageChannel; import discord4j.core.object.entity.channel.MessageChannel;
import lombok.Getter; import lombok.Getter;
import org.bukkit.scheduler.BukkitScheduler; import org.bukkit.scheduler.BukkitScheduler;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
@ -19,9 +19,8 @@ public class ChromaBot {
/** /**
* This will set the instance field. * This will set the instance field.
* *
* @param dp * @param dp The Discord plugin
* The Discord plugin
*/ */
ChromaBot(DiscordPlugin dp) { ChromaBot(DiscordPlugin dp) {
instance = this; instance = this;
@ -34,23 +33,22 @@ public class ChromaBot {
/** /**
* Send a message to the chat channels and private chats. * Send a message to the chat channels and private chats.
* *
* @param message * @param message The message to send, duh (use {@link MessageChannel#createMessage(String)})
* The message to send, duh (use {@link MessageChannel#createMessage(String)})
*/ */
public void sendMessage(Function<Mono<MessageChannel>, Mono<Message>> message) { public void sendMessage(Function<Mono<MessageChannel>, Mono<Message>> message) {
MCChatUtils.forAllMCChat(ch -> message.apply(ch).subscribe()); MCChatUtils.forAllMCChat(ch -> message.apply(ch).subscribe());
} }
/** /**
* Send a message to the chat channels, private chats and custom chats. * Send a message to the chat channels, private chats and custom chats.
* *
* @param message The message to send, duh * @param message The message to send, duh
* @param toggle The toggle type for channelcon * @param toggle The toggle type for channelcon
*/ */
public void sendMessageCustomAsWell(Function<Mono<MessageChannel>, Mono<Message>> message, @Nullable ChannelconBroadcast toggle) { public void sendMessageCustomAsWell(Function<Mono<MessageChannel>, Mono<Message>> message, @Nullable ChannelconBroadcast toggle) {
MCChatUtils.forCustomAndAllMCChat(ch -> message.apply(ch).subscribe(), toggle, false); MCChatUtils.forCustomAndAllMCChat(ch -> message.apply(ch).subscribe(), toggle, false);
} }
public void updatePlayerList() { public void updatePlayerList() {
MCChatUtils.updatePlayerList(); MCChatUtils.updatePlayerList();

View file

@ -5,11 +5,11 @@ import buttondevteam.lib.architecture.Component;
import buttondevteam.lib.architecture.ConfigData; import buttondevteam.lib.architecture.ConfigData;
import buttondevteam.lib.architecture.IHaveConfig; import buttondevteam.lib.architecture.IHaveConfig;
import buttondevteam.lib.architecture.ReadOnlyConfigData; import buttondevteam.lib.architecture.ReadOnlyConfigData;
import discord4j.common.util.Snowflake;
import discord4j.core.object.entity.Guild; import discord4j.core.object.entity.Guild;
import discord4j.core.object.entity.Message; import discord4j.core.object.entity.Message;
import discord4j.core.object.entity.MessageChannel;
import discord4j.core.object.entity.Role; import discord4j.core.object.entity.Role;
import discord4j.core.object.util.Snowflake; import discord4j.core.object.entity.channel.MessageChannel;
import discord4j.core.spec.EmbedCreateSpec; import discord4j.core.spec.EmbedCreateSpec;
import lombok.val; import lombok.val;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
@ -23,8 +23,8 @@ import java.util.regex.Pattern;
public final class DPUtils { public final class DPUtils {
public static final Pattern URL_PATTERN = Pattern.compile("https?://\\S*"); private static final Pattern URL_PATTERN = Pattern.compile("https?://\\S*");
public static final Pattern FORMAT_PATTERN = Pattern.compile("[*_~]"); private static final Pattern FORMAT_PATTERN = Pattern.compile("[*_~]");
public static EmbedCreateSpec embedWithHead(EmbedCreateSpec ecs, String displayname, String playername, String profileUrl) { public static EmbedCreateSpec embedWithHead(EmbedCreateSpec ecs, String displayname, String playername, String profileUrl) {
return ecs.setAuthor(displayname, profileUrl, "https://minotar.net/avatar/" + playername + "/32.png"); return ecs.setAuthor(displayname, profileUrl, "https://minotar.net/avatar/" + playername + "/32.png");

View file

@ -3,8 +3,8 @@ package buttondevteam.discordplugin;
import buttondevteam.discordplugin.mcchat.MinecraftChatModule; import buttondevteam.discordplugin.mcchat.MinecraftChatModule;
import buttondevteam.discordplugin.playerfaker.DiscordInventory; import buttondevteam.discordplugin.playerfaker.DiscordInventory;
import buttondevteam.discordplugin.playerfaker.VCMDWrapper; import buttondevteam.discordplugin.playerfaker.VCMDWrapper;
import discord4j.core.object.entity.MessageChannel;
import discord4j.core.object.entity.User; import discord4j.core.object.entity.User;
import discord4j.core.object.entity.channel.MessageChannel;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import lombok.experimental.Delegate; import lombok.experimental.Delegate;
@ -161,6 +161,7 @@ public abstract class DiscordConnectedPlayer extends DiscordSenderBase implement
} }
@Override @Override
@Deprecated
public double getMaxHealth() { public double getMaxHealth() {
return 20; return 20;
} }

View file

@ -2,8 +2,8 @@ package buttondevteam.discordplugin;
import buttondevteam.discordplugin.mcchat.MinecraftChatModule; import buttondevteam.discordplugin.mcchat.MinecraftChatModule;
import buttondevteam.discordplugin.playerfaker.VCMDWrapper; import buttondevteam.discordplugin.playerfaker.VCMDWrapper;
import discord4j.core.object.entity.MessageChannel;
import discord4j.core.object.entity.User; import discord4j.core.object.entity.User;
import discord4j.core.object.entity.channel.MessageChannel;
import lombok.Getter; import lombok.Getter;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.mockito.Mockito; import org.mockito.Mockito;

View file

@ -19,8 +19,9 @@ import buttondevteam.lib.architecture.ConfigData;
import buttondevteam.lib.architecture.IHaveConfig; import buttondevteam.lib.architecture.IHaveConfig;
import buttondevteam.lib.player.ChromaGamerBase; import buttondevteam.lib.player.ChromaGamerBase;
import com.google.common.io.Files; import com.google.common.io.Files;
import discord4j.core.DiscordClient; import discord4j.common.util.Snowflake;
import discord4j.core.DiscordClientBuilder; import discord4j.core.DiscordClientBuilder;
import discord4j.core.GatewayDiscordClient;
import discord4j.core.event.domain.guild.GuildCreateEvent; import discord4j.core.event.domain.guild.GuildCreateEvent;
import discord4j.core.event.domain.lifecycle.ReadyEvent; import discord4j.core.event.domain.lifecycle.ReadyEvent;
import discord4j.core.object.entity.Guild; import discord4j.core.object.entity.Guild;
@ -28,7 +29,7 @@ import discord4j.core.object.entity.Role;
import discord4j.core.object.presence.Activity; import discord4j.core.object.presence.Activity;
import discord4j.core.object.presence.Presence; import discord4j.core.object.presence.Presence;
import discord4j.core.object.reaction.ReactionEmoji; import discord4j.core.object.reaction.ReactionEmoji;
import discord4j.core.object.util.Snowflake; import discord4j.rest.util.Color;
import discord4j.store.jdk.JdkStoreService; import discord4j.store.jdk.JdkStoreService;
import lombok.Getter; import lombok.Getter;
import lombok.val; import lombok.val;
@ -38,7 +39,6 @@ import org.bukkit.entity.Player;
import org.mockito.internal.util.MockUtil; import org.mockito.internal.util.MockUtil;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import java.awt.*;
import java.io.File; import java.io.File;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
@ -47,7 +47,7 @@ import java.util.stream.Collectors;
@ButtonPlugin.ConfigOpts(disableConfigGen = true) @ButtonPlugin.ConfigOpts(disableConfigGen = true)
public class DiscordPlugin extends ButtonPlugin { public class DiscordPlugin extends ButtonPlugin {
public static DiscordClient dc; public static GatewayDiscordClient dc;
public static DiscordPlugin plugin; public static DiscordPlugin plugin;
public static boolean SafeMode = true; public static boolean SafeMode = true;
@Getter @Getter
@ -138,19 +138,18 @@ public class DiscordPlugin extends ButtonPlugin {
return; return;
} }
} }
val cb = DiscordClientBuilder.create(token); val cb = DiscordClientBuilder.create(token).build().gateway();
cb.setInitialPresence(Presence.doNotDisturb(Activity.playing("booting"))); cb.setInitialStatus(si -> Presence.doNotDisturb(Activity.playing("booting")));
cb.setStoreService(new JdkStoreService()); //The default doesn't work for some reason - it's waaay faster now cb.setStoreService(new JdkStoreService()); //The default doesn't work for some reason - it's waaay faster now
dc = cb.build(); cb.login().subscribe(dc -> {
dc.getEventDispatcher().on(ReadyEvent.class) // Listen for ReadyEvent(s) DiscordPlugin.dc = dc; //Set to gateway client
.map(event -> event.getGuilds().size()) // Get how many guilds the bot is in dc.on(ReadyEvent.class) // Listen for ReadyEvent(s)
.flatMap(size -> dc.getEventDispatcher() .map(event -> event.getGuilds().size()) // Get how many guilds the bot is in
.on(GuildCreateEvent.class) // Listen for GuildCreateEvent(s) .flatMap(size -> dc
.take(size) // Take only the first `size` GuildCreateEvent(s) to be received .on(GuildCreateEvent.class) // Listen for GuildCreateEvent(s)
.collectList()) // Take all received GuildCreateEvents and make it a List .take(size) // Take only the first `size` GuildCreateEvent(s) to be received
.subscribe(this::handleReady); /* All guilds have been received, client is fully connected */ .collectList()).subscribe(this::handleReady); // Take all received GuildCreateEvents and make it a List
//dc.getEventDispatcher().on(DisconnectEvent.class); }); /* All guilds have been received, client is fully connected */
dc.login().subscribe();
} catch (Exception e) { } catch (Exception e) {
TBMCCoreAPI.SendException("Failed to enable the Discord plugin!", e); TBMCCoreAPI.SendException("Failed to enable the Discord plugin!", e);
getLogger().severe("You may be able to reset the plugin using /discord reset"); getLogger().severe("You may be able to reset the plugin using /discord reset");
@ -170,9 +169,8 @@ public class DiscordPlugin extends ButtonPlugin {
if (mainServer == null) { if (mainServer == null) {
if (event.size() == 0) { if (event.size() == 0) {
getLogger().severe("Main server not found! Invite the bot and do /discord reset"); getLogger().severe("Main server not found! Invite the bot and do /discord reset");
dc.getApplicationInfo().subscribe(info -> { dc.getApplicationInfo().subscribe(info ->
getLogger().severe("Click here: https://discordapp.com/oauth2/authorize?client_id=" + info.getId().asString() + "&scope=bot&permissions=268509264"); getLogger().severe("Click here: https://discordapp.com/oauth2/authorize?client_id=" + info.getId().asString() + "&scope=bot&permissions=268509264"));
});
saveConfig(); //Put default there saveConfig(); //Put default there
return; //We should have all guilds by now, no need to retry return; //We should have all guilds by now, no need to retry
} }

View file

@ -1,8 +1,8 @@
package buttondevteam.discordplugin; package buttondevteam.discordplugin;
import discord4j.core.object.entity.Member; import discord4j.core.object.entity.Member;
import discord4j.core.object.entity.MessageChannel;
import discord4j.core.object.entity.User; import discord4j.core.object.entity.User;
import discord4j.core.object.entity.channel.MessageChannel;
import lombok.val; import lombok.val;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Server; import org.bukkit.Server;

View file

@ -1,8 +1,8 @@
package buttondevteam.discordplugin; package buttondevteam.discordplugin;
import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.TBMCCoreAPI;
import discord4j.core.object.entity.MessageChannel;
import discord4j.core.object.entity.User; import discord4j.core.object.entity.User;
import discord4j.core.object.entity.channel.MessageChannel;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
@ -24,7 +24,7 @@ public abstract class DiscordSenderBase implements CommandSender {
/** /**
* Returns the user. May be null. * Returns the user. May be null.
* *
* @return The user or null. * @return The user or null.
*/ */
public User getUser() { public User getUser() {
@ -58,7 +58,7 @@ public abstract class DiscordSenderBase implements CommandSender {
msgtosend += "\n" + sendmsg; msgtosend += "\n" + sendmsg;
if (sendtask == null) if (sendtask == null)
sendtask = Bukkit.getScheduler().runTaskLaterAsynchronously(DiscordPlugin.plugin, () -> { sendtask = Bukkit.getScheduler().runTaskLaterAsynchronously(DiscordPlugin.plugin, () -> {
channel.createMessage((user != null ? user.getMention() + "\n":"") + msgtosend.trim()).subscribe(); channel.createMessage((user != null ? user.getMention() + "\n" : "") + msgtosend.trim()).subscribe();
sendtask = null; sendtask = null;
msgtosend = ""; msgtosend = "";
}, 4); // Waits a 0.2 second to gather all/most of the different messages }, 4); // Waits a 0.2 second to gather all/most of the different messages

View file

@ -14,7 +14,7 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import discord4j.core.object.entity.Message; import discord4j.core.object.entity.Message;
import discord4j.core.object.entity.MessageChannel; import discord4j.core.object.entity.channel.MessageChannel;
import lombok.val; import lombok.val;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
@ -34,14 +34,14 @@ public class AnnouncerModule extends Component<DiscordPlugin> {
/** /**
* Channel where distinguished (moderator) posts go. * Channel where distinguished (moderator) posts go.
*/ */
public ReadOnlyConfigData<Mono<MessageChannel>> modChannel() { private ReadOnlyConfigData<Mono<MessageChannel>> modChannel() {
return DPUtils.channelData(getConfig(), "modChannel"); return DPUtils.channelData(getConfig(), "modChannel");
} }
/** /**
* Automatically unpins all messages except the last few. Set to 0 or >50 to disable * Automatically unpins all messages except the last few. Set to 0 or >50 to disable
*/ */
public ConfigData<Short> keepPinned() { private ConfigData<Short> keepPinned() {
return getConfig().getData("keepPinned", (short) 40); return getConfig().getData("keepPinned", (short) 40);
} }

View file

@ -91,11 +91,7 @@ public class PlayerListWatcher {
if (fHandle == null) { if (fHandle == null) {
assert lookupConstructor != null; assert lookupConstructor != null;
var lookup = lookupConstructor.newInstance(mock.getClass()); var lookup = lookupConstructor.newInstance(mock.getClass());
//var mcl = method.getDeclaringClass();
fHandle = lookup.unreflectSpecial(method, mock.getClass()); //Special: super.method() fHandle = lookup.unreflectSpecial(method, mock.getClass()); //Special: super.method()
/*if (mcl.getSimpleName().contains("Mock")) //inline mock
lookup.findSpecial(mcl, method.getName(), )
fHandle.type()*/
} }
return fHandle.invoke(mock, invocation.getArgument(0)); //Invoke with our instance, so it passes that to advancement data, we have the fields as well return fHandle.invoke(mock, invocation.getArgument(0)); //Invoke with our instance, so it passes that to advancement data, we have the fields as well
} }

View file

@ -28,8 +28,8 @@ public class UserinfoCommand extends ICommand2DC {
if (user == null || user.length() == 0) if (user == null || user.length() == 0)
target = message.getAuthor().orElse(null); target = message.getAuthor().orElse(null);
else { else {
@SuppressWarnings("OptionalGetWithoutIsPresent") final User firstmention = message.getUserMentions() final User firstmention = message.getUserMentions()
.filter(m -> !m.getId().asString().equals(DiscordPlugin.dc.getSelfId().get().asString())).blockFirst(); .filter(m -> !m.getId().asString().equals(DiscordPlugin.dc.getSelfId().asString())).blockFirst();
if (firstmention != null) if (firstmention != null)
target = firstmention; target = firstmention;
else if (user.contains("#")) { else if (user.contains("#")) {

View file

@ -3,7 +3,7 @@ package buttondevteam.discordplugin.exceptions;
import buttondevteam.core.ComponentManager; import buttondevteam.core.ComponentManager;
import buttondevteam.discordplugin.DiscordPlugin; import buttondevteam.discordplugin.DiscordPlugin;
import buttondevteam.lib.TBMCDebugMessageEvent; import buttondevteam.lib.TBMCDebugMessageEvent;
import discord4j.core.object.entity.MessageChannel; import discord4j.core.object.entity.channel.MessageChannel;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;

View file

@ -9,9 +9,9 @@ import buttondevteam.lib.architecture.Component;
import buttondevteam.lib.architecture.ConfigData; import buttondevteam.lib.architecture.ConfigData;
import buttondevteam.lib.architecture.ReadOnlyConfigData; import buttondevteam.lib.architecture.ReadOnlyConfigData;
import discord4j.core.object.entity.Guild; import discord4j.core.object.entity.Guild;
import discord4j.core.object.entity.GuildChannel;
import discord4j.core.object.entity.MessageChannel;
import discord4j.core.object.entity.Role; import discord4j.core.object.entity.Role;
import discord4j.core.object.entity.channel.GuildChannel;
import discord4j.core.object.entity.channel.MessageChannel;
import org.apache.commons.lang.exception.ExceptionUtils; import org.apache.commons.lang.exception.ExceptionUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -27,8 +27,8 @@ import java.util.stream.Collectors;
* Listens for errors from the Chroma plugins and posts them to Discord, ignoring repeating errors so it's not that spammy. * Listens for errors from the Chroma plugins and posts them to Discord, ignoring repeating errors so it's not that spammy.
*/ */
public class ExceptionListenerModule extends Component<DiscordPlugin> implements Listener { public class ExceptionListenerModule extends Component<DiscordPlugin> implements Listener {
private List<Throwable> lastthrown = new ArrayList<>(); private final List<Throwable> lastthrown = new ArrayList<>();
private List<String> lastsourcemsg = new ArrayList<>(); private final List<String> lastsourcemsg = new ArrayList<>();
@EventHandler @EventHandler
public void onException(TBMCExceptionEvent e) { public void onException(TBMCExceptionEvent e) {

View file

@ -9,7 +9,12 @@ import buttondevteam.lib.architecture.ConfigData;
import buttondevteam.lib.architecture.ReadOnlyConfigData; import buttondevteam.lib.architecture.ReadOnlyConfigData;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import discord4j.core.event.domain.PresenceUpdateEvent; import discord4j.core.event.domain.PresenceUpdateEvent;
import discord4j.core.object.entity.*; import discord4j.core.object.entity.Guild;
import discord4j.core.object.entity.Member;
import discord4j.core.object.entity.Message;
import discord4j.core.object.entity.Role;
import discord4j.core.object.entity.channel.GuildChannel;
import discord4j.core.object.entity.channel.MessageChannel;
import discord4j.core.object.presence.Status; import discord4j.core.object.presence.Status;
import lombok.val; import lombok.val;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -89,7 +94,7 @@ public class FunModule extends Component<DiscordPlugin> implements Listener {
public static boolean executeMemes(Message message) { public static boolean executeMemes(Message message) {
val fm = ComponentManager.getIfEnabled(FunModule.class); val fm = ComponentManager.getIfEnabled(FunModule.class);
if (fm == null) return false; if (fm == null) return false;
String msglowercased = message.getContent().orElse("").toLowerCase(); String msglowercased = message.getContent().toLowerCase();
lastlist++; lastlist++;
if (lastlist > 5) { if (lastlist > 5) {
ListC = 0; ListC = 0;

View file

@ -6,9 +6,9 @@ import buttondevteam.discordplugin.commands.Command2DCSender;
import buttondevteam.discordplugin.util.Timings; import buttondevteam.discordplugin.util.Timings;
import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.TBMCCoreAPI;
import discord4j.core.object.entity.Message; import discord4j.core.object.entity.Message;
import discord4j.core.object.entity.MessageChannel;
import discord4j.core.object.entity.PrivateChannel;
import discord4j.core.object.entity.Role; import discord4j.core.object.entity.Role;
import discord4j.core.object.entity.channel.MessageChannel;
import discord4j.core.object.entity.channel.PrivateChannel;
import lombok.val; import lombok.val;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
@ -25,9 +25,9 @@ public class CommandListener {
public static Mono<Boolean> runCommand(Message message, MessageChannel commandChannel, boolean mentionedonly) { public static Mono<Boolean> runCommand(Message message, MessageChannel commandChannel, boolean mentionedonly) {
Timings timings = CommonListeners.timings; Timings timings = CommonListeners.timings;
Mono<Boolean> ret = Mono.just(true); Mono<Boolean> ret = Mono.just(true);
if (!message.getContent().isPresent()) if (message.getContent().length() == 0)
return ret; //Pin messages and such, let the mcchat listener deal with it return ret; //Pin messages and such, let the mcchat listener deal with it
val content = message.getContent().get(); val content = message.getContent();
timings.printElapsed("A"); timings.printElapsed("A");
return message.getChannel().flatMap(channel -> { return message.getChannel().flatMap(channel -> {
Mono<?> tmp = ret; Mono<?> tmp = ret;
@ -74,7 +74,7 @@ public class CommandListener {
private static boolean checkanddeletemention(StringBuilder cmdwithargs, String mention, Message message) { private static boolean checkanddeletemention(StringBuilder cmdwithargs, String mention, Message message) {
final char prefix = DiscordPlugin.getPrefix(); final char prefix = DiscordPlugin.getPrefix();
if (message.getContent().orElse("").startsWith(mention)) // TODO: Resolve mentions: Compound arguments, either a mention or text if (message.getContent().startsWith(mention)) // TODO: Resolve mentions: Compound arguments, either a mention or text
if (cmdwithargs.length() > mention.length() + 1) { if (cmdwithargs.length() > mention.length() + 1) {
int i = cmdwithargs.indexOf(" ", mention.length()); int i = cmdwithargs.indexOf(" ", mention.length());
if (i == -1) if (i == -1)
@ -89,7 +89,7 @@ public class CommandListener {
cmdwithargs.replace(0, cmdwithargs.length(), prefix + "help"); cmdwithargs.replace(0, cmdwithargs.length(), prefix + "help");
else { else {
if (cmdwithargs.length() == 0) if (cmdwithargs.length() == 0)
cmdwithargs.replace(0, cmdwithargs.length(), prefix + "help"); cmdwithargs.replace(0, 0, prefix + "help");
else if (cmdwithargs.charAt(0) != prefix) else if (cmdwithargs.charAt(0) != prefix)
cmdwithargs.insert(0, prefix); cmdwithargs.insert(0, prefix);
return false; //Don't treat / as mention, mentions can be used in public mcchat return false; //Don't treat / as mention, mentions can be used in public mcchat

View file

@ -14,7 +14,7 @@ import discord4j.core.event.domain.message.MessageCreateEvent;
import discord4j.core.event.domain.role.RoleCreateEvent; import discord4j.core.event.domain.role.RoleCreateEvent;
import discord4j.core.event.domain.role.RoleDeleteEvent; import discord4j.core.event.domain.role.RoleDeleteEvent;
import discord4j.core.event.domain.role.RoleUpdateEvent; import discord4j.core.event.domain.role.RoleUpdateEvent;
import discord4j.core.object.entity.PrivateChannel; import discord4j.core.object.entity.channel.PrivateChannel;
import lombok.val; import lombok.val;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
@ -47,7 +47,7 @@ public class CommonListeners {
return commandCh.filterWhen(ch -> event.getMessage().getChannel().map(mch -> return commandCh.filterWhen(ch -> event.getMessage().getChannel().map(mch ->
(commandChannel != null && mch.getId().asLong() == commandChannel.asLong()) //If mentioned, that's higher than chat (commandChannel != null && mch.getId().asLong() == commandChannel.asLong()) //If mentioned, that's higher than chat
|| mch instanceof PrivateChannel || mch instanceof PrivateChannel
|| event.getMessage().getContent().orElse("").contains("channelcon")) //Only 'channelcon' is allowed in other channels || event.getMessage().getContent().contains("channelcon")) //Only 'channelcon' is allowed in other channels
.flatMap(shouldRun -> { //Only continue if this doesn't handle the event .flatMap(shouldRun -> { //Only continue if this doesn't handle the event
if (!shouldRun) if (!shouldRun)
return Mono.just(true); //The condition is only for the first command execution, not mcchat return Mono.just(true); //The condition is only for the first command execution, not mcchat

View file

@ -6,13 +6,12 @@ import buttondevteam.discordplugin.commands.ConnectCommand;
import buttondevteam.lib.TBMCCommandPreprocessEvent; import buttondevteam.lib.TBMCCommandPreprocessEvent;
import buttondevteam.lib.player.TBMCPlayerGetInfoEvent; import buttondevteam.lib.player.TBMCPlayerGetInfoEvent;
import buttondevteam.lib.player.TBMCPlayerJoinEvent; import buttondevteam.lib.player.TBMCPlayerJoinEvent;
import discord4j.common.util.Snowflake;
import discord4j.core.object.entity.Member; import discord4j.core.object.entity.Member;
import discord4j.core.object.entity.User; import discord4j.core.object.entity.User;
import discord4j.core.object.util.Snowflake;
import lombok.val; import lombok.val;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.server.ServerCommandEvent;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
public class MCListener implements Listener { public class MCListener implements Listener {
@ -53,7 +52,7 @@ public class MCListener implements Listener {
} }
@EventHandler @EventHandler
public void onCommandPreprocess(TBMCCommandPreprocessEvent e){ public void onCommandPreprocess(TBMCCommandPreprocessEvent e) {
DiscordPlugin.Restart = !e.getMessage().equalsIgnoreCase("/stop"); // The variable is always true except if stopped DiscordPlugin.Restart = !e.getMessage().equalsIgnoreCase("/stop"); // The variable is always true except if stopped
} }
} }

View file

@ -9,11 +9,11 @@ import buttondevteam.lib.TBMCSystemChatEvent;
import buttondevteam.lib.chat.Command2; import buttondevteam.lib.chat.Command2;
import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.player.TBMCPlayer; import buttondevteam.lib.player.TBMCPlayer;
import discord4j.core.object.entity.GuildChannel;
import discord4j.core.object.entity.Message; import discord4j.core.object.entity.Message;
import discord4j.core.object.entity.MessageChannel;
import discord4j.core.object.entity.User; import discord4j.core.object.entity.User;
import discord4j.core.object.util.Permission; import discord4j.core.object.entity.channel.GuildChannel;
import discord4j.core.object.entity.channel.MessageChannel;
import discord4j.rest.util.Permission;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.val; import lombok.val;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -149,6 +149,7 @@ public class ChannelconCommand extends ICommand2DC {
DPUtils.reply(message, channel, "you can only use this command in a server!").subscribe(); DPUtils.reply(message, channel, "you can only use this command in a server!").subscribe();
return true; return true;
} }
//noinspection OptionalGetWithoutIsPresent
var perms = ((GuildChannel) channel).getEffectivePermissions(message.getAuthor().map(User::getId).get()).block(); var perms = ((GuildChannel) channel).getEffectivePermissions(message.getAuthor().map(User::getId).get()).block();
if (!perms.contains(Permission.ADMINISTRATOR) && !perms.contains(Permission.MANAGE_CHANNELS)) { if (!perms.contains(Permission.ADMINISTRATOR) && !perms.contains(Permission.MANAGE_CHANNELS)) {
DPUtils.reply(message, channel, "you need to have manage permissions for this channel!").subscribe(); DPUtils.reply(message, channel, "you need to have manage permissions for this channel!").subscribe();

View file

@ -8,7 +8,7 @@ import buttondevteam.discordplugin.commands.ICommand2DC;
import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.chat.Command2; import buttondevteam.lib.chat.Command2;
import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.CommandClass;
import discord4j.core.object.entity.PrivateChannel; import discord4j.core.object.entity.channel.PrivateChannel;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.val; import lombok.val;

View file

@ -4,9 +4,9 @@ import buttondevteam.core.component.channel.Channel;
import buttondevteam.core.component.channel.ChatRoom; import buttondevteam.core.component.channel.ChatRoom;
import buttondevteam.discordplugin.DiscordConnectedPlayer; import buttondevteam.discordplugin.DiscordConnectedPlayer;
import buttondevteam.lib.TBMCSystemChatEvent; import buttondevteam.lib.TBMCSystemChatEvent;
import discord4j.core.object.entity.MessageChannel; import discord4j.common.util.Snowflake;
import discord4j.core.object.entity.User; import discord4j.core.object.entity.User;
import discord4j.core.object.util.Snowflake; import discord4j.core.object.entity.channel.MessageChannel;
import lombok.NonNull; import lombok.NonNull;
import lombok.val; import lombok.val;
@ -62,7 +62,7 @@ public class MCChatCustom {
public Set<TBMCSystemChatEvent.BroadcastTarget> brtoggles; public Set<TBMCSystemChatEvent.BroadcastTarget> brtoggles;
private CustomLMD(@NonNull MessageChannel channel, @NonNull User user, private CustomLMD(@NonNull MessageChannel channel, @NonNull User user,
@NonNull String groupid, @NonNull Channel mcchannel, @NonNull DiscordConnectedPlayer dcp, int toggles, Set<TBMCSystemChatEvent.BroadcastTarget> brtoggles) { @NonNull String groupid, @NonNull Channel mcchannel, @NonNull DiscordConnectedPlayer dcp, int toggles, Set<TBMCSystemChatEvent.BroadcastTarget> brtoggles) {
super(channel, user); super(channel, user);
groupID = groupid; groupID = groupid;
this.mcchannel = mcchannel; this.mcchannel = mcchannel;

View file

@ -13,11 +13,17 @@ import buttondevteam.lib.chat.ChatMessage;
import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.chat.TBMCChatAPI;
import buttondevteam.lib.player.TBMCPlayer; import buttondevteam.lib.player.TBMCPlayer;
import com.vdurmont.emoji.EmojiParser; import com.vdurmont.emoji.EmojiParser;
import discord4j.common.util.Snowflake;
import discord4j.core.event.domain.message.MessageCreateEvent; import discord4j.core.event.domain.message.MessageCreateEvent;
import discord4j.core.object.Embed; import discord4j.core.object.Embed;
import discord4j.core.object.entity.*; import discord4j.core.object.entity.Attachment;
import discord4j.core.object.util.Snowflake; import discord4j.core.object.entity.Guild;
import discord4j.core.object.entity.Message;
import discord4j.core.object.entity.User;
import discord4j.core.object.entity.channel.GuildChannel;
import discord4j.core.object.entity.channel.PrivateChannel;
import discord4j.core.spec.EmbedCreateSpec; import discord4j.core.spec.EmbedCreateSpec;
import discord4j.rest.util.Color;
import lombok.val; import lombok.val;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -26,7 +32,6 @@ import org.bukkit.event.Listener;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import java.awt.*;
import java.time.Instant; import java.time.Instant;
import java.util.AbstractMap; import java.util.AbstractMap;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
@ -72,11 +77,11 @@ public class MCChatListener implements Listener {
time = se.getValue(); time = se.getValue();
final String authorPlayer = "[" + DPUtils.sanitizeStringNoEscape(e.getChannel().DisplayName().get()) + "] " // final String authorPlayer = "[" + DPUtils.sanitizeStringNoEscape(e.getChannel().DisplayName().get()) + "] " //
+ ("Minecraft".equals(e.getOrigin()) ? "" : "[" + e.getOrigin().substring(0, 1) + "]") // + ("Minecraft".equals(e.getOrigin()) ? "" : "[" + e.getOrigin().charAt(0) + "]") //
+ (DPUtils.sanitizeStringNoEscape(ChromaUtils.getDisplayName(e.getSender()))); + (DPUtils.sanitizeStringNoEscape(ChromaUtils.getDisplayName(e.getSender())));
val color = e.getChannel().Color().get(); val color = e.getChannel().Color().get();
final Consumer<EmbedCreateSpec> embed = ecs -> { final Consumer<EmbedCreateSpec> embed = ecs -> {
ecs.setDescription(e.getMessage()).setColor(new Color(color.getRed(), ecs.setDescription(e.getMessage()).setColor(Color.of(color.getRed(),
color.getGreen(), color.getBlue())); color.getGreen(), color.getBlue()));
String url = module.profileURL().get(); String url = module.profileURL().get();
if (e.getSender() instanceof Player) if (e.getSender() instanceof Player)
@ -235,9 +240,8 @@ public class MCChatListener implements Listener {
}).filter(channel -> { }).filter(channel -> {
timings.printElapsed("Filter 2"); timings.printElapsed("Filter 2");
return !(channel instanceof PrivateChannel //Only in private chat return !(channel instanceof PrivateChannel //Only in private chat
&& ev.getMessage().getContent().isPresent() && ev.getMessage().getContent().length() < "/mcchat<>".length()
&& ev.getMessage().getContent().get().length() < "/mcchat<>".length() && ev.getMessage().getContent().replace(prefix + "", "")
&& ev.getMessage().getContent().get().replace(prefix + "", "")
.equalsIgnoreCase("mcchat")); //Either mcchat or /mcchat .equalsIgnoreCase("mcchat")); //Either mcchat or /mcchat
//Allow disabling the chat if needed //Allow disabling the chat if needed
}).filterWhen(channel -> CommandListener.runCommand(ev.getMessage(), channel, true)) }).filterWhen(channel -> CommandListener.runCommand(ev.getMessage(), channel, true))
@ -268,7 +272,7 @@ public class MCChatListener implements Listener {
return; return;
} }
val sender = event.getMessage().getAuthor().orElse(null); val sender = event.getMessage().getAuthor().orElse(null);
String dmessage = event.getMessage().getContent().orElse(""); String dmessage = event.getMessage().getContent();
try { try {
final DiscordSenderBase dsender = MCChatUtils.getSender(event.getMessage().getChannelId(), sender); final DiscordSenderBase dsender = MCChatUtils.getSender(event.getMessage().getChannelId(), sender);
val user = dsender.getChromaUser(); val user = dsender.getChromaUser();

View file

@ -4,9 +4,9 @@ import buttondevteam.core.ComponentManager;
import buttondevteam.discordplugin.DiscordConnectedPlayer; import buttondevteam.discordplugin.DiscordConnectedPlayer;
import buttondevteam.discordplugin.DiscordPlayer; import buttondevteam.discordplugin.DiscordPlayer;
import buttondevteam.lib.player.TBMCPlayer; import buttondevteam.lib.player.TBMCPlayer;
import discord4j.core.object.entity.MessageChannel;
import discord4j.core.object.entity.PrivateChannel;
import discord4j.core.object.entity.User; import discord4j.core.object.entity.User;
import discord4j.core.object.entity.channel.MessageChannel;
import discord4j.core.object.entity.channel.PrivateChannel;
import lombok.val; import lombok.val;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;

View file

@ -7,8 +7,13 @@ import buttondevteam.discordplugin.broadcaster.GeneralEventBroadcasterModule;
import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.TBMCSystemChatEvent; import buttondevteam.lib.TBMCSystemChatEvent;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import discord4j.core.object.entity.*; import discord4j.common.util.Snowflake;
import discord4j.core.object.util.Snowflake; import discord4j.core.object.entity.Message;
import discord4j.core.object.entity.User;
import discord4j.core.object.entity.channel.Channel;
import discord4j.core.object.entity.channel.MessageChannel;
import discord4j.core.object.entity.channel.PrivateChannel;
import discord4j.core.object.entity.channel.TextChannel;
import io.netty.util.collection.LongObjectHashMap; import io.netty.util.collection.LongObjectHashMap;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.val; import lombok.val;

View file

@ -7,8 +7,8 @@ import buttondevteam.lib.player.TBMCPlayer;
import buttondevteam.lib.player.TBMCPlayerBase; import buttondevteam.lib.player.TBMCPlayerBase;
import buttondevteam.lib.player.TBMCYEEHAWEvent; import buttondevteam.lib.player.TBMCYEEHAWEvent;
import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.CommandSource;
import discord4j.common.util.Snowflake;
import discord4j.core.object.entity.Role; import discord4j.core.object.entity.Role;
import discord4j.core.object.util.Snowflake;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.val; import lombok.val;
import net.ess3.api.events.AfkStatusChangeEvent; import net.ess3.api.events.AfkStatusChangeEvent;

View file

@ -13,8 +13,8 @@ import buttondevteam.lib.architecture.Component;
import buttondevteam.lib.architecture.ConfigData; import buttondevteam.lib.architecture.ConfigData;
import buttondevteam.lib.architecture.ReadOnlyConfigData; import buttondevteam.lib.architecture.ReadOnlyConfigData;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import discord4j.core.object.entity.MessageChannel; import discord4j.common.util.Snowflake;
import discord4j.core.object.util.Snowflake; import discord4j.core.object.entity.channel.MessageChannel;
import lombok.Getter; import lombok.Getter;
import lombok.val; import lombok.val;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -116,17 +116,15 @@ public class MinecraftChatModule extends Component<DiscordPlugin> {
} }
/** /**
* Whether players logged on from Discord should be recognised by other plugins. Some plugins might break if it's turned off. * Whether players logged on from Discord (mcchat command) should be recognised by other plugins. Some plugins might break if it's turned off.
* But it's really hacky. * But it's really hacky.
*/ */
public final ConfigData<Boolean> addFakePlayersToBukkit = getConfig().getData("addFakePlayersToBukkit", true); private final ConfigData<Boolean> addFakePlayersToBukkit = getConfig().getData("addFakePlayersToBukkit", true);
@Override @Override
protected void enable() { protected void enable() {
if (DPUtils.disableIfConfigErrorRes(this, chatChannel(), chatChannelMono())) if (DPUtils.disableIfConfigErrorRes(this, chatChannel(), chatChannelMono()))
return; return;
/*clientID = DiscordPlugin.dc.getApplicationInfo().blockOptional().map(info->info.getId().asString())
.orElse("Unknown"); //Need to block because otherwise it may not be set in time*/
listener = new MCChatListener(this); listener = new MCChatListener(this);
TBMCCoreAPI.RegisterEventsForExceptions(listener, getPlugin()); TBMCCoreAPI.RegisterEventsForExceptions(listener, getPlugin());
TBMCCoreAPI.RegisterEventsForExceptions(new MCListener(this), getPlugin());//These get undone if restarting/resetting - it will ignore events if disabled TBMCCoreAPI.RegisterEventsForExceptions(new MCListener(this), getPlugin());//These get undone if restarting/resetting - it will ignore events if disabled

View file

@ -113,6 +113,7 @@ public class DiscordInventory implements Inventory {
} }
@Override @Override
@Deprecated
public HashMap<Integer, ? extends ItemStack> all(int materialId) { public HashMap<Integer, ? extends ItemStack> all(int materialId) {
return new HashMap<>(); return new HashMap<>();
} }
@ -128,6 +129,7 @@ public class DiscordInventory implements Inventory {
} }
@Override @Override
@Deprecated
public int first(int materialId) { public int first(int materialId) {
return -1; return -1;
} }
@ -148,6 +150,7 @@ public class DiscordInventory implements Inventory {
} }
@Override @Override
@Deprecated
public void remove(int materialId) { public void remove(int materialId) {
} }

View file

@ -17,8 +17,6 @@ public class ServerWatcher {
private List<Player> playerList; private List<Player> playerList;
private final List<Player> fakePlayers = new ArrayList<>(); private final List<Player> fakePlayers = new ArrayList<>();
private Server origServer; private Server origServer;
//private ByteBuddy byteBuddy;
//private AsmVisitorWrapper mockTransformer;
@IgnoreForBinding @IgnoreForBinding
public void enableDisable(boolean enable) throws Exception { public void enableDisable(boolean enable) throws Exception {
@ -27,17 +25,6 @@ public class ServerWatcher {
if (enable) { if (enable) {
var serverClass = Bukkit.getServer().getClass(); var serverClass = Bukkit.getServer().getClass();
var originalServer = serverField.get(null); var originalServer = serverField.get(null);
//var impl = MethodDelegation.to(this);
//var names = Arrays.stream(ServerWatcher.class.getMethods()).map(Method::getName).toArray(String[]::new);
/*if (byteBuddy == null) {
byteBuddy = new ByteBuddy()
.with(TypeValidation.DISABLED)
.with(Implementation.Context.Disabled.Factory.INSTANCE)
.with(MethodGraph.Compiler.ForDeclaredMethods.INSTANCE)
.ignore(isSynthetic().and(not(isConstructor())).or(isDefaultFinalizer()));
mockTransformer=new InlineByteBuddyMockMaker().createMock()
}*/
DelegatingMockMaker.getInstance().setMockMaker(new InlineByteBuddyMockMaker()); DelegatingMockMaker.getInstance().setMockMaker(new InlineByteBuddyMockMaker());
var settings = Mockito.withSettings().stubOnly() var settings = Mockito.withSettings().stubOnly()
.defaultAnswer(invocation -> { .defaultAnswer(invocation -> {
@ -91,26 +78,6 @@ public class ServerWatcher {
serverField.set(null, origServer); serverField.set(null, origServer);
} }
/*@Override
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
if (classBeingRedefined == null)
return null;
try {
return byteBuddy
.redefine(
classBeingRedefined,
ClassFileLocator.Simple.of(classBeingRedefined.getName(), classfileBuffer)
)
//.visit(new InlineBytecodeGenerator.ParameterWritingVisitorWrapper(classBeingRedefined))
.visit(mockTransformer)
.make()
.getBytes();
} catch (Throwable throwable) {
TBMCCoreAPI.SendException("Failed to transform class!", throwable);
return null;
}
}*/
@RequiredArgsConstructor @RequiredArgsConstructor
public static class AppendListView<T> extends AbstractSequentialList<T> { public static class AppendListView<T> extends AbstractSequentialList<T> {
private final List<T> originalList; private final List<T> originalList;

View file

@ -3,20 +3,19 @@ package buttondevteam.discordplugin.role;
import buttondevteam.core.ComponentManager; import buttondevteam.core.ComponentManager;
import buttondevteam.discordplugin.DPUtils; import buttondevteam.discordplugin.DPUtils;
import buttondevteam.discordplugin.DiscordPlugin; import buttondevteam.discordplugin.DiscordPlugin;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.architecture.Component; import buttondevteam.lib.architecture.Component;
import buttondevteam.lib.architecture.ReadOnlyConfigData; import buttondevteam.lib.architecture.ReadOnlyConfigData;
import discord4j.core.event.domain.role.RoleCreateEvent; import discord4j.core.event.domain.role.RoleCreateEvent;
import discord4j.core.event.domain.role.RoleDeleteEvent; import discord4j.core.event.domain.role.RoleDeleteEvent;
import discord4j.core.event.domain.role.RoleEvent; import discord4j.core.event.domain.role.RoleEvent;
import discord4j.core.event.domain.role.RoleUpdateEvent; import discord4j.core.event.domain.role.RoleUpdateEvent;
import discord4j.core.object.entity.MessageChannel;
import discord4j.core.object.entity.Role; import discord4j.core.object.entity.Role;
import discord4j.core.object.entity.channel.MessageChannel;
import discord4j.rest.util.Color;
import lombok.val; import lombok.val;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import java.awt.*;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.function.Predicate; import java.util.function.Predicate;
@ -52,8 +51,8 @@ public class GameRoleModule extends Component<DiscordPlugin> {
* Defaults to the second to last in the upper row - #95a5a6. * Defaults to the second to last in the upper row - #95a5a6.
*/ */
private final ReadOnlyConfigData<Color> roleColor = getConfig().<Color>getConfig("roleColor") private final ReadOnlyConfigData<Color> roleColor = getConfig().<Color>getConfig("roleColor")
.def(new Color(149, 165, 166, 0)) .def(Color.of(149, 165, 166))
.getter(rgb -> new Color(Integer.parseInt(((String) rgb).substring(1), 16), true)) .getter(rgb -> Color.of(Integer.parseInt(((String) rgb).substring(1), 16)))
.setter(color -> String.format("#%08x", color.getRGB())).buildReadOnly(); .setter(color -> String.format("#%08x", color.getRGB())).buildReadOnly();
public static void handleRoleEvent(RoleEvent roleEvent) { public static void handleRoleEvent(RoleEvent roleEvent) {
@ -119,7 +118,7 @@ public class GameRoleModule extends Component<DiscordPlugin> {
val rc = roleColor.get(); val rc = roleColor.get();
return Mono.just(r.getColor().equals(rc)).filter(b -> b).flatMap(b -> return Mono.just(r.getColor().equals(rc)).filter(b -> b).flatMap(b ->
DiscordPlugin.dc.getSelf().flatMap(u -> u.asMember(DiscordPlugin.mainServer.getId())) DiscordPlugin.dc.getSelf().flatMap(u -> u.asMember(DiscordPlugin.mainServer.getId()))
.flatMap(m -> m.hasHigherRoles(Collections.singleton(r)))) //Below one of our roles .flatMap(m -> m.hasHigherRoles(Collections.singleton(r.getId())))) //Below one of our roles
.defaultIfEmpty(false); .defaultIfEmpty(false);
} }
} }