From 563df955611da0c30418fc75249dd294e5c6c25a Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 27 Jan 2024 11:15:30 +0100 Subject: [PATCH] Attempt to fix packet injector issues --- .../nms/v1_10_R1/VersionNMSManager.java | 15 +++++++++++++-- .../nms/v1_11_R1/VersionNMSManager.java | 15 +++++++++++++-- .../nms/v1_12_R1/VersionNMSManager.java | 15 +++++++++++++-- .../nms/v1_13_R2/VersionNMSManager.java | 15 +++++++++++++-- .../nms/v1_14_R1/VersionNMSManager.java | 15 +++++++++++++-- .../nms/v1_15_R1/VersionNMSManager.java | 15 +++++++++++++-- .../nms/v1_16_R3/VersionNMSManager.java | 15 +++++++++++++-- .../nms/v1_17_R1/VersionNMSManager.java | 15 +++++++++++++-- .../nms/v1_18_R1/VersionNMSManager.java | 15 +++++++++++++-- .../nms/v1_18_R2/VersionNMSManager.java | 15 +++++++++++++-- .../nms/v1_19_R1/VersionNMSManager.java | 15 +++++++++++++-- .../nms/v1_19_R2/VersionNMSManager.java | 15 +++++++++++++-- .../nms/v1_19_R3/VersionNMSManager.java | 15 +++++++++++++-- .../nms/v1_20_R1/VersionNMSManager.java | 15 +++++++++++++-- .../nms/v1_20_R2/VersionNMSManager.java | 15 +++++++++++++-- .../nms/v1_20_R3/VersionNMSManager.java | 15 +++++++++++++-- .../nms/v1_8_R3/VersionNMSManager.java | 15 +++++++++++++-- .../nms/v1_9_R2/VersionNMSManager.java | 15 +++++++++++++-- 18 files changed, 234 insertions(+), 36 deletions(-) diff --git a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionNMSManager.java b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionNMSManager.java index f24abff5..fc907751 100644 --- a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionNMSManager.java +++ b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionNMSManager.java @@ -8,6 +8,7 @@ package me.filoghost.holographicdisplays.nms.v1_10_R1; import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelPipeline; +import io.netty.channel.EventLoop; import me.filoghost.fcommons.logging.ErrorCollector; import me.filoghost.fcommons.logging.Log; import me.filoghost.fcommons.reflection.ReflectField; @@ -115,8 +116,12 @@ public class VersionNMSManager implements NMSManager { PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; NetworkManager networkManager = playerConnection.a(); Channel channel = networkManager.channel; + if (channel == null) { + return; + } + EventLoop eventLoop = channel.eventLoop(); - channel.eventLoop().execute(() -> { + Runnable safeModifierTask = () -> { if (!player.isOnline()) { return; } @@ -125,7 +130,13 @@ public class VersionNMSManager implements NMSManager { } catch (Exception e) { Log.warning(NMSErrors.EXCEPTION_MODIFYING_CHANNEL_PIPELINE, e); } - }); + }; + + if (eventLoop.inEventLoop()) { + safeModifierTask.run(); + } else { + eventLoop.execute(safeModifierTask); + } } } diff --git a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionNMSManager.java b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionNMSManager.java index aa919db6..fa35801f 100644 --- a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionNMSManager.java +++ b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionNMSManager.java @@ -8,6 +8,7 @@ package me.filoghost.holographicdisplays.nms.v1_11_R1; import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelPipeline; +import io.netty.channel.EventLoop; import me.filoghost.fcommons.logging.ErrorCollector; import me.filoghost.fcommons.logging.Log; import me.filoghost.fcommons.reflection.ReflectField; @@ -115,8 +116,12 @@ public class VersionNMSManager implements NMSManager { PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; NetworkManager networkManager = playerConnection.a(); Channel channel = networkManager.channel; + if (channel == null) { + return; + } + EventLoop eventLoop = channel.eventLoop(); - channel.eventLoop().execute(() -> { + Runnable safeModifierTask = () -> { if (!player.isOnline()) { return; } @@ -125,7 +130,13 @@ public class VersionNMSManager implements NMSManager { } catch (Exception e) { Log.warning(NMSErrors.EXCEPTION_MODIFYING_CHANNEL_PIPELINE, e); } - }); + }; + + if (eventLoop.inEventLoop()) { + safeModifierTask.run(); + } else { + eventLoop.execute(safeModifierTask); + } } } diff --git a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionNMSManager.java b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionNMSManager.java index 13bedaca..a7ecec3d 100644 --- a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionNMSManager.java +++ b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionNMSManager.java @@ -8,6 +8,7 @@ package me.filoghost.holographicdisplays.nms.v1_12_R1; import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelPipeline; +import io.netty.channel.EventLoop; import me.filoghost.fcommons.logging.ErrorCollector; import me.filoghost.fcommons.logging.Log; import me.filoghost.fcommons.reflection.ReflectField; @@ -115,8 +116,12 @@ public class VersionNMSManager implements NMSManager { PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; NetworkManager networkManager = playerConnection.a(); Channel channel = networkManager.channel; + if (channel == null) { + return; + } + EventLoop eventLoop = channel.eventLoop(); - channel.eventLoop().execute(() -> { + Runnable safeModifierTask = () -> { if (!player.isOnline()) { return; } @@ -125,7 +130,13 @@ public class VersionNMSManager implements NMSManager { } catch (Exception e) { Log.warning(NMSErrors.EXCEPTION_MODIFYING_CHANNEL_PIPELINE, e); } - }); + }; + + if (eventLoop.inEventLoop()) { + safeModifierTask.run(); + } else { + eventLoop.execute(safeModifierTask); + } } } diff --git a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionNMSManager.java b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionNMSManager.java index 1c506707..c8d89af9 100644 --- a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionNMSManager.java +++ b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionNMSManager.java @@ -8,6 +8,7 @@ package me.filoghost.holographicdisplays.nms.v1_13_R2; import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelPipeline; +import io.netty.channel.EventLoop; import me.filoghost.fcommons.logging.ErrorCollector; import me.filoghost.fcommons.logging.Log; import me.filoghost.fcommons.reflection.ReflectField; @@ -115,8 +116,12 @@ public class VersionNMSManager implements NMSManager { PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; NetworkManager networkManager = playerConnection.a(); Channel channel = networkManager.channel; + if (channel == null) { + return; + } + EventLoop eventLoop = channel.eventLoop(); - channel.eventLoop().execute(() -> { + Runnable safeModifierTask = () -> { if (!player.isOnline()) { return; } @@ -125,7 +130,13 @@ public class VersionNMSManager implements NMSManager { } catch (Exception e) { Log.warning(NMSErrors.EXCEPTION_MODIFYING_CHANNEL_PIPELINE, e); } - }); + }; + + if (eventLoop.inEventLoop()) { + safeModifierTask.run(); + } else { + eventLoop.execute(safeModifierTask); + } } } diff --git a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionNMSManager.java b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionNMSManager.java index 94a7cffe..999cb4df 100644 --- a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionNMSManager.java +++ b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionNMSManager.java @@ -8,6 +8,7 @@ package me.filoghost.holographicdisplays.nms.v1_14_R1; import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelPipeline; +import io.netty.channel.EventLoop; import me.filoghost.fcommons.logging.ErrorCollector; import me.filoghost.fcommons.logging.Log; import me.filoghost.fcommons.reflection.ReflectField; @@ -100,8 +101,12 @@ public class VersionNMSManager implements NMSManager { PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; NetworkManager networkManager = playerConnection.a(); Channel channel = networkManager.channel; + if (channel == null) { + return; + } + EventLoop eventLoop = channel.eventLoop(); - channel.eventLoop().execute(() -> { + Runnable safeModifierTask = () -> { if (!player.isOnline()) { return; } @@ -110,7 +115,13 @@ public class VersionNMSManager implements NMSManager { } catch (Exception e) { Log.warning(NMSErrors.EXCEPTION_MODIFYING_CHANNEL_PIPELINE, e); } - }); + }; + + if (eventLoop.inEventLoop()) { + safeModifierTask.run(); + } else { + eventLoop.execute(safeModifierTask); + } } } diff --git a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionNMSManager.java b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionNMSManager.java index ec6dd8b7..31dd047b 100644 --- a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionNMSManager.java +++ b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionNMSManager.java @@ -8,6 +8,7 @@ package me.filoghost.holographicdisplays.nms.v1_15_R1; import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelPipeline; +import io.netty.channel.EventLoop; import me.filoghost.fcommons.logging.ErrorCollector; import me.filoghost.fcommons.logging.Log; import me.filoghost.fcommons.reflection.ReflectField; @@ -100,8 +101,12 @@ public class VersionNMSManager implements NMSManager { PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; NetworkManager networkManager = playerConnection.a(); Channel channel = networkManager.channel; + if (channel == null) { + return; + } + EventLoop eventLoop = channel.eventLoop(); - channel.eventLoop().execute(() -> { + Runnable safeModifierTask = () -> { if (!player.isOnline()) { return; } @@ -110,7 +115,13 @@ public class VersionNMSManager implements NMSManager { } catch (Exception e) { Log.warning(NMSErrors.EXCEPTION_MODIFYING_CHANNEL_PIPELINE, e); } - }); + }; + + if (eventLoop.inEventLoop()) { + safeModifierTask.run(); + } else { + eventLoop.execute(safeModifierTask); + } } } diff --git a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionNMSManager.java b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionNMSManager.java index 79dbc0ab..4d7a9681 100644 --- a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionNMSManager.java +++ b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionNMSManager.java @@ -8,6 +8,7 @@ package me.filoghost.holographicdisplays.nms.v1_16_R3; import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelPipeline; +import io.netty.channel.EventLoop; import me.filoghost.fcommons.logging.ErrorCollector; import me.filoghost.fcommons.logging.Log; import me.filoghost.fcommons.reflection.ReflectField; @@ -100,8 +101,12 @@ public class VersionNMSManager implements NMSManager { PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; NetworkManager networkManager = playerConnection.a(); Channel channel = networkManager.channel; + if (channel == null) { + return; + } + EventLoop eventLoop = channel.eventLoop(); - channel.eventLoop().execute(() -> { + Runnable safeModifierTask = () -> { if (!player.isOnline()) { return; } @@ -110,7 +115,13 @@ public class VersionNMSManager implements NMSManager { } catch (Exception e) { Log.warning(NMSErrors.EXCEPTION_MODIFYING_CHANNEL_PIPELINE, e); } - }); + }; + + if (eventLoop.inEventLoop()) { + safeModifierTask.run(); + } else { + eventLoop.execute(safeModifierTask); + } } } diff --git a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionNMSManager.java b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionNMSManager.java index 81ec682d..f87c094c 100644 --- a/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionNMSManager.java +++ b/nms/v1_17_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_17_R1/VersionNMSManager.java @@ -8,6 +8,7 @@ package me.filoghost.holographicdisplays.nms.v1_17_R1; import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelPipeline; +import io.netty.channel.EventLoop; import me.filoghost.fcommons.logging.ErrorCollector; import me.filoghost.fcommons.logging.Log; import me.filoghost.fcommons.reflection.ReflectField; @@ -99,8 +100,12 @@ public class VersionNMSManager implements NMSManager { PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().b; NetworkManager networkManager = playerConnection.a(); Channel channel = networkManager.k; + if (channel == null) { + return; + } + EventLoop eventLoop = channel.eventLoop(); - channel.eventLoop().execute(() -> { + Runnable safeModifierTask = () -> { if (!player.isOnline()) { return; } @@ -109,7 +114,13 @@ public class VersionNMSManager implements NMSManager { } catch (Exception e) { Log.warning(NMSErrors.EXCEPTION_MODIFYING_CHANNEL_PIPELINE, e); } - }); + }; + + if (eventLoop.inEventLoop()) { + safeModifierTask.run(); + } else { + eventLoop.execute(safeModifierTask); + } } } diff --git a/nms/v1_18_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R1/VersionNMSManager.java b/nms/v1_18_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R1/VersionNMSManager.java index 561f908c..b4b06865 100644 --- a/nms/v1_18_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R1/VersionNMSManager.java +++ b/nms/v1_18_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R1/VersionNMSManager.java @@ -8,6 +8,7 @@ package me.filoghost.holographicdisplays.nms.v1_18_R1; import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelPipeline; +import io.netty.channel.EventLoop; import me.filoghost.fcommons.logging.ErrorCollector; import me.filoghost.fcommons.logging.Log; import me.filoghost.fcommons.reflection.ReflectField; @@ -99,8 +100,12 @@ public class VersionNMSManager implements NMSManager { PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().b; NetworkManager networkManager = playerConnection.a(); Channel channel = networkManager.k; + if (channel == null) { + return; + } + EventLoop eventLoop = channel.eventLoop(); - channel.eventLoop().execute(() -> { + Runnable safeModifierTask = () -> { if (!player.isOnline()) { return; } @@ -109,7 +114,13 @@ public class VersionNMSManager implements NMSManager { } catch (Exception e) { Log.warning(NMSErrors.EXCEPTION_MODIFYING_CHANNEL_PIPELINE, e); } - }); + }; + + if (eventLoop.inEventLoop()) { + safeModifierTask.run(); + } else { + eventLoop.execute(safeModifierTask); + } } } diff --git a/nms/v1_18_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R2/VersionNMSManager.java b/nms/v1_18_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R2/VersionNMSManager.java index 34df8126..b8f39fb1 100644 --- a/nms/v1_18_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R2/VersionNMSManager.java +++ b/nms/v1_18_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_18_R2/VersionNMSManager.java @@ -8,6 +8,7 @@ package me.filoghost.holographicdisplays.nms.v1_18_R2; import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelPipeline; +import io.netty.channel.EventLoop; import me.filoghost.fcommons.logging.ErrorCollector; import me.filoghost.fcommons.logging.Log; import me.filoghost.fcommons.reflection.ReflectField; @@ -99,8 +100,12 @@ public class VersionNMSManager implements NMSManager { PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().b; NetworkManager networkManager = playerConnection.a(); Channel channel = networkManager.m; + if (channel == null) { + return; + } + EventLoop eventLoop = channel.eventLoop(); - channel.eventLoop().execute(() -> { + Runnable safeModifierTask = () -> { if (!player.isOnline()) { return; } @@ -109,7 +114,13 @@ public class VersionNMSManager implements NMSManager { } catch (Exception e) { Log.warning(NMSErrors.EXCEPTION_MODIFYING_CHANNEL_PIPELINE, e); } - }); + }; + + if (eventLoop.inEventLoop()) { + safeModifierTask.run(); + } else { + eventLoop.execute(safeModifierTask); + } } } diff --git a/nms/v1_19_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R1/VersionNMSManager.java b/nms/v1_19_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R1/VersionNMSManager.java index d368f26b..de1461a8 100644 --- a/nms/v1_19_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R1/VersionNMSManager.java +++ b/nms/v1_19_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R1/VersionNMSManager.java @@ -8,6 +8,7 @@ package me.filoghost.holographicdisplays.nms.v1_19_R1; import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelPipeline; +import io.netty.channel.EventLoop; import me.filoghost.fcommons.logging.ErrorCollector; import me.filoghost.fcommons.logging.Log; import me.filoghost.fcommons.reflection.ReflectField; @@ -99,8 +100,12 @@ public class VersionNMSManager implements NMSManager { PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().b; NetworkManager networkManager = playerConnection.a(); Channel channel = networkManager.m; + if (channel == null) { + return; + } + EventLoop eventLoop = channel.eventLoop(); - channel.eventLoop().execute(() -> { + Runnable safeModifierTask = () -> { if (!player.isOnline()) { return; } @@ -109,7 +114,13 @@ public class VersionNMSManager implements NMSManager { } catch (Exception e) { Log.warning(NMSErrors.EXCEPTION_MODIFYING_CHANNEL_PIPELINE, e); } - }); + }; + + if (eventLoop.inEventLoop()) { + safeModifierTask.run(); + } else { + eventLoop.execute(safeModifierTask); + } } } diff --git a/nms/v1_19_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R2/VersionNMSManager.java b/nms/v1_19_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R2/VersionNMSManager.java index a230a91a..6b636a4e 100644 --- a/nms/v1_19_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R2/VersionNMSManager.java +++ b/nms/v1_19_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R2/VersionNMSManager.java @@ -8,6 +8,7 @@ package me.filoghost.holographicdisplays.nms.v1_19_R2; import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelPipeline; +import io.netty.channel.EventLoop; import me.filoghost.fcommons.logging.ErrorCollector; import me.filoghost.fcommons.logging.Log; import me.filoghost.fcommons.reflection.ReflectField; @@ -99,8 +100,12 @@ public class VersionNMSManager implements NMSManager { PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().b; NetworkManager networkManager = playerConnection.a(); Channel channel = networkManager.m; + if (channel == null) { + return; + } + EventLoop eventLoop = channel.eventLoop(); - channel.eventLoop().execute(() -> { + Runnable safeModifierTask = () -> { if (!player.isOnline()) { return; } @@ -109,7 +114,13 @@ public class VersionNMSManager implements NMSManager { } catch (Exception e) { Log.warning(NMSErrors.EXCEPTION_MODIFYING_CHANNEL_PIPELINE, e); } - }); + }; + + if (eventLoop.inEventLoop()) { + safeModifierTask.run(); + } else { + eventLoop.execute(safeModifierTask); + } } } diff --git a/nms/v1_19_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R3/VersionNMSManager.java b/nms/v1_19_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R3/VersionNMSManager.java index 420d4e27..ff6b4616 100644 --- a/nms/v1_19_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R3/VersionNMSManager.java +++ b/nms/v1_19_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_19_R3/VersionNMSManager.java @@ -8,6 +8,7 @@ package me.filoghost.holographicdisplays.nms.v1_19_R3; import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelPipeline; +import io.netty.channel.EventLoop; import me.filoghost.fcommons.logging.ErrorCollector; import me.filoghost.fcommons.logging.Log; import me.filoghost.fcommons.reflection.ReflectField; @@ -106,8 +107,12 @@ public class VersionNMSManager implements NMSManager { return; } Channel channel = networkManager.m; + if (channel == null) { + return; + } + EventLoop eventLoop = channel.eventLoop(); - channel.eventLoop().execute(() -> { + Runnable safeModifierTask = () -> { if (!player.isOnline()) { return; } @@ -116,7 +121,13 @@ public class VersionNMSManager implements NMSManager { } catch (Exception e) { Log.warning(NMSErrors.EXCEPTION_MODIFYING_CHANNEL_PIPELINE, e); } - }); + }; + + if (eventLoop.inEventLoop()) { + safeModifierTask.run(); + } else { + eventLoop.execute(safeModifierTask); + } } } diff --git a/nms/v1_20_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_20_R1/VersionNMSManager.java b/nms/v1_20_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_20_R1/VersionNMSManager.java index b2cd2819..1c281b27 100644 --- a/nms/v1_20_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_20_R1/VersionNMSManager.java +++ b/nms/v1_20_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_20_R1/VersionNMSManager.java @@ -8,6 +8,7 @@ package me.filoghost.holographicdisplays.nms.v1_20_R1; import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelPipeline; +import io.netty.channel.EventLoop; import me.filoghost.fcommons.logging.ErrorCollector; import me.filoghost.fcommons.logging.Log; import me.filoghost.fcommons.reflection.ReflectField; @@ -106,8 +107,12 @@ public class VersionNMSManager implements NMSManager { return; } Channel channel = networkManager.m; + if (channel == null) { + return; + } + EventLoop eventLoop = channel.eventLoop(); - channel.eventLoop().execute(() -> { + Runnable safeModifierTask = () -> { if (!player.isOnline()) { return; } @@ -116,7 +121,13 @@ public class VersionNMSManager implements NMSManager { } catch (Exception e) { Log.warning(NMSErrors.EXCEPTION_MODIFYING_CHANNEL_PIPELINE, e); } - }); + }; + + if (eventLoop.inEventLoop()) { + safeModifierTask.run(); + } else { + eventLoop.execute(safeModifierTask); + } } } diff --git a/nms/v1_20_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_20_R2/VersionNMSManager.java b/nms/v1_20_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_20_R2/VersionNMSManager.java index b5c86a5d..8f9a7223 100644 --- a/nms/v1_20_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_20_R2/VersionNMSManager.java +++ b/nms/v1_20_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_20_R2/VersionNMSManager.java @@ -8,6 +8,7 @@ package me.filoghost.holographicdisplays.nms.v1_20_R2; import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelPipeline; +import io.netty.channel.EventLoop; import me.filoghost.fcommons.logging.ErrorCollector; import me.filoghost.fcommons.logging.Log; import me.filoghost.fcommons.reflection.ReflectField; @@ -107,8 +108,12 @@ public class VersionNMSManager implements NMSManager { return; } Channel channel = networkManager.n; + if (channel == null) { + return; + } + EventLoop eventLoop = channel.eventLoop(); - channel.eventLoop().execute(() -> { + Runnable safeModifierTask = () -> { if (!player.isOnline()) { return; } @@ -117,7 +122,13 @@ public class VersionNMSManager implements NMSManager { } catch (Exception e) { Log.warning(NMSErrors.EXCEPTION_MODIFYING_CHANNEL_PIPELINE, e); } - }); + }; + + if (eventLoop.inEventLoop()) { + safeModifierTask.run(); + } else { + eventLoop.execute(safeModifierTask); + } } } diff --git a/nms/v1_20_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_20_R3/VersionNMSManager.java b/nms/v1_20_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_20_R3/VersionNMSManager.java index 7a5a9027..9fb8bc60 100644 --- a/nms/v1_20_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_20_R3/VersionNMSManager.java +++ b/nms/v1_20_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_20_R3/VersionNMSManager.java @@ -8,6 +8,7 @@ package me.filoghost.holographicdisplays.nms.v1_20_R3; import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelPipeline; +import io.netty.channel.EventLoop; import me.filoghost.fcommons.logging.ErrorCollector; import me.filoghost.fcommons.logging.Log; import me.filoghost.fcommons.reflection.ReflectField; @@ -107,8 +108,12 @@ public class VersionNMSManager implements NMSManager { return; } Channel channel = networkManager.n; + if (channel == null) { + return; + } + EventLoop eventLoop = channel.eventLoop(); - channel.eventLoop().execute(() -> { + Runnable safeModifierTask = () -> { if (!player.isOnline()) { return; } @@ -117,7 +122,13 @@ public class VersionNMSManager implements NMSManager { } catch (Exception e) { Log.warning(NMSErrors.EXCEPTION_MODIFYING_CHANNEL_PIPELINE, e); } - }); + }; + + if (eventLoop.inEventLoop()) { + safeModifierTask.run(); + } else { + eventLoop.execute(safeModifierTask); + } } } diff --git a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionNMSManager.java b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionNMSManager.java index e9ded51c..611779a9 100644 --- a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionNMSManager.java +++ b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionNMSManager.java @@ -8,6 +8,7 @@ package me.filoghost.holographicdisplays.nms.v1_8_R3; import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelPipeline; +import io.netty.channel.EventLoop; import me.filoghost.fcommons.logging.ErrorCollector; import me.filoghost.fcommons.logging.Log; import me.filoghost.fcommons.reflection.ReflectField; @@ -112,8 +113,12 @@ public class VersionNMSManager implements NMSManager { PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; NetworkManager networkManager = playerConnection.a(); Channel channel = networkManager.channel; + if (channel == null) { + return; + } + EventLoop eventLoop = channel.eventLoop(); - channel.eventLoop().execute(() -> { + Runnable safeModifierTask = () -> { if (!player.isOnline()) { return; } @@ -122,7 +127,13 @@ public class VersionNMSManager implements NMSManager { } catch (Exception e) { Log.warning(NMSErrors.EXCEPTION_MODIFYING_CHANNEL_PIPELINE, e); } - }); + }; + + if (eventLoop.inEventLoop()) { + safeModifierTask.run(); + } else { + eventLoop.execute(safeModifierTask); + } } } diff --git a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionNMSManager.java b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionNMSManager.java index 8f2a0ada..bc56d10a 100644 --- a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionNMSManager.java +++ b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionNMSManager.java @@ -8,6 +8,7 @@ package me.filoghost.holographicdisplays.nms.v1_9_R2; import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelPipeline; +import io.netty.channel.EventLoop; import me.filoghost.fcommons.logging.ErrorCollector; import me.filoghost.fcommons.logging.Log; import me.filoghost.fcommons.reflection.ReflectField; @@ -115,8 +116,12 @@ public class VersionNMSManager implements NMSManager { PlayerConnection playerConnection = ((CraftPlayer) player).getHandle().playerConnection; NetworkManager networkManager = playerConnection.a(); Channel channel = networkManager.channel; + if (channel == null) { + return; + } + EventLoop eventLoop = channel.eventLoop(); - channel.eventLoop().execute(() -> { + Runnable safeModifierTask = () -> { if (!player.isOnline()) { return; } @@ -125,7 +130,13 @@ public class VersionNMSManager implements NMSManager { } catch (Exception e) { Log.warning(NMSErrors.EXCEPTION_MODIFYING_CHANNEL_PIPELINE, e); } - }); + }; + + if (eventLoop.inEventLoop()) { + safeModifierTask.run(); + } else { + eventLoop.execute(safeModifierTask); + } } }