Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-24 15:20:25 +01:00
Print a logger warning if Geyser players will be unable to join this server
We check if ViaVersion supports our version and doesn't have us blocked, and if the server supports our version natively.
Dieser Commit ist enthalten in:
Ursprung
5d7e564d95
Commit
6318655e28
@ -11,6 +11,10 @@
|
||||
<artifactId>bootstrap-spigot</artifactId>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>papermc</id>
|
||||
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>viaversion-repo</id>
|
||||
<url>https://repo.viaversion.com</url>
|
||||
@ -25,9 +29,9 @@
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.15.2-R0.1-SNAPSHOT</version>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.18.1-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -168,8 +168,7 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
|
||||
// Ensure that we have the latest 4.0.0 changes and not an older ViaVersion version
|
||||
Class.forName("com.viaversion.viaversion.api.ViaManager");
|
||||
} catch (ClassNotFoundException e) {
|
||||
geyserLogger.warning(GeyserLocale.getLocaleStringLog("geyser.bootstrap.viaversion.too_old",
|
||||
"https://ci.viaversion.com/job/ViaVersion/"));
|
||||
GeyserSpigotVersionChecker.sendOutdatedViaVersionMessage(geyserLogger);
|
||||
isViaVersion = false;
|
||||
if (this.geyserConfig.isDebugMode()) {
|
||||
e.printStackTrace();
|
||||
@ -242,6 +241,9 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap {
|
||||
}
|
||||
|
||||
this.getCommand("geyser").setExecutor(new GeyserSpigotCommandExecutor(geyser));
|
||||
|
||||
// Check to ensure the current setup can support the protocol version Geyser uses
|
||||
GeyserSpigotVersionChecker.checkForSupportedProtocol(geyserLogger, isViaVersion);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author GeyserMC
|
||||
* @link https://github.com/GeyserMC/Geyser
|
||||
*/
|
||||
|
||||
package org.geysermc.geyser.platform.spigot;
|
||||
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.UnsafeValues;
|
||||
import org.geysermc.geyser.GeyserLogger;
|
||||
import org.geysermc.geyser.network.MinecraftProtocol;
|
||||
import org.geysermc.geyser.text.GeyserLocale;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
public final class GeyserSpigotVersionChecker {
|
||||
private static final String VIAVERSION_DOWNLOAD_URL = "https://ci.viaversion.com/job/ViaVersion/";
|
||||
|
||||
public static void checkForSupportedProtocol(GeyserLogger logger, boolean viaversion) {
|
||||
if (viaversion) {
|
||||
checkViaVersionSupportedVersions(logger);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// This method is only present on later versions of Paper
|
||||
UnsafeValues.class.getMethod("getProtocolVersion");
|
||||
if (Bukkit.getUnsafe().getProtocolVersion() != MinecraftProtocol.getJavaProtocolVersion()) {
|
||||
sendOutdatedMessage(logger);
|
||||
}
|
||||
return;
|
||||
} catch (NoSuchMethodException ignored) {
|
||||
}
|
||||
|
||||
// Otherwise, we can just try to find the SharedConstants class
|
||||
// It isn't present in all server versions, but if we can't find it, then we're probably not in the latest version
|
||||
Class<?> sharedConstants;
|
||||
try {
|
||||
sharedConstants = Class.forName("net.minecraft.SharedConstants");
|
||||
} catch (ClassNotFoundException e) {
|
||||
// We're using pre-1.17
|
||||
String prefix = Bukkit.getServer().getClass().getPackage().getName().replace("org.bukkit.craftbukkit", "net.minecraft.server");
|
||||
try {
|
||||
sharedConstants = Class.forName(prefix + ".SharedConstants");
|
||||
} catch (ClassNotFoundException e2) {
|
||||
sendOutdatedMessage(logger);
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (Method method : sharedConstants.getMethods()) {
|
||||
if (method.getReturnType() == int.class && Modifier.isStatic(method.getModifiers())) {
|
||||
int protocolVersion;
|
||||
try {
|
||||
protocolVersion = (int) method.invoke(null);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
logger.warning("Could not determine server version! This is safe to ignore, but please report to the developers: " + e.getMessage());
|
||||
if (logger.isDebug()) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (protocolVersion != MinecraftProtocol.getJavaProtocolVersion()) {
|
||||
sendOutdatedMessage(logger);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
sendOutdatedMessage(logger);
|
||||
}
|
||||
|
||||
private static void checkViaVersionSupportedVersions(GeyserLogger logger) {
|
||||
// Run after ViaVersion has obtained the server protocol version
|
||||
Via.getPlatform().runSync(() -> {
|
||||
if (Via.getAPI().getSupportedVersions().contains(MinecraftProtocol.getJavaProtocolVersion())) {
|
||||
// Via supports this protocol version; we will be able to connect.
|
||||
return;
|
||||
}
|
||||
if (Via.getAPI().getFullSupportedVersions().contains(MinecraftProtocol.getJavaProtocolVersion())) {
|
||||
// ViaVersion supports our protocol, but the user has blocked them from connecting.
|
||||
logger.warning(GeyserLocale.getLocaleStringLog("geyser.bootstrap.viaversion.blocked", MinecraftProtocol.getAllSupportedJavaVersions()));
|
||||
return;
|
||||
}
|
||||
// Else, presumably, ViaVersion is not updated.
|
||||
sendOutdatedViaVersionMessage(logger);
|
||||
});
|
||||
}
|
||||
|
||||
public static void sendOutdatedViaVersionMessage(GeyserLogger logger) {
|
||||
logger.warning(GeyserLocale.getLocaleStringLog("geyser.bootstrap.viaversion.too_old",
|
||||
VIAVERSION_DOWNLOAD_URL));
|
||||
}
|
||||
|
||||
private static void sendOutdatedMessage(GeyserLogger logger) {
|
||||
logger.warning(GeyserLocale.getLocaleStringLog("geyser.bootstrap.no_supported_protocol", MinecraftProtocol.getAllSupportedJavaVersions(), VIAVERSION_DOWNLOAD_URL));
|
||||
}
|
||||
|
||||
private GeyserSpigotVersionChecker() {
|
||||
}
|
||||
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren