Don't use google commons in Util#requiresNettyChannelMetadata (#2907)

* Improve Util#requiresNettyChannelMetadata

* Fix comment

* Don't use google commons in Util#requiresNettyChannelMetadata
This commit is contained in:
Peridot 2022-10-03 03:12:39 +02:00 committed by GitHub
parent 838aa3019b
commit 2a4f222c3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,6 +7,7 @@ import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.StreamSupport;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -345,20 +346,18 @@ public class Util {
if (version == null) if (version == null)
return REQUIRES_CHANNEL_METADATA = false; return REQUIRES_CHANNEL_METADATA = false;
try { try {
Integer[] parts = Iterables.toArray( Integer[] parts = StreamSupport.stream(Splitter.on('.').split(version.artifactVersion()).spliterator(), false).map(string -> {
Iterables.transform(Splitter.on('.').split(version.artifactVersion()), string -> { // Newer versions of netty use suffix (like .Final) that can't be parsed to Integer
// Newer versions of netty use suffix (like .Final) that can't be parsed to Integer try {
try { return Integer.parseInt(string);
return Integer.parseInt(string); } catch (NumberFormatException e) {
} catch (NumberFormatException e) { return -1;
return -1; }
} }).toArray(Integer[]::new);
}),
int.class);
int major = parts[0]; int major = parts[0];
int minor = parts[1]; int minor = parts[1];
int patch = parts[2]; int patch = parts[2];
return REQUIRES_CHANNEL_METADATA = major >= 5 || major == 4 && minor > 1 || patch >= 64; return REQUIRES_CHANNEL_METADATA = major >= 5 || major == 4 && (minor > 1 || patch >= 64);
} catch (Throwable t) { } catch (Throwable t) {
t.printStackTrace(); t.printStackTrace();
return REQUIRES_CHANNEL_METADATA = true; return REQUIRES_CHANNEL_METADATA = true;