我正在为朋友的我的世界服务器制作插件,他们也为此服务器提供了不和谐服务器。我正在尝试使用 discord4j 在不和谐服务器和插件之间添加一些集成。插件编译得很好,当我尝试加载插件时,我得到两个异常之一:
- 第一次加载插件
java.lang.NoSuchMethodError: 'boolean io.netty.handler.ssl.SslProvider.isAlpnSupported(io.netty.handler.ssl.SslProvider)'
at reactor.netty.http.client.HttpClientSecure.<clinit>(HttpClientSecure.java:79) ~[?:?]
at reactor.netty.http.client.HttpClient.secure(HttpClient.java:1073) ~[?:?]
at discord4j.common.ReactorResources.lambda$static$0(ReactorResources.java:41) ~[?:?]
at discord4j.common.ReactorResources.<init>(ReactorResources.java:54) ~[?:?]
at discord4j.rest.RestClientBuilder.initReactorResources(RestClientBuilder.java:245) ~[?:?]
at discord4j.rest.RestClientBuilder.build(RestClientBuilder.java:226) ~[?:?]
at discord4j.core.DiscordClientBuilder.build(DiscordClientBuilder.java:85) ~[?:?]
at discord4j.core.DiscordClientBuilder.build(DiscordClientBuilder.java:73) ~[?:?]
at nz.laspruca.tcplugin.util.Discord.<init>(Discord.java:18) ~[?:?]
at nz.laspruca.tcplugin.Plugin.onEnable(Plugin.java:14) ~[?:?]
at org.qrl.tcplugin.TCPlugin.onEnable(TCPlugin.java:18) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) ~[spigot-1.16.3.jar:git-Spigot-57bbdd8-55a78ff]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:351) ~[spigot-1.16.3.jar:git-Spigot-57bbdd8-55a78ff]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:480) ~[spigot-1.16.3.jar:git-Spigot-57bbdd8-55a78ff]
at org.bukkit.craftbukkit.v1_16_R2.CraftServer.enablePlugin(CraftServer.java:494) ~[spigot-1.16.3.jar:git-Spigot-57bbdd8-55a78ff]
at org.bukkit.craftbukkit.v1_16_R2.CraftServer.enablePlugins(CraftServer.java:408) ~[spigot-1.16.3.jar:git-Spigot-57bbdd8-55a78ff]
at net.minecraft.server.v1_16_R2.MinecraftServer.loadWorld(MinecraftServer.java:435) ~[spigot-1.16.3.jar:git-Spigot-57bbdd8-55a78ff]
at net.minecraft.server.v1_16_R2.DedicatedServer.init(DedicatedServer.java:216) ~[spigot-1.16.3.jar:git-Spigot-57bbdd8-55a78ff]
at net.minecraft.server.v1_16_R2.MinecraftServer.w(MinecraftServer.java:808) ~[spigot-1.16.3.jar:git-Spigot-57bbdd8-55a78ff]
at net.minecraft.server.v1_16_R2.MinecraftServer.lambda$0(MinecraftServer.java:164) ~[spigot-1.16.3.jar:git-Spigot-57bbdd8-55a78ff]
at java.lang.Thread.run(Thread.java:834) [?:?]
- 当我重新加载插件时
java.lang.ExceptionInInitializerError: null
at reactor.netty.http.client.HttpClient.followRedirect(HttpClient.java:870) ~[?:?]
at reactor.netty.http.client.HttpClient.followRedirect(HttpClient.java:806) ~[?:?]
at discord4j.common.ReactorResources.lambda$static$0(ReactorResources.java:41) ~[?:?]
at discord4j.common.ReactorResources.<init>(ReactorResources.java:54) ~[?:?]
at discord4j.rest.RestClientBuilder.initReactorResources(RestClientBuilder.java:245) ~[?:?]
at discord4j.rest.RestClientBuilder.build(RestClientBuilder.java:226) ~[?:?]
at discord4j.core.DiscordClientBuilder.build(DiscordClientBuilder.java:85) ~[?:?]
at discord4j.core.DiscordClientBuilder.build(DiscordClientBuilder.java:73) ~[?:?]
at nz.laspruca.tcplugin.util.Discord.<init>(Discord.java:18) ~[?:?]
at nz.laspruca.tcplugin.Plugin.onEnable(Plugin.java:14) ~[?:?]
at org.qrl.tcplugin.TCPlugin.onEnable(TCPlugin.java:18) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) ~[spigot-1.16.3.jar:git-Spigot-57bbdd8-55a78ff]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:351) ~[spigot-1.16.3.jar:git-Spigot-57bbdd8-55a78ff]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:480) ~[spigot-1.16.3.jar:git-Spigot-57bbdd8-55a78ff]
at org.bukkit.craftbukkit.v1_16_R2.CraftServer.enablePlugin(CraftServer.java:494) ~[spigot-1.16.3.jar:git-Spigot-57bbdd8-55a78ff]
at org.bukkit.craftbukkit.v1_16_R2.CraftServer.enablePlugins(CraftServer.java:408) ~[spigot-1.16.3.jar:git-Spigot-57bbdd8-55a78ff]
at org.bukkit.craftbukkit.v1_16_R2.CraftServer.reload(CraftServer.java:876) ~[spigot-1.16.3.jar:git-Spigot-57bbdd8-55a78ff]
at org.bukkit.Bukkit.reload(Bukkit.java:642) ~[spigot-1.16.3.jar:git-Spigot-57bbdd8-55a78ff]
at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:27) ~[spigot-1.16.3.jar:git-Spigot-57bbdd8-55a78ff]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149) ~[spigot-1.16.3.jar:git-Spigot-57bbdd8-55a78ff]
at org.bukkit.craftbukkit.v1_16_R2.CraftServer.dispatchCommand(CraftServer.java:758) ~[spigot-1.16.3.jar:git-Spigot-57bbdd8-55a78ff]
at org.bukkit.craftbukkit.v1_16_R2.CraftServer.dispatchServerCommand(CraftServer.java:743) ~[spigot-1.16.3.jar:git-Spigot-57bbdd8-55a78ff]
at net.minecraft.server.v1_16_R2.DedicatedServer.handleCommandQueue(DedicatedServer.java:381) ~[spigot-1.16.3.jar:git-Spigot-57bbdd8-55a78ff]
at net.minecraft.server.v1_16_R2.DedicatedServer.b(DedicatedServer.java:350) ~[spigot-1.16.3.jar:git-Spigot-57bbdd8-55a78ff]
at net.minecraft.server.v1_16_R2.MinecraftServer.a(MinecraftServer.java:1007) ~[spigot-1.16.3.jar:git-Spigot-57bbdd8-55a78ff]
at net.minecraft.server.v1_16_R2.MinecraftServer.w(MinecraftServer.java:846) ~[spigot-1.16.3.jar:git-Spigot-57bbdd8-55a78ff]
at net.minecraft.server.v1_16_R2.MinecraftServer.lambda$0(MinecraftServer.java:164) ~[spigot-1.16.3.jar:git-Spigot-57bbdd8-55a78ff]
at java.lang.Thread.run(Thread.java:834) [?:?]
Caused by: java.lang.IllegalArgumentException: 'httpClientConf' is already in use
at io.netty.util.ConstantPool.createOrThrow(ConstantPool.java:113) ~[spigot-1.16.3.jar:git-Spigot-57bbdd8-55a78ff]
at io.netty.util.ConstantPool.newInstance(ConstantPool.java:95) ~[spigot-1.16.3.jar:git-Spigot-57bbdd8-55a78ff]
at io.netty.util.AttributeKey.newInstance(AttributeKey.java:55) ~[spigot-1.16.3.jar:git-Spigot-57bbdd8-55a78ff]
at reactor.netty.http.client.HttpClientConfiguration.<clinit>(HttpClientConfiguration.java:51) ~[?:?]
... 28 more
这是我的 pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.qrl</groupId>
<artifactId>tcplugin</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>TCPlugin</name>
<description>The offical TCPlugin</description>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<url>qrl.nz</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>module-info.class</exclude>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<repositories>
<repository>
<id>jitpack</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>bintray</name>
<url>https://jcenter.bintray.com</url>
</repository>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.3-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.discord4j</groupId>
<artifactId>discord4j-core</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>com.github.DevLeoko</groupId>
<artifactId>AdvancedBan</artifactId>
<version>2.2.1</version>
</dependency>
</dependencies>
</project>
负责不和谐互动的班级
package nz.laspruca.tcplugin.util;
import discord4j.core.DiscordClient;
import discord4j.core.GatewayDiscordClient;
import discord4j.core.object.entity.Member;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import static org.qrl.tcplugin.TCPlugin.*;
public class Discord {
public GatewayDiscordClient gateway;
private boolean goBrr = true;
public Discord(String token) {
DiscordClient client = DiscordClient.builder(token).build();
gateway = client.login().block();
if (gateway == null) {
logger.warning("Unable to connect to discord, oh well");
goBrr = false;
}
}
public void exitDiscord() {
if (goBrr) {
gateway.logout();
}
}
public boolean logedIn() {
return this.goBrr;
}
public List<String> getMembers() throws IllegalStateException {
if (goBrr)
return Objects.requireNonNull(Objects.requireNonNull(gateway
.getGuilds()
.collect(Collectors.toList())
.block())
.get(0)
.getMembers()
.collect(Collectors.toList())
.block())
.stream()
.map(Member::getDisplayName)
.collect(Collectors.toList());
else
throw new IllegalStateException("No valid connection to discord");
}
}