@@ -216,10 +216,12 @@ public void clear(List<UUID> onlinePlayers) {
216216 @ Override
217217 public void addPermission (UUID uuid , String ... permissions ) {
218218 // Put the permissions into the cache
219- Map < String , Boolean > playerPermissions = cachedPermissions .getOrDefault (uuid , new HashMap <>());
219+ List < Permission > playerPermissions = cachedPermissions .getOrDefault (uuid , new ArrayList <>());
220220
221221 for (String permission : permissions ) {
222- playerPermissions .put (permission , true );
222+ Permission perm = new Permission (permission , true );
223+ playerPermissions .add (perm );
224+
223225 Optional <Connection > connection = getConnection ();
224226 if (!connection .isPresent ()) {
225227 PermissifyAPI .get ().ifPresent (api -> api .getDisplayUtil ().displayError (ConnectionError .REJECTED , Optional .empty ()));
@@ -245,8 +247,8 @@ public void addPermission(UUID uuid, String... permissions) {
245247 public void removePermission (UUID uuid , String ... permissions ) {
246248 for (String permission : permissions ) {
247249 // Remove from cache
248- Map < String , Boolean > playerPermissions = cachedPermissions .getOrDefault (uuid , new HashMap <>());
249- playerPermissions .remove ( permission );
250+ List < Permission > playerPermissions = cachedPermissions .getOrDefault (uuid , new ArrayList <>());
251+ playerPermissions .removeIf ( perm -> perm . getPermission (). equals ( permission ) );
250252 cachedPermissions .put (uuid , playerPermissions );
251253 // Attempt to remove from MySQL
252254 Optional <Connection > connection = getConnection ();
@@ -280,9 +282,9 @@ public void removePermission(UUID uuid, String... permissions) {
280282 public boolean hasPermission (UUID uuid , String permission ) {
281283 // Check the cache first
282284 if (cachedPermissions .containsKey (uuid ))
283- return cachedPermissions .get (uuid ).entrySet (). stream ()
284- .filter (entry -> entry .getKey ().equals (permission ))
285- .allMatch (entry -> entry . getValue (). equals ( true ) );
285+ return cachedPermissions .get (uuid ).stream ()
286+ .filter (entry -> entry .getPermission ().equals (permission ))
287+ .allMatch (Permission :: isGranted );
286288 // Cache didn't have it, see if the database does.
287289 Optional <Connection > connection = getConnection ();
288290 if (!connection .isPresent ()) {
@@ -313,8 +315,7 @@ public boolean hasPermission(UUID uuid, String permission) {
313315 public List <Permission > getPermissions (UUID uuid ) {
314316 if (cachedPermissions .containsKey (uuid )) {
315317 System .out .println ("Found cached permissions for " + uuid );
316- return cachedPermissions .get (uuid ).entrySet ().stream ()
317- .map (entry -> new Permission (entry .getKey (), entry .getValue ())).collect (Collectors .toList ());
318+ return cachedPermissions .get (uuid );
318319 }
319320 System .out .println ("No cache for " + uuid + " found. Getting." );
320321 Optional <Connection > connection = getConnection ();
@@ -336,6 +337,7 @@ public List<Permission> getPermissions(UUID uuid) {
336337 results .close ();
337338 statement .close ();
338339 connection .get ().close ();
340+ cachedPermissions .put (uuid , permissions );
339341 return permissions ;
340342 } catch (SQLException e ) {
341343 PermissifyAPI .get ().ifPresent (api -> api .getDisplayUtil ().displayError (ConnectionError .REJECTED , Optional .of (e )));
0 commit comments