1+ /*
2+ * SPDX-License-Identifier: MIT
3+ *
4+ * The MIT License (MIT)
5+ *
6+ * Copyright (c) 2015-2021 <Your name and contributors>
7+ *
8+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9+ * of this software and associated documentation files (the "Software"), to deal
10+ * in the Software without restriction, including without limitation the rights
11+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+ * copies of the Software, and to permit persons to whom the Software is
13+ * furnished to do so, subject to the following conditions:
14+ *
15+ * The above copyright notice and this permission notice shall be included in all
16+ * copies or substantial portions of the Software.
17+ *
18+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24+ * SOFTWARE.
25+ */
26+ package com .github .games647 .fastlogin .velocity .task ;
27+
28+ import com .github .games647 .fastlogin .core .shared .FastLoginCore ;
29+ import com .github .games647 .fastlogin .core .shared .FloodgateManagement ;
30+ import com .github .games647 .fastlogin .velocity .FastLoginVelocity ;
31+ import com .github .games647 .fastlogin .velocity .VelocityLoginSession ;
32+ import com .velocitypowered .api .command .CommandSource ;
33+ import com .velocitypowered .api .proxy .Player ;
34+ import com .velocitypowered .api .proxy .server .RegisteredServer ;
35+ import org .geysermc .floodgate .api .player .FloodgatePlayer ;
36+
37+ import java .net .InetSocketAddress ;
38+ import java .util .UUID ;
39+ import java .util .concurrent .TimeUnit ;
40+
41+ public class FloodgateAuthTask
42+ extends FloodgateManagement <Player , CommandSource , VelocityLoginSession , FastLoginVelocity > {
43+
44+ private final RegisteredServer server ;
45+
46+ public FloodgateAuthTask (FastLoginCore <Player , CommandSource , FastLoginVelocity > core , Player player ,
47+ FloodgatePlayer floodgatePlayer , RegisteredServer server ) {
48+ super (core , player , floodgatePlayer );
49+ this .server = server ;
50+ }
51+
52+ @ Override
53+ protected void startLogin () {
54+ VelocityLoginSession session = new VelocityLoginSession (player .getUsername (), isRegistered , profile );
55+ core .getPlugin ().getSession ().put (player .getRemoteAddress (), session );
56+
57+ // enable auto login based on the value of 'autoLoginFloodgate' in config.yml
58+ boolean forcedOnlineMode = autoLoginFloodgate .equals ("true" )
59+ || (autoLoginFloodgate .equals ("linked" ) && isLinked );
60+
61+ // delay sending force command, because Paper will process the login event asynchronously
62+ // In this case it means that the force command (plugin message) is already received and processed while
63+ // player is still in the login phase and reported to be offline.
64+ Runnable loginTask = new ForceLoginTask (core .getPlugin ().getCore (), player , server , session , forcedOnlineMode );
65+ core .getPlugin ().getProxy ().getScheduler ()
66+ .buildTask (core .getPlugin (), () -> core .getPlugin ().getScheduler ().runAsync (loginTask ))
67+ .delay (1L , TimeUnit .SECONDS ) // Delay at least one second, otherwise the login command can be missed
68+ .schedule ();
69+ }
70+
71+ @ Override
72+ protected String getName (Player player ) {
73+ return player .getUsername ();
74+ }
75+
76+ @ Override
77+ protected UUID getUUID (Player player ) {
78+ return player .getUniqueId ();
79+ }
80+
81+ @ Override
82+ protected InetSocketAddress getAddress (Player player ) {
83+ return player .getRemoteAddress ();
84+ }
85+
86+ }
0 commit comments