@@ -274,7 +274,7 @@ public boolean deleteGroup(String name) {
274274 @ Override
275275 public boolean addPlayerToGroup (UUID uuid , PermissionGroup group ) {
276276 if (group .hasPlayer (uuid )) return false ;
277- group .addPlayer (uuid );
277+ group .addPlayer (uuid , false );
278278 // Update the cache
279279 cachedGroups .removeIf (entry -> entry .getName ().equals (group .getName ()));
280280 cachedGroups .add (group );
@@ -353,8 +353,10 @@ public boolean setPrimaryGroup(PermissionGroup group, UUID uuid) {
353353 statement .setString (2 , uuid .toString ());
354354 statement .setString (3 , group .getName ());
355355 statement .execute ();
356+ statement .close ();
357+ connection .get ().close ();
356358 } catch (SQLException e ) {
357- e . printStackTrace ( );
359+ displayError ( ConnectionError . DATABASE_EXCEPTION , e );
358360 }
359361 return true ;
360362 }
@@ -366,7 +368,6 @@ public Optional<PermissionGroup> getPrimaryGroup(UUID uuid) {
366368
367369 @ Override
368370 public void updateCache (UUID uuid ) {
369- // TODO: Make this method not exist. It shouldn't be needed.
370371 Optional <Connection > connection = getConnection ();
371372 if (!connection .isPresent ()) {
372373 displayError (ConnectionError .REJECTED );
@@ -381,20 +382,25 @@ public void updateCache(UUID uuid) {
381382 Optional <PermissionGroup > group = cachedGroups .stream ().filter (permissionGroup -> permissionGroup .getName ().equals (groupName )).findFirst ();
382383 // Get the group from the database, if we don't have have it already
383384 if (!group .isPresent ()) {
385+ System .out .println ("Not present" );
384386 PreparedStatement groupStatement = connection .get ().prepareStatement ("SELECT prefix,suffix,chatcolor FROM groups WHERE name=?" );
385387 groupStatement .setString (1 , groupName );
386388 ResultSet groupResults = groupStatement .executeQuery ();
387389 if (!groupResults .next ()) return ;
390+ System .out .println ("Got results" );
388391 PermissionGroup permissionGroup = new PermissionGroup (
389392 groupName , groupResults .getString ("chatcolor" ), groupResults .getString ("prefix" ),
390393 groupResults .getString ("suffix" ));
394+ System .out .println (permissionGroup );
391395 groupResults .close ();
392396 groupStatement .close ();
393- PreparedStatement groupPlayersStatement = connection .get ().prepareStatement ("SELECT uuid FROM groupMembers WHERE `group`=?" );
397+ PreparedStatement groupPlayersStatement = connection .get ().prepareStatement ("SELECT uuid,`primary` FROM groupMembers WHERE `group`=?" );
394398 groupPlayersStatement .setString (1 , groupName );
395399 ResultSet groupPlayersResult = groupPlayersStatement .executeQuery ();
396400 while (groupPlayersResult .next ()) {
397- permissionGroup .addPlayer (UUID .fromString (groupPlayersResult .getString ("uuid" )));
401+ permissionGroup .addPlayer (UUID .fromString (groupPlayersResult .getString ("uuid" )),
402+ groupPlayersResult .getBoolean ("primary" ));
403+ System .out .println (permissionGroup .getPlayers ());
398404 }
399405 cachedGroups .add (permissionGroup );
400406 }
@@ -403,7 +409,7 @@ public void updateCache(UUID uuid) {
403409 statement .close ();
404410 connection .get ().close ();
405411 } catch (SQLException e ) {
406- e . printStackTrace ( );
412+ displayError ( ConnectionError . DATABASE_EXCEPTION , e );
407413 }
408414 }
409415
@@ -511,6 +517,9 @@ public boolean isSuperAdmin(UUID uuid) {
511517 return true ;
512518 }
513519 }
520+ results .close ();
521+ statement .close ();
522+ connection .get ().close ();
514523 } catch (SQLException e ) {
515524 displayError (ConnectionError .DATABASE_EXCEPTION , e );
516525 }
@@ -554,7 +563,11 @@ public String getChatFormat(boolean skipCache) {
554563 statement .setString (1 , FormatterType .CHAT .getUsageName ());
555564 ResultSet results = statement .executeQuery ();
556565 if (!results .next ()) return "" ;
557- return results .getString ("format" );
566+ String format = results .getString ("format" );
567+ results .close ();
568+ statement .close ();
569+ connection .get ().close ();
570+ return format ;
558571 } catch (SQLException e ) {
559572 e .printStackTrace ();
560573 }
@@ -598,9 +611,14 @@ public String getWhisperFormat(boolean skipCache) {
598611 statement .setString (1 , FormatterType .WHISPER .getUsageName ());
599612 ResultSet results = statement .executeQuery ();
600613 if (!results .next ()) return "" ;
601- return results .getString ("format" );
614+ String format = results .getString ("format" );
615+ results .close ();
616+ statement .close ();
617+ connection .get ().close ();
618+ return format ;
602619 } catch (SQLException e ) {
603620 e .printStackTrace ();
604621 }
605- return "" ; }
622+ return "" ;
623+ }
606624}
0 commit comments