mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-25 11:35:18 +01:00
Use Paper method to get server protocol version if possible
This commit is contained in:
parent
76e739e4f0
commit
7300a69817
@ -47,11 +47,11 @@ subprojects {
|
|||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
maven("https://repo.viaversion.com")
|
||||||
|
maven("https://papermc.io/repo/repository/maven-public/")
|
||||||
maven("https://oss.sonatype.org/content/repositories/snapshots/")
|
maven("https://oss.sonatype.org/content/repositories/snapshots/")
|
||||||
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots")
|
|
||||||
maven("https://nexus.velocitypowered.com/repository/velocity-artifacts-snapshots/")
|
maven("https://nexus.velocitypowered.com/repository/velocity-artifacts-snapshots/")
|
||||||
maven("https://repo.spongepowered.org/repository/maven-public/")
|
maven("https://repo.spongepowered.org/repository/maven-public/")
|
||||||
maven("https://repo.viaversion.com")
|
|
||||||
maven("https://libraries.minecraft.net")
|
maven("https://libraries.minecraft.net")
|
||||||
maven("https://repo.maven.apache.org/maven2/")
|
maven("https://repo.maven.apache.org/maven2/")
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ object Versions {
|
|||||||
const val checkerQual = "3.12.0"
|
const val checkerQual = "3.12.0"
|
||||||
|
|
||||||
// Platforms
|
// Platforms
|
||||||
const val spigot = "1.16.5-R0.1-SNAPSHOT"
|
const val paper = "1.16.5-R0.1-SNAPSHOT"
|
||||||
const val legacyBukkit = "1.8.8-R0.1-SNAPSHOT"
|
const val legacyBukkit = "1.8.8-R0.1-SNAPSHOT"
|
||||||
const val bungee = "1.16-R0.5-SNAPSHOT"
|
const val bungee = "1.16-R0.5-SNAPSHOT"
|
||||||
const val sponge = "5.0.0"
|
const val sponge = "5.0.0"
|
||||||
|
@ -2,7 +2,7 @@ dependencies {
|
|||||||
implementation(project(":viaversion-bukkit-legacy"))
|
implementation(project(":viaversion-bukkit-legacy"))
|
||||||
implementation(project(":viaversion-common"))
|
implementation(project(":viaversion-common"))
|
||||||
implementation("org.javassist", "javassist", Versions.javassist)
|
implementation("org.javassist", "javassist", Versions.javassist)
|
||||||
compileOnly("org.spigotmc", "spigot-api", Versions.spigot) {
|
compileOnly("com.destroystokyo.paper", "paper-api", Versions.paper) {
|
||||||
exclude("junit", "junit")
|
exclude("junit", "junit")
|
||||||
exclude("com.google.code.gson", "gson")
|
exclude("com.google.code.gson", "gson")
|
||||||
exclude("javax.persistence", "persistence-api")
|
exclude("javax.persistence", "persistence-api")
|
||||||
|
@ -23,6 +23,8 @@ import io.netty.channel.ChannelFuture;
|
|||||||
import io.netty.channel.ChannelHandler;
|
import io.netty.channel.ChannelHandler;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
import io.netty.channel.socket.SocketChannel;
|
import io.netty.channel.socket.SocketChannel;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.UnsafeValues;
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
import us.myles.ViaVersion.api.Pair;
|
import us.myles.ViaVersion.api.Pair;
|
||||||
import us.myles.ViaVersion.api.Via;
|
import us.myles.ViaVersion.api.Via;
|
||||||
@ -39,10 +41,12 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
//TODO screams
|
||||||
public class BukkitViaInjector implements ViaInjector {
|
public class BukkitViaInjector implements ViaInjector {
|
||||||
private final List<ChannelFuture> injectedFutures = new ArrayList<>();
|
private final List<ChannelFuture> injectedFutures = new ArrayList<>();
|
||||||
private final List<Pair<Field, Object>> injectedLists = new ArrayList<>();
|
private final List<Pair<Field, Object>> injectedLists = new ArrayList<>();
|
||||||
|
|
||||||
|
private final boolean modernPaper = hasServerProtocolMethod();
|
||||||
private boolean protocolLib;
|
private boolean protocolLib;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -186,6 +190,11 @@ public class BukkitViaInjector implements ViaInjector {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getServerProtocolVersion() throws Exception {
|
public int getServerProtocolVersion() throws Exception {
|
||||||
|
if (modernPaper) {
|
||||||
|
// *Trust me, it's safe*
|
||||||
|
return Bukkit.getUnsafe().getProtocolVersion();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Class<?> serverClazz = NMSUtil.nms("MinecraftServer");
|
Class<?> serverClazz = NMSUtil.nms("MinecraftServer");
|
||||||
Object server = ReflectionUtil.invokeStatic(serverClazz, "getServer");
|
Object server = ReflectionUtil.invokeStatic(serverClazz, "getServer");
|
||||||
@ -367,4 +376,17 @@ public class BukkitViaInjector implements ViaInjector {
|
|||||||
public void setProtocolLib(boolean protocolLib) {
|
public void setProtocolLib(boolean protocolLib) {
|
||||||
this.protocolLib = protocolLib;
|
this.protocolLib = protocolLib;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isModernPaper() {
|
||||||
|
return modernPaper;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean hasServerProtocolMethod() {
|
||||||
|
try {
|
||||||
|
Class.forName("org.bukkit.UnsafeValues").getDeclaredMethod("getProtocolVersion");
|
||||||
|
return true;
|
||||||
|
} catch (ReflectiveOperationException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -42,6 +42,7 @@ public class BungeeViaInjector implements ViaInjector {
|
|||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
|
|
||||||
// Remove the final modifier (unless removed by a fork)
|
// Remove the final modifier (unless removed by a fork)
|
||||||
|
//TODO Fix Java 16 compatibility
|
||||||
int modifiers = field.getModifiers();
|
int modifiers = field.getModifiers();
|
||||||
if (Modifier.isFinal(modifiers)) {
|
if (Modifier.isFinal(modifiers)) {
|
||||||
try {
|
try {
|
||||||
|
@ -37,6 +37,7 @@ import java.lang.reflect.Method;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
//TODO screams
|
||||||
public class SpongeViaInjector implements ViaInjector {
|
public class SpongeViaInjector implements ViaInjector {
|
||||||
private List<ChannelFuture> injectedFutures = new ArrayList<>();
|
private List<ChannelFuture> injectedFutures = new ArrayList<>();
|
||||||
private List<Pair<Field, Object>> injectedLists = new ArrayList<>();
|
private List<Pair<Field, Object>> injectedLists = new ArrayList<>();
|
||||||
|
Loading…
Reference in New Issue
Block a user