3030import it .unimi .dsi .fastutil .shorts .Short2ObjectMap ;
3131import it .unimi .dsi .fastutil .shorts .Short2ObjectMaps ;
3232import it .unimi .dsi .fastutil .shorts .Short2ObjectOpenHashMap ;
33- import java .util .ArrayList ;
34- import java .util .Collections ;
35- import java .util .HashSet ;
3633import java .util .Map ;
3734import java .util .Set ;
3835import java .util .UUID ;
3936import java .util .concurrent .ConcurrentHashMap ;
37+ import java .util .concurrent .atomic .AtomicBoolean ;
4038import java .util .concurrent .atomic .AtomicInteger ;
4139import org .geysermc .cumulus .form .Form ;
4240import org .geysermc .cumulus .form .impl .FormDefinition ;
4341import org .geysermc .cumulus .form .impl .FormDefinitions ;
4442import org .geysermc .floodgate .api .logger .FloodgateLogger ;
43+ import org .geysermc .floodgate .api .player .FloodgatePlayer ;
4544import org .geysermc .floodgate .config .FloodgateConfig ;
4645import org .geysermc .floodgate .platform .pluginmessage .PluginMessageUtils ;
4746import org .geysermc .floodgate .pluginmessage .PluginMessageChannel ;
@@ -65,8 +64,7 @@ public String getIdentifier() {
6564 @ Override
6665 public Result handleProxyCall (
6766 byte [] data ,
68- UUID sourceUuid ,
69- String sourceUsername ,
67+ FloodgatePlayer source ,
7068 Identity sourceIdentity
7169 ) {
7270 if (sourceIdentity == Identity .SERVER ) {
@@ -86,17 +84,19 @@ public Result handleProxyCall(
8684 return Result .forward ();
8785 }
8886
89- if (!callResponseConsumer (sourceUuid , data )) {
87+ if (!callResponseConsumer (source , data )) {
9088 logger .error ("Couldn't find stored form with id {} for player {}" ,
91- formId , sourceUsername );
89+ formId , source . getCorrectUsername () );
9290 }
9391 }
9492 return Result .handled ();
9593 }
9694
9795 @ Override
98- public Result handleServerCall (byte [] data , UUID playerUuid , String playerUsername ) {
99- callResponseConsumer (playerUuid , data );
96+ public Result handleServerCall (byte [] data , FloodgatePlayer source ) {
97+ if (!callResponseConsumer (source , data )) {
98+ logger .error ("Couldn't find stored form for player {}" , source .getCorrectUsername ());
99+ }
100100 return Result .handled ();
101101 }
102102
@@ -125,7 +125,7 @@ public boolean sendForm(UUID player, Form form) {
125125 public byte [] createFormData (UUID uuid , Form form ) {
126126 short formId = getNextFormId ();
127127 if (config .isProxy ()) {
128- formId |= 0x8000 ;
128+ formId |= ( short ) 0x8000 ;
129129 }
130130 storedForms .put (formId , form );
131131 playerToFormMap .computeIfAbsent (uuid , k -> ConcurrentHashMap .newKeySet ()).add (formId );
@@ -145,13 +145,18 @@ public byte[] createFormData(UUID uuid, Form form) {
145145 return data ;
146146 }
147147
148- protected boolean callResponseConsumer (UUID player , byte [] data ) {
148+ protected boolean callResponseConsumer (FloodgatePlayer player , byte [] data ) {
149149 short formId = getFormId (data );
150- playerToFormMap .computeIfPresent (player , (k , list ) -> {
151- list .remove (Short .valueOf (formId )); // remove by value, not index
150+ AtomicBoolean found = new AtomicBoolean (false );
151+ playerToFormMap .computeIfPresent (player .getCorrectUniqueId (), (k , list ) -> {
152+ found .set (list .remove (formId )); // remove by value, not index
152153 return list .isEmpty () ? null : list ;
153154 });
154155
156+ if (!found .get ()) {
157+ return false ;
158+ }
159+
155160 Form storedForm = storedForms .remove (formId );
156161 if (storedForm != null ) {
157162 String responseData = new String (data , 2 , data .length - 2 , Charsets .UTF_8 );
0 commit comments