diff --git a/gateway/EaglercraftXBukkitAPI/EaglercraftXBukkitAPI-Latest.jar b/gateway/EaglercraftXBukkitAPI/EaglercraftXBukkitAPI-Latest.jar index 5c6b63e..640488b 100644 Binary files a/gateway/EaglercraftXBukkitAPI/EaglercraftXBukkitAPI-Latest.jar and b/gateway/EaglercraftXBukkitAPI/EaglercraftXBukkitAPI-Latest.jar differ diff --git a/gateway/EaglercraftXBukkitAPI/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/bukkit_rpc_helper/EaglerXBukkitAPIListener.java b/gateway/EaglercraftXBukkitAPI/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/bukkit_rpc_helper/EaglerXBukkitAPIListener.java index 29d5f8e..a0eabcc 100644 --- a/gateway/EaglercraftXBukkitAPI/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/bukkit_rpc_helper/EaglerXBukkitAPIListener.java +++ b/gateway/EaglercraftXBukkitAPI/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/bukkit_rpc_helper/EaglerXBukkitAPIListener.java @@ -34,16 +34,28 @@ public class EaglerXBukkitAPIListener implements Listener, PluginMessageListener @Override public void onPluginMessageReceived(String channel, Player player, byte[] data) { - if(EaglerBackendRPCProtocol.CHANNEL_NAME.equals(channel)) { - PlayerDataObj dataObj = PlayerDataObj.getForPlayer(player); + PlayerDataObj dataObj; + switch(channel) { + case EaglerBackendRPCProtocol.CHANNEL_NAME: + case EaglerBackendRPCProtocol.CHANNEL_NAME_MODERN: + dataObj = PlayerDataObj.getForPlayer(player); if(dataObj != null) { dataObj.firePluginMsgRecievedInternal(data); } - }else if(EaglerBackendRPCProtocol.CHANNEL_NAME_READY.equals(channel)) { - PlayerDataObj dataObj = PlayerDataObj.getForPlayer(player); + break; + case EaglerBackendRPCProtocol.CHANNEL_NAME_READY: + dataObj = PlayerDataObj.getForPlayer(player); if(dataObj != null) { - dataObj.firePluginReadyMsgRecieved(); + dataObj.firePluginReadyMsgRecieved(false); } + break; + case EaglerBackendRPCProtocol.CHANNEL_NAME_READY_MODERN: + dataObj = PlayerDataObj.getForPlayer(player); + if(dataObj != null) { + dataObj.firePluginReadyMsgRecieved(true); + } + default: + break; } } diff --git a/gateway/EaglercraftXBukkitAPI/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/bukkit_rpc_helper/EaglerXBukkitAPIPlugin.java b/gateway/EaglercraftXBukkitAPI/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/bukkit_rpc_helper/EaglerXBukkitAPIPlugin.java index 2a97fa4..8d069ed 100644 --- a/gateway/EaglercraftXBukkitAPI/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/bukkit_rpc_helper/EaglerXBukkitAPIPlugin.java +++ b/gateway/EaglercraftXBukkitAPI/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/bukkit_rpc_helper/EaglerXBukkitAPIPlugin.java @@ -5,8 +5,10 @@ import java.util.Timer; import java.util.TimerTask; import java.util.logging.Logger; +import org.bukkit.Server; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.plugin.messaging.Messenger; import net.lax1dude.eaglercraft.v1_8.plugin.backend_rpc_protocol.EaglerBackendRPCProtocol; import net.lax1dude.eaglercraft.v1_8.plugin.bukkit_rpc_helper.impl.PlayerDataObj; @@ -44,10 +46,30 @@ public class EaglerXBukkitAPIPlugin extends JavaPlugin { @Override public void onEnable() { EaglerXBukkitAPIListener ls = new EaglerXBukkitAPIListener(); - getServer().getPluginManager().registerEvents(ls, this); - getServer().getMessenger().registerOutgoingPluginChannel(this, EaglerBackendRPCProtocol.CHANNEL_NAME); - getServer().getMessenger().registerIncomingPluginChannel(this, EaglerBackendRPCProtocol.CHANNEL_NAME, ls); - getServer().getMessenger().registerIncomingPluginChannel(this, EaglerBackendRPCProtocol.CHANNEL_NAME_READY, ls); + Server svr = getServer(); + svr.getPluginManager().registerEvents(ls, this); + Messenger msgr = svr.getMessenger(); + boolean registerLegacy = !isPost_v1_13(); + if(registerLegacy) { + try { + msgr.registerOutgoingPluginChannel(this, EaglerBackendRPCProtocol.CHANNEL_NAME); + }catch(Throwable t) { + registerLegacy = false; + } + } + if(!registerLegacy) { + getLogger().warning("Note: Only the modernized plugin channel names can be used for this server!"); + getLogger().warning("Make sure to set \"use_modernized_channel_names: true\" in bungee/velocity plugin settings.yml"); + } + msgr.registerOutgoingPluginChannel(this, EaglerBackendRPCProtocol.CHANNEL_NAME_MODERN); + if(registerLegacy) { + msgr.registerIncomingPluginChannel(this, EaglerBackendRPCProtocol.CHANNEL_NAME, ls); + } + msgr.registerIncomingPluginChannel(this, EaglerBackendRPCProtocol.CHANNEL_NAME_MODERN, ls); + if(registerLegacy) { + msgr.registerIncomingPluginChannel(this, EaglerBackendRPCProtocol.CHANNEL_NAME_READY, ls); + } + msgr.registerIncomingPluginChannel(this, EaglerBackendRPCProtocol.CHANNEL_NAME_READY_MODERN, ls); if(timeoutHandler == null) { timeoutHandler = new Timer("EaglerXBukkitAPI: Timeout cleanup thread"); timeoutHandler.scheduleAtFixedRate(new TimerTask() { @@ -83,4 +105,15 @@ public class EaglerXBukkitAPIPlugin extends JavaPlugin { return instance.getLogger(); } + private boolean isPost_v1_13() { + String[] ver = getServer().getVersion().split("[\\.\\-]"); + if(ver.length >= 2) { + try { + return Integer.parseInt(ver[0]) >= 1 || Integer.parseInt(ver[1]) >= 13; + }catch(NumberFormatException ex) { + } + } + return false; + } + } diff --git a/gateway/EaglercraftXBukkitAPI/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/bukkit_rpc_helper/api/IEaglerRPCFuture.java b/gateway/EaglercraftXBukkitAPI/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/bukkit_rpc_helper/api/IEaglerRPCFuture.java index b3b68e7..e31be16 100644 --- a/gateway/EaglercraftXBukkitAPI/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/bukkit_rpc_helper/api/IEaglerRPCFuture.java +++ b/gateway/EaglercraftXBukkitAPI/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/bukkit_rpc_helper/api/IEaglerRPCFuture.java @@ -5,7 +5,8 @@ import java.util.concurrent.Executor; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.MoreExecutors; + +import net.lax1dude.eaglercraft.v1_8.plugin.bukkit_rpc_helper.impl.SameThreadExecutor; /** * Copyright (c) 2024 lax1dude. All Rights Reserved. @@ -24,13 +25,11 @@ import com.google.common.util.concurrent.MoreExecutors; */ public interface IEaglerRPCFuture extends ListenableFuture { - public static final Executor SAME_THREAD_EXECUTOR = MoreExecutors.sameThreadExecutor(); - /** * Warning: Futures.addCallback is recommended! */ default void addListener(Runnable runnable) { - addListener(runnable, SAME_THREAD_EXECUTOR); + addListener(runnable, SameThreadExecutor.SAME_THREAD_EXECUTOR); } default void addCallback(FutureCallback runnable, Executor executor) { @@ -38,7 +37,7 @@ public interface IEaglerRPCFuture extends ListenableFuture { } default void addCallback(FutureCallback runnable) { - Futures.addCallback(this, runnable, SAME_THREAD_EXECUTOR); + Futures.addCallback(this, runnable, SameThreadExecutor.SAME_THREAD_EXECUTOR); } void setExpiresMSFromNow(int millis); diff --git a/gateway/EaglercraftXBukkitAPI/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/bukkit_rpc_helper/impl/EaglerXBukkitImpl.java b/gateway/EaglercraftXBukkitAPI/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/bukkit_rpc_helper/impl/EaglerXBukkitImpl.java index 6db93be..54ffd0b 100644 --- a/gateway/EaglercraftXBukkitAPI/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/bukkit_rpc_helper/impl/EaglerXBukkitImpl.java +++ b/gateway/EaglercraftXBukkitAPI/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/bukkit_rpc_helper/impl/EaglerXBukkitImpl.java @@ -79,13 +79,13 @@ public class EaglerXBukkitImpl implements IEaglerXBukkitAPI { sendHello = data.hasRecievedReady; } if(sendHello) { - sendHelloPacket(player); + sendHelloPacket(data.pluginChName, player); } return data.openFuture; } - protected static void sendHelloPacket(Player player) { - player.sendPluginMessage(EaglerXBukkitAPIPlugin.getEagler(), EaglerBackendRPCProtocol.CHANNEL_NAME, HelloPacketFactory.BASE_HELLO_PACKET); + protected static void sendHelloPacket(String channel, Player player) { + player.sendPluginMessage(EaglerXBukkitAPIPlugin.getEagler(), channel, HelloPacketFactory.BASE_HELLO_PACKET); } protected static EaglerXBukkitImpl createFromHandshakeInternal(PlayerDataObj playerDataObj, SPacketRPCEnabledSuccess pkt) { @@ -362,7 +362,7 @@ public class EaglerXBukkitImpl implements IEaglerXBukkitAPI { .warning("[" + playerObj.getName() + "] Packet type " + packet.getClass().getSimpleName() + " was the wrong length after serialization: " + ret.length + " != " + len); } - playerObj.sendPluginMessage(EaglerXBukkitAPIPlugin.getEagler(), EaglerBackendRPCProtocol.CHANNEL_NAME, ret); + playerObj.sendPluginMessage(EaglerXBukkitAPIPlugin.getEagler(), playerDataObj.pluginChName, ret); } protected EaglerBackendRPCPacket decodePacket(byte[] data) throws IOException { diff --git a/gateway/EaglercraftXBukkitAPI/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/bukkit_rpc_helper/impl/PlayerDataObj.java b/gateway/EaglercraftXBukkitAPI/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/bukkit_rpc_helper/impl/PlayerDataObj.java index 13b3c17..f1e4e35 100644 --- a/gateway/EaglercraftXBukkitAPI/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/bukkit_rpc_helper/impl/PlayerDataObj.java +++ b/gateway/EaglercraftXBukkitAPI/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/bukkit_rpc_helper/impl/PlayerDataObj.java @@ -41,6 +41,8 @@ public class PlayerDataObj { public final Player player; + public String pluginChName = null; + public volatile boolean hasRecievedReady = false; public volatile boolean isSupported = true; public volatile EaglerXBukkitImpl currentAPI = null; @@ -60,12 +62,13 @@ public class PlayerDataObj { this.player = player; } - public void firePluginReadyMsgRecieved() { + public void firePluginReadyMsgRecieved(boolean modern) { synchronized(this) { if(!hasRecievedReady) { hasRecievedReady = true; + pluginChName = modern ? EaglerBackendRPCProtocol.CHANNEL_NAME_MODERN : EaglerBackendRPCProtocol.CHANNEL_NAME; if(openFuture != null) { - EaglerXBukkitImpl.sendHelloPacket(player); + EaglerXBukkitImpl.sendHelloPacket(pluginChName, player); } } } @@ -121,7 +124,7 @@ public class PlayerDataObj { if(pkt.selectedRPCProtocol != EaglerBackendRPCProtocol.V1.vers) { try { // send raw CPacketRPCDisabled - player.sendPluginMessage(EaglerXBukkitAPIPlugin.getEagler(), EaglerBackendRPCProtocol.CHANNEL_NAME, new byte[] { 0x03 }); + player.sendPluginMessage(EaglerXBukkitAPIPlugin.getEagler(), pluginChName, new byte[] { 0x03 }); }finally { apiFuture.fireExceptionInternal(new EaglerRPCException("Server tried to select an unsupported protocol: " + pkt.selectedRPCProtocol)); } diff --git a/gateway/EaglercraftXBukkitAPI/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/bukkit_rpc_helper/impl/SameThreadExecutor.java b/gateway/EaglercraftXBukkitAPI/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/bukkit_rpc_helper/impl/SameThreadExecutor.java new file mode 100644 index 0000000..3fe12d2 --- /dev/null +++ b/gateway/EaglercraftXBukkitAPI/src/main/java/net/lax1dude/eaglercraft/v1_8/plugin/bukkit_rpc_helper/impl/SameThreadExecutor.java @@ -0,0 +1,40 @@ +package net.lax1dude.eaglercraft.v1_8.plugin.bukkit_rpc_helper.impl; + +import java.util.concurrent.Executor; + +import com.google.common.util.concurrent.MoreExecutors; + +/** + * Copyright (c) 2024 lax1dude. All Rights Reserved. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +public class SameThreadExecutor { + + public static final Executor SAME_THREAD_EXECUTOR; + + static { + Executor fuck; + try { + fuck = (Executor) MoreExecutors.class.getDeclaredMethod("newDirectExecutorService").invoke(null); + }catch(Throwable t) { + try { + fuck = (Executor) MoreExecutors.class.getDeclaredMethod("sameThreadExecutor").invoke(null); + }catch(Throwable t2) { + throw new RuntimeException("Google fucked up!", t2); + } + } + SAME_THREAD_EXECUTOR = fuck; + } + +} diff --git a/gateway/EaglercraftXBukkitAPI/src/main/resources/plugin.yml b/gateway/EaglercraftXBukkitAPI/src/main/resources/plugin.yml index 58d06d1..8faf609 100644 --- a/gateway/EaglercraftXBukkitAPI/src/main/resources/plugin.yml +++ b/gateway/EaglercraftXBukkitAPI/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: EaglercraftXBukkitAPI -version: 1.0.0 +version: 1.0.1 main: net.lax1dude.eaglercraft.v1_8.plugin.bukkit_rpc_helper.EaglerXBukkitAPIPlugin description: Official EaglercraftX API for Bukkit servers author: lax1dude diff --git a/gateway/backend-rpc-protocol/src/backend-rpc-protocol/java/net/lax1dude/eaglercraft/v1_8/plugin/backend_rpc_protocol/EaglerBackendRPCProtocol.java b/gateway/backend-rpc-protocol/src/backend-rpc-protocol/java/net/lax1dude/eaglercraft/v1_8/plugin/backend_rpc_protocol/EaglerBackendRPCProtocol.java index b1f4e82..21927d4 100644 --- a/gateway/backend-rpc-protocol/src/backend-rpc-protocol/java/net/lax1dude/eaglercraft/v1_8/plugin/backend_rpc_protocol/EaglerBackendRPCProtocol.java +++ b/gateway/backend-rpc-protocol/src/backend-rpc-protocol/java/net/lax1dude/eaglercraft/v1_8/plugin/backend_rpc_protocol/EaglerBackendRPCProtocol.java @@ -63,6 +63,9 @@ public enum EaglerBackendRPCProtocol { public static final String CHANNEL_NAME = "EAG|1.8-RPC"; public static final String CHANNEL_NAME_READY = "EAG|1.8-Ready"; + public static final String CHANNEL_NAME_MODERN = "eagler:1-8-rpc"; + public static final String CHANNEL_NAME_READY_MODERN = "eagler:1-8-ready"; + public static final int CLIENT_TO_SERVER = 0; public static final int SERVER_TO_CLIENT = 1;