33import com .github .benmanes .caffeine .cache .Cache ;
44import com .github .benmanes .caffeine .cache .Caffeine ;
55import me .xginko .aef .utils .enums .TriState ;
6- import org .bukkit .command .CommandSender ;
76import org .bukkit .event .EventHandler ;
87import org .bukkit .event .EventPriority ;
98import org .bukkit .event .HandlerList ;
109import org .bukkit .event .Listener ;
1110import org .bukkit .event .player .PlayerKickEvent ;
1211import org .bukkit .event .player .PlayerQuitEvent ;
12+ import org .bukkit .permissions .Permissible ;
1313import org .bukkit .permissions .PermissionAttachmentInfo ;
1414import org .bukkit .plugin .java .JavaPlugin ;
1515
1919
2020public final class BukkitPermissionHandler implements PermissionHandler , Listener {
2121
22- private final Map <CommandSender , Cache <String , TriState >> permissionCacheMap ;
22+ private final Map <Permissible , Cache <String , TriState >> permissionCacheMap ;
2323 private final Duration permissionCacheDuration ;
2424
2525 BukkitPermissionHandler (JavaPlugin plugin ) {
@@ -31,35 +31,35 @@ public final class BukkitPermissionHandler implements PermissionHandler, Listene
3131 @ Override
3232 public void disable () {
3333 HandlerList .unregisterAll (this );
34- for (Map .Entry <CommandSender , Cache <String , TriState >> entry : permissionCacheMap .entrySet ()) {
34+ for (Map .Entry <Permissible , Cache <String , TriState >> entry : permissionCacheMap .entrySet ()) {
3535 flushCache (entry .getKey ());
3636 }
3737 }
3838
3939 @ Override
40- public TriState permissionValue (CommandSender commandSender , String permission ) {
41- Cache <String , TriState > permCache = permissionCacheMap .computeIfAbsent (commandSender , sender ->
40+ public TriState permissionValue (Permissible permissible , String permission ) {
41+ Cache <String , TriState > permCache = permissionCacheMap .computeIfAbsent (permissible , sender ->
4242 Caffeine .newBuilder ().expireAfterWrite (permissionCacheDuration ).build ());
4343 TriState value = permCache .getIfPresent (permission );
4444 if (value == null ) {
45- value = commandSender .isPermissionSet (permission ) ? TriState .of (commandSender .hasPermission (permission )) : TriState .UNDEFINED ;
45+ value = permissible .isPermissionSet (permission ) ? TriState .of (permissible .hasPermission (permission )) : TriState .UNDEFINED ;
4646 permCache .put (permission , value );
4747 }
4848 return value ;
4949 }
5050
5151 @ Override
52- public void setPermission (CommandSender commandSender , String permission , TriState state ) {
53- for (PermissionAttachmentInfo attachmentInfo : commandSender .getEffectivePermissions ()) {
52+ public void setPermission (Permissible permissible , String permission , TriState state ) {
53+ for (PermissionAttachmentInfo attachmentInfo : permissible .getEffectivePermissions ()) {
5454 if (attachmentInfo .getAttachment () == null ) {
5555 continue ;
5656 }
5757
5858 if (attachmentInfo .getPermission ().equals (permission )) {
5959 if (state == TriState .UNDEFINED ) {
60- commandSender .removeAttachment (attachmentInfo .getAttachment ());
60+ permissible .removeAttachment (attachmentInfo .getAttachment ());
6161 } else {
62- commandSender .addAttachment (attachmentInfo .getAttachment ().getPlugin (), permission , state .toBoolean ());
62+ permissible .addAttachment (attachmentInfo .getAttachment ().getPlugin (), permission , state .toBoolean ());
6363 }
6464 }
6565 }
@@ -75,7 +75,7 @@ private void onPlayerKick(PlayerKickEvent event) {
7575 flushCache (event .getPlayer ());
7676 }
7777
78- private void flushCache (CommandSender commandSender ) {
78+ private void flushCache (Permissible commandSender ) {
7979 if (permissionCacheMap .containsKey (commandSender )) {
8080 permissionCacheMap .get (commandSender ).invalidateAll ();
8181 permissionCacheMap .get (commandSender ).cleanUp ();
0 commit comments