@@ -66,19 +66,24 @@ public String handleAddPlayerToGroup(CommandSender sender, String[] args) {
6666 Optional <PermissionGroup > group = plugin .getPermissifyAPI ().getDatabaseHandler ().get ().getGroup (args [1 ]);
6767 if (!group .isPresent ()) return PermissifyConstants .INVALID_GROUP .replace ("<GROUP>" , args [1 ]);
6868
69- plugin .getPermissifyAPI ().getDatabaseHandler ().get ().addPlayerToGroup (targetPlayer .getUniqueId (), group .get ());
70- if (targetPlayer .isOnline ()) group .get ().getPermissions ().forEach (permission ->
71- targetPlayer .getPlayer ().addAttachment (plugin , permission .getPermission (), permission .isGranted ()));
69+ Tristate added = plugin .getPermissifyAPI ().getDatabaseHandler ().get ().addPlayerToGroup (targetPlayer .getUniqueId (), group .get ());
70+ if (added == Tristate .NONE )
71+ return PermissifyConstants .UNABLE_TO_ADD .replace ("<REASON>" , "Player already in group." );
72+ else if (added == Tristate .FALSE )
73+ return PermissifyConstants .UNABLE_TO_ADD .replace ("<REASON>" , "No database handler." );
7274
7375 plugin .getPermissifyAPI ().getDatabaseHandler ().get ().updateCache (targetPlayer .getUniqueId ());
76+
77+ if (targetPlayer .isOnline ()) PermissionUtil .applyPermissions (targetPlayer .getPlayer ());
78+
7479 return PermissifyConstants .PLAYER_ADDED_TO_GROUP
7580 .replace ("<PLAYER>" , targetPlayer .getName ()).replace ("<GROUP>" , group .get ().getName ());
7681 }
7782
7883 public String handleRemovePlayerFromGroup (CommandSender sender , String [] args ) {
7984 PermissifyMain plugin = PermissifyMain .getInstance ();
8085 if (!plugin .getPermissifyAPI ().getDatabaseHandler ().isPresent ())
81- return PermissifyConstants .UNABLE_TO_REMOVE .replace ("<REASON>" , "No database handler." );
86+ return PermissifyConstants .UNABLE_TO_REMOVE .replace ("<TYPE>" , "player" ). replace ( "< REASON>" , "No database handler." );
8287
8388 if (!PermissionUtil .hasPermissionOrSuperAdmin (sender , PermissifyConstants .PERMISSIFY_PLAYER_GROUP_REMOVE ))
8489 return PermissifyConstants .INSUFFICIENT_PERMISSIONS ;
@@ -90,11 +95,16 @@ public String handleRemovePlayerFromGroup(CommandSender sender, String[] args) {
9095
9196 Optional <PermissionGroup > group = plugin .getPermissifyAPI ().getDatabaseHandler ().get ().getGroup (args [1 ]);
9297 if (!group .isPresent ()) return PermissifyConstants .INVALID_GROUP .replace ("<GROUP>" , args [1 ]);
93- plugin .getPermissifyAPI ().getDatabaseHandler ().get ().removePlayerFromGroup (targetPlayer .getUniqueId (), group .get ());
9498
95- plugin .getAttachmentManager ().getAttachment (targetPlayer .getUniqueId (), Optional .of (group .get ().getName ())).ifPresent (attachment ->
96- group .get ().getPermissions ().forEach (permission -> attachment .unsetPermission (permission .getPermission ())));
99+ Tristate removed = plugin .getPermissifyAPI ().getDatabaseHandler ().get ().removePlayerFromGroup (targetPlayer .getUniqueId (), group .get ());
100+ if (removed == Tristate .NONE )
101+ return PermissifyConstants .UNABLE_TO_REMOVE .replace ("<TYPE>" , "player" ).replace ("<REASON>" , "Player not in group." );
102+ else if (removed == Tristate .FALSE )
103+ return PermissifyConstants .UNABLE_TO_REMOVE .replace ("<TYPE>" , "player" ).replace ("<REASON>" , "No database handler." );
104+
97105 plugin .getPermissifyAPI ().getDatabaseHandler ().get ().updateCache (targetPlayer .getUniqueId ());
106+
107+ if (targetPlayer .isOnline ()) PermissionUtil .applyPermissions (targetPlayer .getPlayer ());
98108 return PermissifyConstants .PLAYER_REMOVED_FROM_GROUP
99109 .replace ("<PLAYER>" , targetPlayer .getName ()).replace ("<GROUP>" , group .get ().getName ());
100110 }
@@ -153,15 +163,15 @@ public String handleAddPermission(CommandSender sender, String[] args) {
153163 return PermissifyConstants .PLAYER_ALREADY_HAS_PERMISSION .replace ("<PLAYER>" , targetPlayer .getName ()).replace ("<PERMISSION>" , args [1 ]);
154164 }
155165 plugin .getPermissifyAPI ().getDatabaseHandler ().get ().addPermission (targetPlayer .getUniqueId (), args [1 ]);
156- if (targetPlayer .isOnline ()) targetPlayer .getPlayer (). addAttachment ( plugin , args [ 1 ], true );
166+ if (targetPlayer .isOnline ()) PermissionUtil . applyPermissions ( targetPlayer .getPlayer ());
157167
158168 if (args .length >= 3 ) {
159169 // Timed permission.
160170 if (!MiscUtil .isInt (args [2 ])) return PermissifyConstants .INVALID_ARGUMENT .replace ("<ARGUMENT>" , args [2 ]);
161171 int time = Integer .parseInt (args [2 ]);
162172
163173 Bukkit .getScheduler ().runTaskLater (plugin , () -> {
164- targetPlayer .getPlayer (). addAttachment ( plugin , args [ 1 ], false );
174+ if ( targetPlayer .isOnline ()) PermissionUtil . applyPermissions ( targetPlayer . getPlayer () );
165175 if (!plugin .getPermissifyAPI ().getDatabaseHandler ().isPresent ()) return ;
166176 plugin .getPermissifyAPI ().getDatabaseHandler ().get ().removePermission (targetPlayer .getUniqueId (), args [1 ]);
167177 plugin .getPermissifyAPI ().getDatabaseHandler ().get ().updateCache (targetPlayer .getUniqueId ());
0 commit comments