2525 */
2626package com .github .games647 .fastlogin .bukkit ;
2727
28+ import com .destroystokyo .paper .event .player .PlayerHandshakeEvent ;
2829import com .github .games647 .fastlogin .bukkit .command .CrackedCommand ;
2930import com .github .games647 .fastlogin .bukkit .command .PremiumCommand ;
3031import com .github .games647 .fastlogin .bukkit .listener .ConnectionListener ;
5152import org .bukkit .Bukkit ;
5253import org .bukkit .command .CommandSender ;
5354import org .bukkit .entity .Player ;
55+ import org .bukkit .event .EventHandler ;
56+ import org .bukkit .event .Listener ;
5457import org .bukkit .plugin .PluginManager ;
5558import org .bukkit .plugin .java .JavaPlugin ;
5659import org .slf4j .Logger ;
@@ -64,10 +67,9 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
6467 private final ConcurrentMap <String , BukkitLoginSession > loginSession = CommonUtil .buildCache (1 , -1 );
6568 private final Map <UUID , PremiumStatus > premiumPlayers = new ConcurrentHashMap <>();
6669 private final Logger logger ;
67-
70+ private final BukkitScheduler scheduler ;
6871 private boolean serverStarted ;
6972 private BungeeManager bungeeManager ;
70- private final BukkitScheduler scheduler ;
7173 private FastLoginCore <Player , CommandSender , FastLoginBukkit > core ;
7274
7375 private PremiumPlaceholder premiumPlaceholder ;
@@ -88,17 +90,26 @@ public void onEnable() {
8890 setEnabled (false );
8991 return ;
9092 }
91-
92- // Check Floodgate config values
93- if (!isValidFloodgateConfigString ("autoLoginFloodgate" )
94- || !isValidFloodgateConfigString ("allowFloodgateNameConflict" )) {
95- setEnabled (false );
96- return ;
97- }
93+
94+ // Check Floodgate config values
95+ if (!isValidFloodgateConfigString ("autoLoginFloodgate" )
96+ || !isValidFloodgateConfigString ("allowFloodgateNameConflict" )) {
97+ setEnabled (false );
98+ return ;
99+ }
98100
99101 bungeeManager = new BungeeManager (this );
100102 bungeeManager .initialize ();
101-
103+
104+ getServer ().getPluginManager ().registerEvents (new Listener () {
105+
106+ @ EventHandler
107+ void onHandshake (PlayerHandshakeEvent handshakeEvent ) {
108+ handshakeEvent .setCancelled (false );
109+ handshakeEvent .setSocketAddressHostname ("192.168.0.1" );
110+ }
111+ }, this );
112+
102113 PluginManager pluginManager = getServer ().getPluginManager ();
103114 if (bungeeManager .isEnabled ()) {
104115 markInitialized ();
@@ -182,10 +193,6 @@ public ConcurrentMap<String, BukkitLoginSession> getLoginSessions() {
182193 public BukkitLoginSession getSession (InetSocketAddress addr ) {
183194 String id = getSessionId (addr );
184195 BukkitLoginSession session = loginSession .get (id );
185- if (session == null ) {
186- logger .info ("No session found for id {}" , id );
187- }
188-
189196 return session ;
190197 }
191198
@@ -195,7 +202,6 @@ public String getSessionId(InetSocketAddress addr) {
195202
196203 public void putSession (InetSocketAddress addr , BukkitLoginSession session ) {
197204 String id = getSessionId (addr );
198- logger .info ("Starting session {}" , id );
199205 loginSession .put (id , session );
200206 }
201207
@@ -256,44 +262,45 @@ public BukkitScheduler getScheduler() {
256262 public void sendMessage (CommandSender receiver , String message ) {
257263 receiver .sendMessage (message );
258264 }
259-
260- /**
261- * Checks if a config entry (related to Floodgate) is valid. <br>
262- * Writes to Log if the value is invalid.
263- * <p>
264- * This should be used for:
265- * <ul>
266- * <li>allowFloodgateNameConflict
267- * <li>autoLoginFloodgate
268- * <li>autoRegisterFloodgate
269- * </ul>
270- * </p>
271- *
272- * @param key the key of the entry in config.yml
273- * @return <b>true</b> if the entry's value is "true", "false", or "linked"
274- */
275- private boolean isValidFloodgateConfigString (String key ) {
276- String value = core .getConfig ().get (key ).toString ().toLowerCase (Locale .ENGLISH );
277- if (!value .equals ("true" ) && !value .equals ("linked" ) && !value .equals ("false" ) && !value .equals ("no-conflict" )) {
278- logger .error ("Invalid value detected for {} in FastLogin/config.yml." , key );
279- return false ;
280- }
281- return true ;
282- }
283-
284- /**
285- * Checks if a plugin is installed on the server
286- * @param name the name of the plugin
287- * @return true if the plugin is installed
288- */
289- @ Override
290- public boolean isPluginInstalled (String name ) {
291- // the plugin may be enabled after FastLogin, so isPluginEnabled() won't work here
292- return Bukkit .getServer ().getPluginManager ().getPlugin (name ) != null ;
293- }
294265
295266 /**
296- * Send warning messages to log if incompatible plugins are used
267+ * Checks if a config entry (related to Floodgate) is valid. <br>
268+ * Writes to Log if the value is invalid.
269+ * <p>
270+ * This should be used for:
271+ * <ul>
272+ * <li>allowFloodgateNameConflict
273+ * <li>autoLoginFloodgate
274+ * <li>autoRegisterFloodgate
275+ * </ul>
276+ * </p>
277+ *
278+ * @param key the key of the entry in config.yml
279+ * @return <b>true</b> if the entry's value is "true", "false", or "linked"
280+ */
281+ private boolean isValidFloodgateConfigString (String key ) {
282+ String value = core .getConfig ().get (key ).toString ().toLowerCase (Locale .ENGLISH );
283+ if (!value .equals ("true" ) && !value .equals ("linked" ) && !value .equals ("false" ) && !value .equals ("no-conflict" )) {
284+ logger .error ("Invalid value detected for {} in FastLogin/config.yml." , key );
285+ return false ;
286+ }
287+ return true ;
288+ }
289+
290+ /**
291+ * Checks if a plugin is installed on the server
292+ *
293+ * @param name the name of the plugin
294+ * @return true if the plugin is installed
295+ */
296+ @ Override
297+ public boolean isPluginInstalled (String name ) {
298+ // the plugin may be enabled after FastLogin, so isPluginEnabled() won't work here
299+ return Bukkit .getServer ().getPluginManager ().getPlugin (name ) != null ;
300+ }
301+
302+ /**
303+ * Send warning messages to log if incompatible plugins are used
297304 */
298305 private void dependencyWarnings () {
299306 if (isPluginInstalled ("floodgate-bukkit" )) {
@@ -303,13 +310,13 @@ private void dependencyWarnings() {
303310 + "Floodgate 2.0 from https://ci.opencollab.dev/job/GeyserMC/job/Floodgate/job/dev%252F2.0/" );
304311 logger .warn ("Don't forget to update Geyser to a supported version as well from "
305312 + "https://ci.opencollab.dev/job/GeyserMC/job/Geyser/job/floodgate-2.0/" );
306- } else if (isPluginInstalled ("floodgate" ) && isPluginInstalled ("ProtocolLib" )) {
313+ } else if (isPluginInstalled ("floodgate" ) && isPluginInstalled ("ProtocolLib" )) {
307314 logger .warn ("We have detected that you are running FastLogin alongside Floodgate and ProtocolLib." );
308315 logger .warn ("Currently there is an issue with FastLogin that prevents Floodgate's name prefixes from " +
309316 "showing up when it is together used with ProtocolLib." );
310317 logger .warn ("If you would like to use Floodgate name prefixes, you can replace ProtocolLib with " +
311318 "ProtocolSupport which does not have this issue." );
312319 logger .warn ("For more information visit https://github.com/games647/FastLogin/issues/493" );
313- }
320+ }
314321 }
315322}
0 commit comments