Update to Discord4J v3.1.1
It wasn't as complicated as I expected
This commit is contained in:
parent
7cebb74835
commit
56d13ebf9f
28 changed files with 111 additions and 142 deletions
7
pom.xml
7
pom.xml
|
@ -155,7 +155,7 @@
|
|||
<dependency>
|
||||
<groupId>com.discord4j</groupId>
|
||||
<artifactId>discord4j-core</artifactId>
|
||||
<version>3.0.15</version>
|
||||
<version>3.1.1</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-jdk14 -->
|
||||
<dependency>
|
||||
|
@ -217,11 +217,6 @@
|
|||
<artifactId>mockito-core</artifactId>
|
||||
<version>3.5.13</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-inline</artifactId>
|
||||
<version>3.5.10</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<profiles>
|
||||
|
|
|
@ -2,7 +2,7 @@ package buttondevteam.discordplugin;
|
|||
|
||||
import buttondevteam.discordplugin.mcchat.MCChatUtils;
|
||||
import discord4j.core.object.entity.Message;
|
||||
import discord4j.core.object.entity.MessageChannel;
|
||||
import discord4j.core.object.entity.channel.MessageChannel;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
@ -19,9 +19,8 @@ public class ChromaBot {
|
|||
|
||||
/**
|
||||
* This will set the instance field.
|
||||
*
|
||||
* @param dp
|
||||
* The Discord plugin
|
||||
*
|
||||
* @param dp The Discord plugin
|
||||
*/
|
||||
ChromaBot(DiscordPlugin dp) {
|
||||
instance = this;
|
||||
|
@ -34,23 +33,22 @@ public class ChromaBot {
|
|||
|
||||
/**
|
||||
* Send a message to the chat channels and private chats.
|
||||
*
|
||||
* @param message
|
||||
* The message to send, duh (use {@link MessageChannel#createMessage(String)})
|
||||
*
|
||||
* @param message The message to send, duh (use {@link MessageChannel#createMessage(String)})
|
||||
*/
|
||||
public void sendMessage(Function<Mono<MessageChannel>, Mono<Message>> message) {
|
||||
MCChatUtils.forAllMCChat(ch -> message.apply(ch).subscribe());
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to the chat channels, private chats and custom chats.
|
||||
*
|
||||
* @param message The message to send, duh
|
||||
* @param toggle The toggle type for channelcon
|
||||
*/
|
||||
/**
|
||||
* Send a message to the chat channels, private chats and custom chats.
|
||||
*
|
||||
* @param message The message to send, duh
|
||||
* @param toggle The toggle type for channelcon
|
||||
*/
|
||||
public void sendMessageCustomAsWell(Function<Mono<MessageChannel>, Mono<Message>> message, @Nullable ChannelconBroadcast toggle) {
|
||||
MCChatUtils.forCustomAndAllMCChat(ch -> message.apply(ch).subscribe(), toggle, false);
|
||||
}
|
||||
}
|
||||
|
||||
public void updatePlayerList() {
|
||||
MCChatUtils.updatePlayerList();
|
||||
|
|
|
@ -5,11 +5,11 @@ import buttondevteam.lib.architecture.Component;
|
|||
import buttondevteam.lib.architecture.ConfigData;
|
||||
import buttondevteam.lib.architecture.IHaveConfig;
|
||||
import buttondevteam.lib.architecture.ReadOnlyConfigData;
|
||||
import discord4j.common.util.Snowflake;
|
||||
import discord4j.core.object.entity.Guild;
|
||||
import discord4j.core.object.entity.Message;
|
||||
import discord4j.core.object.entity.MessageChannel;
|
||||
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 lombok.val;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
@ -23,8 +23,8 @@ import java.util.regex.Pattern;
|
|||
|
||||
public final class DPUtils {
|
||||
|
||||
public static final Pattern URL_PATTERN = Pattern.compile("https?://\\S*");
|
||||
public static final Pattern FORMAT_PATTERN = Pattern.compile("[*_~]");
|
||||
private static final Pattern URL_PATTERN = Pattern.compile("https?://\\S*");
|
||||
private static final Pattern FORMAT_PATTERN = Pattern.compile("[*_~]");
|
||||
|
||||
public static EmbedCreateSpec embedWithHead(EmbedCreateSpec ecs, String displayname, String playername, String profileUrl) {
|
||||
return ecs.setAuthor(displayname, profileUrl, "https://minotar.net/avatar/" + playername + "/32.png");
|
||||
|
|
|
@ -3,8 +3,8 @@ package buttondevteam.discordplugin;
|
|||
import buttondevteam.discordplugin.mcchat.MinecraftChatModule;
|
||||
import buttondevteam.discordplugin.playerfaker.DiscordInventory;
|
||||
import buttondevteam.discordplugin.playerfaker.VCMDWrapper;
|
||||
import discord4j.core.object.entity.MessageChannel;
|
||||
import discord4j.core.object.entity.User;
|
||||
import discord4j.core.object.entity.channel.MessageChannel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Delegate;
|
||||
|
@ -161,6 +161,7 @@ public abstract class DiscordConnectedPlayer extends DiscordSenderBase implement
|
|||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public double getMaxHealth() {
|
||||
return 20;
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@ package buttondevteam.discordplugin;
|
|||
|
||||
import buttondevteam.discordplugin.mcchat.MinecraftChatModule;
|
||||
import buttondevteam.discordplugin.playerfaker.VCMDWrapper;
|
||||
import discord4j.core.object.entity.MessageChannel;
|
||||
import discord4j.core.object.entity.User;
|
||||
import discord4j.core.object.entity.channel.MessageChannel;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.mockito.Mockito;
|
||||
|
|
|
@ -19,8 +19,9 @@ import buttondevteam.lib.architecture.ConfigData;
|
|||
import buttondevteam.lib.architecture.IHaveConfig;
|
||||
import buttondevteam.lib.player.ChromaGamerBase;
|
||||
import com.google.common.io.Files;
|
||||
import discord4j.core.DiscordClient;
|
||||
import discord4j.common.util.Snowflake;
|
||||
import discord4j.core.DiscordClientBuilder;
|
||||
import discord4j.core.GatewayDiscordClient;
|
||||
import discord4j.core.event.domain.guild.GuildCreateEvent;
|
||||
import discord4j.core.event.domain.lifecycle.ReadyEvent;
|
||||
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.Presence;
|
||||
import discord4j.core.object.reaction.ReactionEmoji;
|
||||
import discord4j.core.object.util.Snowflake;
|
||||
import discord4j.rest.util.Color;
|
||||
import discord4j.store.jdk.JdkStoreService;
|
||||
import lombok.Getter;
|
||||
import lombok.val;
|
||||
|
@ -38,7 +39,6 @@ import org.bukkit.entity.Player;
|
|||
import org.mockito.internal.util.MockUtil;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
@ -47,7 +47,7 @@ import java.util.stream.Collectors;
|
|||
|
||||
@ButtonPlugin.ConfigOpts(disableConfigGen = true)
|
||||
public class DiscordPlugin extends ButtonPlugin {
|
||||
public static DiscordClient dc;
|
||||
public static GatewayDiscordClient dc;
|
||||
public static DiscordPlugin plugin;
|
||||
public static boolean SafeMode = true;
|
||||
@Getter
|
||||
|
@ -138,19 +138,18 @@ public class DiscordPlugin extends ButtonPlugin {
|
|||
return;
|
||||
}
|
||||
}
|
||||
val cb = DiscordClientBuilder.create(token);
|
||||
cb.setInitialPresence(Presence.doNotDisturb(Activity.playing("booting")));
|
||||
val cb = DiscordClientBuilder.create(token).build().gateway();
|
||||
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
|
||||
dc = cb.build();
|
||||
dc.getEventDispatcher().on(ReadyEvent.class) // Listen for ReadyEvent(s)
|
||||
.map(event -> event.getGuilds().size()) // Get how many guilds the bot is in
|
||||
.flatMap(size -> dc.getEventDispatcher()
|
||||
.on(GuildCreateEvent.class) // Listen for GuildCreateEvent(s)
|
||||
.take(size) // Take only the first `size` GuildCreateEvent(s) to be received
|
||||
.collectList()) // Take all received GuildCreateEvents and make it a List
|
||||
.subscribe(this::handleReady); /* All guilds have been received, client is fully connected */
|
||||
//dc.getEventDispatcher().on(DisconnectEvent.class);
|
||||
dc.login().subscribe();
|
||||
cb.login().subscribe(dc -> {
|
||||
DiscordPlugin.dc = dc; //Set to gateway client
|
||||
dc.on(ReadyEvent.class) // Listen for ReadyEvent(s)
|
||||
.map(event -> event.getGuilds().size()) // Get how many guilds the bot is in
|
||||
.flatMap(size -> dc
|
||||
.on(GuildCreateEvent.class) // Listen for GuildCreateEvent(s)
|
||||
.take(size) // Take only the first `size` GuildCreateEvent(s) to be received
|
||||
.collectList()).subscribe(this::handleReady); // Take all received GuildCreateEvents and make it a List
|
||||
}); /* All guilds have been received, client is fully connected */
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("Failed to enable the Discord plugin!", e);
|
||||
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 (event.size() == 0) {
|
||||
getLogger().severe("Main server not found! Invite the bot and do /discord reset");
|
||||
dc.getApplicationInfo().subscribe(info -> {
|
||||
getLogger().severe("Click here: https://discordapp.com/oauth2/authorize?client_id=" + info.getId().asString() + "&scope=bot&permissions=268509264");
|
||||
});
|
||||
dc.getApplicationInfo().subscribe(info ->
|
||||
getLogger().severe("Click here: https://discordapp.com/oauth2/authorize?client_id=" + info.getId().asString() + "&scope=bot&permissions=268509264"));
|
||||
saveConfig(); //Put default there
|
||||
return; //We should have all guilds by now, no need to retry
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package buttondevteam.discordplugin;
|
||||
|
||||
import discord4j.core.object.entity.Member;
|
||||
import discord4j.core.object.entity.MessageChannel;
|
||||
import discord4j.core.object.entity.User;
|
||||
import discord4j.core.object.entity.channel.MessageChannel;
|
||||
import lombok.val;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package buttondevteam.discordplugin;
|
||||
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import discord4j.core.object.entity.MessageChannel;
|
||||
import discord4j.core.object.entity.User;
|
||||
import discord4j.core.object.entity.channel.MessageChannel;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
@ -24,7 +24,7 @@ public abstract class DiscordSenderBase implements CommandSender {
|
|||
|
||||
/**
|
||||
* Returns the user. May be null.
|
||||
*
|
||||
*
|
||||
* @return The user or null.
|
||||
*/
|
||||
public User getUser() {
|
||||
|
@ -58,7 +58,7 @@ public abstract class DiscordSenderBase implements CommandSender {
|
|||
msgtosend += "\n" + sendmsg;
|
||||
if (sendtask == null)
|
||||
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;
|
||||
msgtosend = "";
|
||||
}, 4); // Waits a 0.2 second to gather all/most of the different messages
|
||||
|
|
|
@ -14,7 +14,7 @@ import com.google.gson.JsonElement;
|
|||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import discord4j.core.object.entity.Message;
|
||||
import discord4j.core.object.entity.MessageChannel;
|
||||
import discord4j.core.object.entity.channel.MessageChannel;
|
||||
import lombok.val;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
@ -34,14 +34,14 @@ public class AnnouncerModule extends Component<DiscordPlugin> {
|
|||
/**
|
||||
* Channel where distinguished (moderator) posts go.
|
||||
*/
|
||||
public ReadOnlyConfigData<Mono<MessageChannel>> modChannel() {
|
||||
private ReadOnlyConfigData<Mono<MessageChannel>> modChannel() {
|
||||
return DPUtils.channelData(getConfig(), "modChannel");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -91,11 +91,7 @@ public class PlayerListWatcher {
|
|||
if (fHandle == null) {
|
||||
assert lookupConstructor != null;
|
||||
var lookup = lookupConstructor.newInstance(mock.getClass());
|
||||
//var mcl = method.getDeclaringClass();
|
||||
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
|
||||
}
|
||||
|
|
|
@ -28,8 +28,8 @@ public class UserinfoCommand extends ICommand2DC {
|
|||
if (user == null || user.length() == 0)
|
||||
target = message.getAuthor().orElse(null);
|
||||
else {
|
||||
@SuppressWarnings("OptionalGetWithoutIsPresent") final User firstmention = message.getUserMentions()
|
||||
.filter(m -> !m.getId().asString().equals(DiscordPlugin.dc.getSelfId().get().asString())).blockFirst();
|
||||
final User firstmention = message.getUserMentions()
|
||||
.filter(m -> !m.getId().asString().equals(DiscordPlugin.dc.getSelfId().asString())).blockFirst();
|
||||
if (firstmention != null)
|
||||
target = firstmention;
|
||||
else if (user.contains("#")) {
|
||||
|
|
|
@ -3,7 +3,7 @@ package buttondevteam.discordplugin.exceptions;
|
|||
import buttondevteam.core.ComponentManager;
|
||||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
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.Listener;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
|
|
@ -9,9 +9,9 @@ import buttondevteam.lib.architecture.Component;
|
|||
import buttondevteam.lib.architecture.ConfigData;
|
||||
import buttondevteam.lib.architecture.ReadOnlyConfigData;
|
||||
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.channel.GuildChannel;
|
||||
import discord4j.core.object.entity.channel.MessageChannel;
|
||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
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.
|
||||
*/
|
||||
public class ExceptionListenerModule extends Component<DiscordPlugin> implements Listener {
|
||||
private List<Throwable> lastthrown = new ArrayList<>();
|
||||
private List<String> lastsourcemsg = new ArrayList<>();
|
||||
private final List<Throwable> lastthrown = new ArrayList<>();
|
||||
private final List<String> lastsourcemsg = new ArrayList<>();
|
||||
|
||||
@EventHandler
|
||||
public void onException(TBMCExceptionEvent e) {
|
||||
|
|
|
@ -9,7 +9,12 @@ import buttondevteam.lib.architecture.ConfigData;
|
|||
import buttondevteam.lib.architecture.ReadOnlyConfigData;
|
||||
import com.google.common.collect.Lists;
|
||||
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 lombok.val;
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -89,7 +94,7 @@ public class FunModule extends Component<DiscordPlugin> implements Listener {
|
|||
public static boolean executeMemes(Message message) {
|
||||
val fm = ComponentManager.getIfEnabled(FunModule.class);
|
||||
if (fm == null) return false;
|
||||
String msglowercased = message.getContent().orElse("").toLowerCase();
|
||||
String msglowercased = message.getContent().toLowerCase();
|
||||
lastlist++;
|
||||
if (lastlist > 5) {
|
||||
ListC = 0;
|
||||
|
|
|
@ -6,9 +6,9 @@ import buttondevteam.discordplugin.commands.Command2DCSender;
|
|||
import buttondevteam.discordplugin.util.Timings;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
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.channel.MessageChannel;
|
||||
import discord4j.core.object.entity.channel.PrivateChannel;
|
||||
import lombok.val;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
|
@ -25,9 +25,9 @@ public class CommandListener {
|
|||
public static Mono<Boolean> runCommand(Message message, MessageChannel commandChannel, boolean mentionedonly) {
|
||||
Timings timings = CommonListeners.timings;
|
||||
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
|
||||
val content = message.getContent().get();
|
||||
val content = message.getContent();
|
||||
timings.printElapsed("A");
|
||||
return message.getChannel().flatMap(channel -> {
|
||||
Mono<?> tmp = ret;
|
||||
|
@ -74,7 +74,7 @@ public class CommandListener {
|
|||
|
||||
private static boolean checkanddeletemention(StringBuilder cmdwithargs, String mention, Message message) {
|
||||
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) {
|
||||
int i = cmdwithargs.indexOf(" ", mention.length());
|
||||
if (i == -1)
|
||||
|
@ -89,7 +89,7 @@ public class CommandListener {
|
|||
cmdwithargs.replace(0, cmdwithargs.length(), prefix + "help");
|
||||
else {
|
||||
if (cmdwithargs.length() == 0)
|
||||
cmdwithargs.replace(0, cmdwithargs.length(), prefix + "help");
|
||||
cmdwithargs.replace(0, 0, prefix + "help");
|
||||
else if (cmdwithargs.charAt(0) != prefix)
|
||||
cmdwithargs.insert(0, prefix);
|
||||
return false; //Don't treat / as mention, mentions can be used in public mcchat
|
||||
|
|
|
@ -14,7 +14,7 @@ import discord4j.core.event.domain.message.MessageCreateEvent;
|
|||
import discord4j.core.event.domain.role.RoleCreateEvent;
|
||||
import discord4j.core.event.domain.role.RoleDeleteEvent;
|
||||
import discord4j.core.event.domain.role.RoleUpdateEvent;
|
||||
import discord4j.core.object.entity.PrivateChannel;
|
||||
import discord4j.core.object.entity.channel.PrivateChannel;
|
||||
import lombok.val;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
|
@ -47,7 +47,7 @@ public class CommonListeners {
|
|||
return commandCh.filterWhen(ch -> event.getMessage().getChannel().map(mch ->
|
||||
(commandChannel != null && mch.getId().asLong() == commandChannel.asLong()) //If mentioned, that's higher than chat
|
||||
|| 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
|
||||
if (!shouldRun)
|
||||
return Mono.just(true); //The condition is only for the first command execution, not mcchat
|
||||
|
|
|
@ -6,13 +6,12 @@ import buttondevteam.discordplugin.commands.ConnectCommand;
|
|||
import buttondevteam.lib.TBMCCommandPreprocessEvent;
|
||||
import buttondevteam.lib.player.TBMCPlayerGetInfoEvent;
|
||||
import buttondevteam.lib.player.TBMCPlayerJoinEvent;
|
||||
import discord4j.common.util.Snowflake;
|
||||
import discord4j.core.object.entity.Member;
|
||||
import discord4j.core.object.entity.User;
|
||||
import discord4j.core.object.util.Snowflake;
|
||||
import lombok.val;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.server.ServerCommandEvent;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
public class MCListener implements Listener {
|
||||
|
@ -53,7 +52,7 @@ public class MCListener implements Listener {
|
|||
}
|
||||
|
||||
@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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,11 +9,11 @@ import buttondevteam.lib.TBMCSystemChatEvent;
|
|||
import buttondevteam.lib.chat.Command2;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
import discord4j.core.object.entity.GuildChannel;
|
||||
import discord4j.core.object.entity.Message;
|
||||
import discord4j.core.object.entity.MessageChannel;
|
||||
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.val;
|
||||
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();
|
||||
return true;
|
||||
}
|
||||
//noinspection OptionalGetWithoutIsPresent
|
||||
var perms = ((GuildChannel) channel).getEffectivePermissions(message.getAuthor().map(User::getId).get()).block();
|
||||
if (!perms.contains(Permission.ADMINISTRATOR) && !perms.contains(Permission.MANAGE_CHANNELS)) {
|
||||
DPUtils.reply(message, channel, "you need to have manage permissions for this channel!").subscribe();
|
||||
|
|
|
@ -8,7 +8,7 @@ import buttondevteam.discordplugin.commands.ICommand2DC;
|
|||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.chat.Command2;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import discord4j.core.object.entity.PrivateChannel;
|
||||
import discord4j.core.object.entity.channel.PrivateChannel;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.val;
|
||||
|
||||
|
|
|
@ -4,9 +4,9 @@ import buttondevteam.core.component.channel.Channel;
|
|||
import buttondevteam.core.component.channel.ChatRoom;
|
||||
import buttondevteam.discordplugin.DiscordConnectedPlayer;
|
||||
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.util.Snowflake;
|
||||
import discord4j.core.object.entity.channel.MessageChannel;
|
||||
import lombok.NonNull;
|
||||
import lombok.val;
|
||||
|
||||
|
@ -62,7 +62,7 @@ public class MCChatCustom {
|
|||
public Set<TBMCSystemChatEvent.BroadcastTarget> brtoggles;
|
||||
|
||||
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);
|
||||
groupID = groupid;
|
||||
this.mcchannel = mcchannel;
|
||||
|
|
|
@ -13,11 +13,17 @@ import buttondevteam.lib.chat.ChatMessage;
|
|||
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
import com.vdurmont.emoji.EmojiParser;
|
||||
import discord4j.common.util.Snowflake;
|
||||
import discord4j.core.event.domain.message.MessageCreateEvent;
|
||||
import discord4j.core.object.Embed;
|
||||
import discord4j.core.object.entity.*;
|
||||
import discord4j.core.object.util.Snowflake;
|
||||
import discord4j.core.object.entity.Attachment;
|
||||
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.rest.util.Color;
|
||||
import lombok.val;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -26,7 +32,6 @@ import org.bukkit.event.Listener;
|
|||
import org.bukkit.scheduler.BukkitTask;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.awt.*;
|
||||
import java.time.Instant;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
@ -72,11 +77,11 @@ public class MCChatListener implements Listener {
|
|||
time = se.getValue();
|
||||
|
||||
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())));
|
||||
val color = e.getChannel().Color().get();
|
||||
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()));
|
||||
String url = module.profileURL().get();
|
||||
if (e.getSender() instanceof Player)
|
||||
|
@ -235,9 +240,8 @@ public class MCChatListener implements Listener {
|
|||
}).filter(channel -> {
|
||||
timings.printElapsed("Filter 2");
|
||||
return !(channel instanceof PrivateChannel //Only in private chat
|
||||
&& ev.getMessage().getContent().isPresent()
|
||||
&& ev.getMessage().getContent().get().length() < "/mcchat<>".length()
|
||||
&& ev.getMessage().getContent().get().replace(prefix + "", "")
|
||||
&& ev.getMessage().getContent().length() < "/mcchat<>".length()
|
||||
&& ev.getMessage().getContent().replace(prefix + "", "")
|
||||
.equalsIgnoreCase("mcchat")); //Either mcchat or /mcchat
|
||||
//Allow disabling the chat if needed
|
||||
}).filterWhen(channel -> CommandListener.runCommand(ev.getMessage(), channel, true))
|
||||
|
@ -268,7 +272,7 @@ public class MCChatListener implements Listener {
|
|||
return;
|
||||
}
|
||||
val sender = event.getMessage().getAuthor().orElse(null);
|
||||
String dmessage = event.getMessage().getContent().orElse("");
|
||||
String dmessage = event.getMessage().getContent();
|
||||
try {
|
||||
final DiscordSenderBase dsender = MCChatUtils.getSender(event.getMessage().getChannelId(), sender);
|
||||
val user = dsender.getChromaUser();
|
||||
|
|
|
@ -4,9 +4,9 @@ import buttondevteam.core.ComponentManager;
|
|||
import buttondevteam.discordplugin.DiscordConnectedPlayer;
|
||||
import buttondevteam.discordplugin.DiscordPlayer;
|
||||
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.channel.MessageChannel;
|
||||
import discord4j.core.object.entity.channel.PrivateChannel;
|
||||
import lombok.val;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
|
|
|
@ -7,8 +7,13 @@ import buttondevteam.discordplugin.broadcaster.GeneralEventBroadcasterModule;
|
|||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.TBMCSystemChatEvent;
|
||||
import com.google.common.collect.Sets;
|
||||
import discord4j.core.object.entity.*;
|
||||
import discord4j.core.object.util.Snowflake;
|
||||
import discord4j.common.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 lombok.RequiredArgsConstructor;
|
||||
import lombok.val;
|
||||
|
|
|
@ -7,8 +7,8 @@ import buttondevteam.lib.player.TBMCPlayer;
|
|||
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||
import buttondevteam.lib.player.TBMCYEEHAWEvent;
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import discord4j.common.util.Snowflake;
|
||||
import discord4j.core.object.entity.Role;
|
||||
import discord4j.core.object.util.Snowflake;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.val;
|
||||
import net.ess3.api.events.AfkStatusChangeEvent;
|
||||
|
|
|
@ -13,8 +13,8 @@ import buttondevteam.lib.architecture.Component;
|
|||
import buttondevteam.lib.architecture.ConfigData;
|
||||
import buttondevteam.lib.architecture.ReadOnlyConfigData;
|
||||
import com.google.common.collect.Lists;
|
||||
import discord4j.core.object.entity.MessageChannel;
|
||||
import discord4j.core.object.util.Snowflake;
|
||||
import discord4j.common.util.Snowflake;
|
||||
import discord4j.core.object.entity.channel.MessageChannel;
|
||||
import lombok.Getter;
|
||||
import lombok.val;
|
||||
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.
|
||||
*/
|
||||
public final ConfigData<Boolean> addFakePlayersToBukkit = getConfig().getData("addFakePlayersToBukkit", true);
|
||||
private final ConfigData<Boolean> addFakePlayersToBukkit = getConfig().getData("addFakePlayersToBukkit", true);
|
||||
|
||||
@Override
|
||||
protected void enable() {
|
||||
if (DPUtils.disableIfConfigErrorRes(this, chatChannel(), chatChannelMono()))
|
||||
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);
|
||||
TBMCCoreAPI.RegisterEventsForExceptions(listener, getPlugin());
|
||||
TBMCCoreAPI.RegisterEventsForExceptions(new MCListener(this), getPlugin());//These get undone if restarting/resetting - it will ignore events if disabled
|
||||
|
|
|
@ -113,6 +113,7 @@ public class DiscordInventory implements Inventory {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public HashMap<Integer, ? extends ItemStack> all(int materialId) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
@ -128,6 +129,7 @@ public class DiscordInventory implements Inventory {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public int first(int materialId) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -148,6 +150,7 @@ public class DiscordInventory implements Inventory {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void remove(int materialId) {
|
||||
}
|
||||
|
||||
|
|
|
@ -17,8 +17,6 @@ public class ServerWatcher {
|
|||
private List<Player> playerList;
|
||||
private final List<Player> fakePlayers = new ArrayList<>();
|
||||
private Server origServer;
|
||||
//private ByteBuddy byteBuddy;
|
||||
//private AsmVisitorWrapper mockTransformer;
|
||||
|
||||
@IgnoreForBinding
|
||||
public void enableDisable(boolean enable) throws Exception {
|
||||
|
@ -27,17 +25,6 @@ public class ServerWatcher {
|
|||
if (enable) {
|
||||
var serverClass = Bukkit.getServer().getClass();
|
||||
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());
|
||||
var settings = Mockito.withSettings().stubOnly()
|
||||
.defaultAnswer(invocation -> {
|
||||
|
@ -91,26 +78,6 @@ public class ServerWatcher {
|
|||
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
|
||||
public static class AppendListView<T> extends AbstractSequentialList<T> {
|
||||
private final List<T> originalList;
|
||||
|
|
|
@ -3,20 +3,19 @@ package buttondevteam.discordplugin.role;
|
|||
import buttondevteam.core.ComponentManager;
|
||||
import buttondevteam.discordplugin.DPUtils;
|
||||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.architecture.Component;
|
||||
import buttondevteam.lib.architecture.ReadOnlyConfigData;
|
||||
import discord4j.core.event.domain.role.RoleCreateEvent;
|
||||
import discord4j.core.event.domain.role.RoleDeleteEvent;
|
||||
import discord4j.core.event.domain.role.RoleEvent;
|
||||
import discord4j.core.event.domain.role.RoleUpdateEvent;
|
||||
import discord4j.core.object.entity.MessageChannel;
|
||||
import discord4j.core.object.entity.Role;
|
||||
import discord4j.core.object.entity.channel.MessageChannel;
|
||||
import discord4j.rest.util.Color;
|
||||
import lombok.val;
|
||||
import org.bukkit.Bukkit;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
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.
|
||||
*/
|
||||
private final ReadOnlyConfigData<Color> roleColor = getConfig().<Color>getConfig("roleColor")
|
||||
.def(new Color(149, 165, 166, 0))
|
||||
.getter(rgb -> new Color(Integer.parseInt(((String) rgb).substring(1), 16), true))
|
||||
.def(Color.of(149, 165, 166))
|
||||
.getter(rgb -> Color.of(Integer.parseInt(((String) rgb).substring(1), 16)))
|
||||
.setter(color -> String.format("#%08x", color.getRGB())).buildReadOnly();
|
||||
|
||||
public static void handleRoleEvent(RoleEvent roleEvent) {
|
||||
|
@ -119,7 +118,7 @@ public class GameRoleModule extends Component<DiscordPlugin> {
|
|||
val rc = roleColor.get();
|
||||
return Mono.just(r.getColor().equals(rc)).filter(b -> b).flatMap(b ->
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue