This commit is contained in:
Xaw3ep 2023-04-13 12:39:25 +07:00
parent 347423c60b
commit e29dfcb42a
3 changed files with 10 additions and 10 deletions

Binary file not shown.

View File

@ -106,13 +106,6 @@
<artifactId>bungeecord-event</artifactId>
<version>1.19-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>protocolsupport</groupId>
<artifactId>protocolsupport</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/libs/ProtocolSupport.jar</systemPath>
</dependency>
</dependencies>
<!-- Build Description Profiles -->

View File

@ -1,5 +1,7 @@
package me.asofold.bpl.cncp.ClientVersion;
import java.lang.reflect.Method;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -9,17 +11,19 @@ import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.Plugin;
import com.viaversion.viaversion.api.Via;
import protocolsupport.api.ProtocolSupportAPI;
import fr.neatmonster.nocheatplus.compat.Folia;
import fr.neatmonster.nocheatplus.players.DataManager;
import fr.neatmonster.nocheatplus.players.IPlayerData;
import fr.neatmonster.nocheatplus.utilities.ReflectionUtil;
import me.asofold.bpl.cncp.CompatNoCheatPlus;
import me.asofold.bpl.cncp.config.Settings;
public class ClientVersionListener implements Listener {
private Plugin ViaVersion = Bukkit.getPluginManager().getPlugin("ViaVersion");
private Plugin ProtocolSupport = Bukkit.getPluginManager().getPlugin("ProtocolSupport");
private final Class<?> ProtocolSupportAPIClass = ReflectionUtil.getClass("protocolsupport.api.ProtocolSupportAPI");
private final Class<?> ProtocolVersionClass = ReflectionUtil.getClass("protocolsupport.api.ProtocolVersion");
private final Method getProtocolVersion = ReflectionUtil.getMethod(ProtocolSupportAPIClass, "getProtocolVersion", Player.class);
@SuppressWarnings("unchecked")
@EventHandler(priority = EventPriority.MONITOR)
@ -34,7 +38,10 @@ public class ClientVersionListener implements Listener {
}
else if (ProtocolSupport != null && ProtocolSupport.isEnabled()) {
// Fallback to PS
pData.setClientVersionID(ProtocolSupportAPI.getProtocolVersion(player).getId());
Object protocolVersion = ReflectionUtil.invokeMethod(getProtocolVersion, null, player);
Method getId = ReflectionUtil.getMethodNoArgs(ProtocolVersionClass, "getId", int.class);
int version = (int) ReflectionUtil.invokeMethodNoArgs(getId, protocolVersion);
pData.setClientVersionID(version);
}
// (Client version stays unknown (-1))
}