Skip to content

Commit

Permalink
refactor(spigot): use mc version field to detect protocollib version (#…
Browse files Browse the repository at this point in the history
…368)

Closes #362
  • Loading branch information
diogotcorreia authored Dec 18, 2023
1 parent aba7a9b commit 9219770
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.rexcantor64.triton.spigot;

import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.utility.MinecraftVersion;
import com.rexcantor64.triton.Triton;
import com.rexcantor64.triton.api.players.LanguagePlayer;
import com.rexcantor64.triton.player.PlayerManager;
Expand Down Expand Up @@ -168,7 +169,7 @@ protected void startConfigRefreshTask() {
/**
* Checks if ProtocolLib is enabled and if its version matches
* the expected version.
* Triton requires ProtocolLib 5.1.0 or later.
* Triton requires ProtocolLib 5.2.0 or later.
*
* @return Whether the plugin should continue loading
* @since 3.8.2
Expand All @@ -185,13 +186,11 @@ private boolean isProtocolLibAvailable() {
return true;
}

val version = protocolLib.getDescription().getVersion();
val versionParts = version.split("\\.");
val majorVersion = Integer.parseInt(versionParts[0]);
val minorVersion = Integer.parseInt(versionParts[1]);
if (majorVersion < 5 || (majorVersion == 5 && minorVersion < 1)) {
// Triton requires ProtocolLib 5.1.0 or later
getLogger().logError("ProtocolLib 5.1.0 or later is required! Older versions of ProtocolLib will only partially work, and are therefore not recommended.");
try {
MinecraftVersion ignore = MinecraftVersion.v1_20_4;
} catch (NoSuchFieldError ignore) {
// Triton requires ProtocolLib 5.2.0 or later
getLogger().logError("ProtocolLib 5.2.0 or later is required! Older versions of ProtocolLib will only partially work or not work at all, and are therefore not recommended.");
getLogger().logError("If you want to enable the plugin anyway, add `i-know-what-i-am-doing: true` to Triton's config.yml.");
return false;
}
Expand Down

0 comments on commit 9219770

Please sign in to comment.