Skip to content

Commit

Permalink
Plugins seem to mess with netty versioning so just always create meta…
Browse files Browse the repository at this point in the history
…data
  • Loading branch information
fullwall committed Dec 14, 2022
1 parent ab458f4 commit 8f29e6f
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 34 deletions.
3 changes: 1 addition & 2 deletions main/src/main/java/net/citizensnpcs/util/EmptyChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import io.netty.channel.ChannelOutboundBuffer;
import io.netty.channel.DefaultChannelConfig;
import io.netty.channel.EventLoop;
import net.citizensnpcs.util.Util;

public class EmptyChannel extends AbstractChannel {
private final ChannelConfig config = new DefaultChannelConfig(this);
Expand Down Expand Up @@ -66,7 +65,7 @@ protected SocketAddress localAddress0() {

@Override
public ChannelMetadata metadata() {
return Util.requiresNettyChannelMetadata() ? new ChannelMetadata(true) : null;
return new ChannelMetadata(true);
}

@Override
Expand Down
32 changes: 0 additions & 32 deletions main/src/main/java/net/citizensnpcs/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.Set;
import java.util.UUID;
import java.util.function.Function;
import java.util.stream.StreamSupport;

import org.bukkit.Bukkit;
import org.bukkit.Location;
Expand All @@ -32,7 +31,6 @@
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;

import io.netty.util.Version;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.event.NPCCollisionEvent;
import net.citizensnpcs.api.event.NPCPushEvent;
Expand Down Expand Up @@ -342,36 +340,6 @@ public static String prettyPrintLocation(Location to) {
TWO_DIGIT_DECIMAL.format(to.getYaw()), TWO_DIGIT_DECIMAL.format(to.getPitch()));
}

public static boolean requiresNettyChannelMetadata() {
if (REQUIRES_CHANNEL_METADATA != null)
return REQUIRES_CHANNEL_METADATA;

Version version = Version.identify().get("netty-common");
if (version == null) {
version = Version.identify().get("netty-all");
}
if (version == null)
return REQUIRES_CHANNEL_METADATA = true;
try {
Integer[] parts = StreamSupport
.stream(Splitter.on('.').split(version.artifactVersion()).spliterator(), false).map(string -> {
// Newer versions of netty use suffix (like .Final) that can't be parsed to Integer
try {
return Integer.parseInt(string);
} catch (NumberFormatException e) {
return -1;
}
}).toArray(Integer[]::new);
int major = parts[0];
int minor = parts[1];
int patch = parts[2];
return REQUIRES_CHANNEL_METADATA = major >= 5 || major == 4 && (minor > 1 || patch >= 25);
} catch (Throwable t) {
t.printStackTrace();
return REQUIRES_CHANNEL_METADATA = true;
}
}

public static void runCommand(NPC npc, Player clicker, String command, boolean op, boolean player) {
List<String> split = Splitter.on(' ').omitEmptyStrings().trimResults().limit(2).splitToList(command);
String bungeeServer = split.size() == 2 && split.get(0).equalsIgnoreCase("server") ? split.get(1) : null;
Expand Down

0 comments on commit 8f29e6f

Please sign in to comment.