From 28496e0471237448db017115c769e684ecd76abc Mon Sep 17 00:00:00 2001 From: Daniel Naylor Date: Sun, 21 Dec 2014 14:32:45 +0000 Subject: [PATCH] Add API for getting whether the user is a Forge user. For Minecraft+Forge 1.8 we can detect whether the user is a Forge user before we get the mod list, due to the changes to the initial (not FML|HS) handshake that are now made (which is for vanilla client support). Bungee can exploit this to detect FML clients from the off, but it still does not tell us what the mod list is. Thus, creating this API method for users who simply need to know whether the user is connected via FML is no longer a duplication of the getModList api method. --- .../bungee/api/connection/ProxiedPlayer.java | 19 +++++++++++++++++-- .../java/net/md_5/bungee/UserConnection.java | 6 ++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java b/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java index 4304b1e9a..d4438e51d 100644 --- a/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java +++ b/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java @@ -172,6 +172,20 @@ public interface ProxiedPlayer extends Connection, CommandSender */ void sendTitle(Title title); + /** + * Gets whether this player is using a FML client. + *

+ * This method is only reliable if BungeeCord links Minecraft 1.8 servers + * together, as Bungee can pick up whether a user is a Forge user with the + * initial handshake. If this is used for a 1.7 network, this might return + * false even if the user is a FML user, as Bungee can only + * determine this information if a handshake successfully completes. + *

+ * @return true if it is known that the user is using a FML + * client, false otherwise. + */ + boolean isForgeUser(); + /** * Gets this player's Forge Mod List, if the player has sent this * information during the lifetime of their connection to Bungee. There is @@ -181,7 +195,8 @@ public interface ProxiedPlayer extends Connection, CommandSender *

* Consumers of this API should be aware that an empty mod list does * not indicate that a user is not a Forge user, and so should not - * use this API to check for this - there is no way to tell this reliably. + * use this API to check for this. See the {@link #isForgeUser() + * isForgeUser} method instead. *

*

* Calling this when handling a @@ -189,7 +204,7 @@ public interface ProxiedPlayer extends Connection, CommandSender * place to do so as this event occurs after a FML handshake has completed, * if any has occurred. *

- * + * * @return A {@link Map} of mods, where the key is the name of the mod, and * the value is the version. Returns an empty list if the FML handshake has * not occurred for this {@link ProxiedPlayer} yet. diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java index 936e6845e..4a85f4eb3 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -519,6 +519,12 @@ public final class UserConnection implements ProxiedPlayer return ( locale == null && settings != null ) ? locale = Locale.forLanguageTag( settings.getLocale().replaceAll( "_", "-" ) ) : locale; } + @Override + public boolean isForgeUser() + { + return forgeClientHandler.isForgeUser(); + } + @Override public Map getModList() {