@@ -103,10 +103,31 @@ public void clear(List<UUID> onlinePlayers) {
103103 adminStatement .close ();
104104
105105 // Load all group names
106- PreparedStatement groupStatement = connection .get ().prepareStatement ("SELECT name from groups" );
106+ PreparedStatement groupStatement = connection .get ().prepareStatement ("SELECT * from groups" );
107107 ResultSet groupResults = groupStatement .executeQuery ();
108108 while (groupResults .next ()) {
109- groupNames .add (groupResults .getString ("name" ));
109+ PermissionGroup group = new PermissionGroup (groupResults .getString ("name" ),
110+ groupResults .getString ("chatcolor" ),
111+ groupResults .getString ("prefix" ),
112+ groupResults .getString ("suffix" ));
113+ PreparedStatement groupPermissionsStatement = connection .get ().prepareStatement ("SELECT * FROM groupPermissions WHERE groupName=?" );
114+ groupPermissionsStatement .setString (1 , group .getName ());
115+ ResultSet groupPermissionsResult = groupPermissionsStatement .executeQuery ();
116+ while (groupPermissionsResult .next ()) {
117+ group .addPermission (groupPermissionsResult .getString ("permission" ));
118+ }
119+ groupPermissionsResult .close ();
120+ groupPermissionsStatement .close ();
121+
122+ PreparedStatement groupMembersStatement = connection .get ().prepareStatement ("SELECT uuid,`primary` FROM groupMembers WHERE `group`=?" );
123+ groupMembersStatement .setString (1 , group .getName ());
124+ ResultSet groupMembersResults = groupMembersStatement .executeQuery ();
125+ while (groupMembersResults .next ()) {
126+ group .addPlayer (UUID .fromString (groupMembersResults .getString ("uuid" )), groupMembersResults .getBoolean ("primary" ));
127+ }
128+ groupMembersResults .close ();
129+ groupMembersStatement .close ();
130+ cachedGroups .add (group );
110131 }
111132 groupStatement .close ();
112133 groupResults .close ();
@@ -215,9 +236,12 @@ public boolean hasPermission(UUID uuid, String permission) {
215236
216237 @ Override
217238 public List <Permission > getPermissions (UUID uuid ) {
218- if (cachedPermissions .containsKey (uuid ))
239+ if (cachedPermissions .containsKey (uuid )) {
240+ System .out .println ("Found cached permissions for " + uuid );
219241 return cachedPermissions .get (uuid ).entrySet ().stream ()
220242 .map (entry -> new Permission (entry .getKey (), entry .getValue ())).collect (Collectors .toList ());
243+ }
244+ System .out .println ("No cache for " + uuid + " found. Getting." );
221245 Optional <Connection > connection = getConnection ();
222246 List <Permission > permissions = new ArrayList <>();
223247
@@ -250,7 +274,6 @@ public boolean createGroup(String name, String prefix, String suffix, String cha
250274 if (cachedGroups .stream ().anyMatch (group -> group .getName ().equalsIgnoreCase (name ))) return false ;
251275 // Add the new group to the cache
252276 cachedGroups .add (new PermissionGroup (name , chatColor , prefix , suffix ));
253- groupNames .add (name );
254277
255278 Optional <Connection > connection = getConnection ();
256279 if (!connection .isPresent ()) {
@@ -280,7 +303,6 @@ public boolean deleteGroup(String name) {
280303 if (getGroups ().stream ().noneMatch (group -> group .getName ().equalsIgnoreCase (name ))) return false ;
281304 // Delete from the cache
282305 cachedGroups .removeIf (group -> group .getName ().equalsIgnoreCase (name ));
283- groupNames .removeIf (entry -> entry .equalsIgnoreCase (name ));
284306
285307 Optional <Connection > connection = getConnection ();
286308 if (!connection .isPresent ()) {
@@ -302,32 +324,7 @@ public boolean deleteGroup(String name) {
302324
303325 @ Override
304326 public Optional <PermissionGroup > getGroup (String name ) {
305- if (!groupNames .contains (name )) return Optional .empty ();
306- Optional <PermissionGroup > cached = cachedGroups .stream ().filter (group -> group .getName ().equalsIgnoreCase (name )).findFirst ();
307- if (cached .isPresent ()) return cached ;
308- // Not a cached group, and it's a real group. Must be pulled from DB.
309- Optional <Connection > connection = getConnection ();
310- if (!connection .isPresent ()) {
311- PermissifyAPI .get ().ifPresent (api -> api .getDisplayUtil ().displayError (ConnectionError .REJECTED , Optional .empty ()));
312- return Optional .empty ();
313- }
314-
315- try {
316- PreparedStatement statement = connection .get ().prepareStatement ("SELECT * FROM groups WHERE name=?" );
317- statement .setString (1 , name );
318- ResultSet results = statement .executeQuery ();
319- if (results .next ()) {
320- PermissionGroup group = new PermissionGroup (results .getString ("name" ), results .getString ("chatcolor" ), results .getString ("prefix" ), results .getString ("suffix" ));
321- cachedGroups .add (group );
322- return Optional .of (group );
323- }
324- results .close ();
325- statement .close ();
326- connection .get ().close ();
327- } catch (SQLException e ) {
328- PermissifyAPI .get ().ifPresent (api -> api .getDisplayUtil ().displayError (ConnectionError .REJECTED , Optional .of (e )));
329- }
330- return Optional .empty ();
327+ return cachedGroups .stream ().filter (group -> group .getName ().equalsIgnoreCase (name )).findFirst ();
331328 }
332329
333330 @ Override
0 commit comments