Attempt to retrieve the client's protocol ID through ProtocolSupport/ViaVersion.
This commit is contained in:
parent
d12cf777f4
commit
eaf1b2280e
|
@ -0,0 +1,6 @@
|
||||||
|
/target/
|
||||||
|
.classpath
|
||||||
|
.DS_Store
|
||||||
|
.project
|
||||||
|
.settings/org.eclipse.core.resources.prefs
|
||||||
|
*.prefs
|
Binary file not shown.
35
pom.xml
35
pom.xml
|
@ -25,14 +25,18 @@
|
||||||
<enabled>true</enabled>
|
<enabled>true</enabled>
|
||||||
</snapshots>
|
</snapshots>
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
|
||||||
<id>repo-public</id>
|
|
||||||
<url>https://repo.codemc.org/repository/maven-public/</url>
|
|
||||||
</repository>
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>jitpack.io</id>
|
<id>jitpack.io</id>
|
||||||
<url>https://jitpack.io</url>
|
<url>https://jitpack.io</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>viaversion-repo</id>
|
||||||
|
<url>https://repo.viaversion.com</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>repo-public</id>
|
||||||
|
<url>https://repo.codemc.org/repository/maven-public/</url>
|
||||||
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<!-- Dependencies -->
|
<!-- Dependencies -->
|
||||||
|
@ -91,11 +95,23 @@
|
||||||
<artifactId>bungeecord-api</artifactId>
|
<artifactId>bungeecord-api</artifactId>
|
||||||
<version>1.18-R0.1-20220408.230221-26</version>
|
<version>1.18-R0.1-20220408.230221-26</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.viaversion</groupId>
|
||||||
|
<artifactId>viaversion-api</artifactId>
|
||||||
|
<version>LATEST</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.md-5</groupId>
|
<groupId>net.md-5</groupId>
|
||||||
<artifactId>bungeecord-event</artifactId>
|
<artifactId>bungeecord-event</artifactId>
|
||||||
<version>1.18-R0.1-20220408.230147-26</version>
|
<version>1.18-R0.1-20220408.230147-26</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>protocolsupport</groupId>
|
||||||
|
<artifactId>protocolsupport</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
<scope>system</scope>
|
||||||
|
<systemPath>${basedir}/libs/ProtocolSupport.jar</systemPath>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<!-- Build Description Profiles -->
|
<!-- Build Description Profiles -->
|
||||||
|
@ -168,8 +184,15 @@
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
<pluginRepositories>
|
||||||
|
<pluginRepository>
|
||||||
|
<id>jitpack.io</id>
|
||||||
|
<url>https://jitpack.io</url>
|
||||||
|
</pluginRepository>
|
||||||
|
</pluginRepositories>
|
||||||
|
-->
|
||||||
|
|
||||||
<!-- Properties -->
|
<!-- Properties -->
|
||||||
<properties>
|
<properties>
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
package me.asofold.bpl.cncp.ClientVersion;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
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.players.DataManager;
|
||||||
|
import fr.neatmonster.nocheatplus.players.IPlayerData;
|
||||||
|
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");
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
final Player player = event.getPlayer();
|
||||||
|
Bukkit.getScheduler()
|
||||||
|
.runTaskLater(CompatNoCheatPlus.getInstance(), new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
final IPlayerData pData = DataManager.getPlayerData(player);
|
||||||
|
if (pData != null) {
|
||||||
|
if (ViaVersion != null && ViaVersion.isEnabled()) {
|
||||||
|
// Give precedence to ViaVersion
|
||||||
|
pData.setClientVersionID(Via.getAPI().getPlayerVersion(player));
|
||||||
|
}
|
||||||
|
else if (ProtocolSupport != null && ProtocolSupport.isEnabled()) {
|
||||||
|
// Fallback to PS
|
||||||
|
pData.setClientVersionID(ProtocolSupportAPI.getProtocolVersion(player).getId());
|
||||||
|
}
|
||||||
|
// (Client version stays unknown (-1))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 20); // Wait 20 ticks before setting client data
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,6 +28,7 @@ import fr.neatmonster.nocheatplus.components.registry.feature.IDisableListener;
|
||||||
import fr.neatmonster.nocheatplus.hooks.NCPHook;
|
import fr.neatmonster.nocheatplus.hooks.NCPHook;
|
||||||
import fr.neatmonster.nocheatplus.hooks.NCPHookManager;
|
import fr.neatmonster.nocheatplus.hooks.NCPHookManager;
|
||||||
import me.asofold.bpl.cncp.bedrock.BedrockPlayerListener;
|
import me.asofold.bpl.cncp.bedrock.BedrockPlayerListener;
|
||||||
|
import me.asofold.bpl.cncp.ClientVersion.ClientVersionListener;
|
||||||
import me.asofold.bpl.cncp.config.Settings;
|
import me.asofold.bpl.cncp.config.Settings;
|
||||||
import me.asofold.bpl.cncp.config.compatlayer.CompatConfig;
|
import me.asofold.bpl.cncp.config.compatlayer.CompatConfig;
|
||||||
import me.asofold.bpl.cncp.config.compatlayer.NewConfig;
|
import me.asofold.bpl.cncp.config.compatlayer.NewConfig;
|
||||||
|
@ -171,25 +172,25 @@ public class CompatNoCheatPlus extends JavaPlugin implements Listener {
|
||||||
builtinHooks.clear();
|
builtinHooks.clear();
|
||||||
// Might-fail hooks:
|
// Might-fail hooks:
|
||||||
// Set speed
|
// Set speed
|
||||||
try{
|
try {
|
||||||
builtinHooks.add(new me.asofold.bpl.cncp.hooks.generic.HookSetSpeed());
|
builtinHooks.add(new me.asofold.bpl.cncp.hooks.generic.HookSetSpeed());
|
||||||
}
|
}
|
||||||
catch (Throwable t){}
|
catch (Throwable t) {}
|
||||||
// Citizens 2
|
// Citizens 2
|
||||||
try{
|
try {
|
||||||
builtinHooks.add(new me.asofold.bpl.cncp.hooks.citizens2.HookCitizens2());
|
builtinHooks.add(new me.asofold.bpl.cncp.hooks.citizens2.HookCitizens2());
|
||||||
}
|
}
|
||||||
catch (Throwable t){}
|
catch (Throwable t) {}
|
||||||
// mcMMO
|
// mcMMO
|
||||||
try{
|
try {
|
||||||
builtinHooks.add(new me.asofold.bpl.cncp.hooks.mcmmo.HookmcMMO());
|
builtinHooks.add(new me.asofold.bpl.cncp.hooks.mcmmo.HookmcMMO());
|
||||||
}
|
}
|
||||||
catch (Throwable t){}
|
catch (Throwable t) {}
|
||||||
// GravityTubes
|
// GravityTubes
|
||||||
try {
|
try {
|
||||||
builtinHooks.add(new me.asofold.bpl.cncp.hooks.GravityTubes.HookGravityTubes());
|
builtinHooks.add(new me.asofold.bpl.cncp.hooks.GravityTubes.HookGravityTubes());
|
||||||
}
|
}
|
||||||
catch(Throwable t){}
|
catch (Throwable t) {}
|
||||||
// CMI
|
// CMI
|
||||||
try {
|
try {
|
||||||
builtinHooks.add(new me.asofold.bpl.cncp.hooks.CMI.HookCMI());
|
builtinHooks.add(new me.asofold.bpl.cncp.hooks.CMI.HookCMI());
|
||||||
|
@ -247,6 +248,7 @@ public class CompatNoCheatPlus extends JavaPlugin implements Listener {
|
||||||
final PluginManager pm = getServer().getPluginManager();
|
final PluginManager pm = getServer().getPluginManager();
|
||||||
pm.registerEvents(this, this);
|
pm.registerEvents(this, this);
|
||||||
pm.registerEvents(new BedrockPlayerListener(), this);
|
pm.registerEvents(new BedrockPlayerListener(), this);
|
||||||
|
pm.registerEvents(new ClientVersionListener(), this);
|
||||||
getServer().getMessenger().registerIncomingPluginChannel(this, "cncp:geyser", new BedrockPlayerListener());
|
getServer().getMessenger().registerIncomingPluginChannel(this, "cncp:geyser", new BedrockPlayerListener());
|
||||||
try {
|
try {
|
||||||
bungee = getServer().spigot().getConfig().getBoolean("settings.bungeecord");
|
bungee = getServer().spigot().getConfig().getBoolean("settings.bungeecord");
|
||||||
|
|
Loading…
Reference in New Issue