@@ -116,7 +116,7 @@ public void initialize() {
116116 groupPermissionsStatement .close ();
117117
118118 PreparedStatement groupsStatement = connection .prepareStatement ("CREATE TABLE IF NOT EXISTS " + database +
119- "groups (name VARCHAR(100) NOT NULL UNIQUE, displayName VARCHAR(100) NOT NULL UNIQUE , prefix VARCHAR(100) NOT NULL, suffix VARCHAR(100) NOT NULL, chatcolor VARCHAR(4) NOT NULL, defaultGroup TINYINT NOT NULL, ladder VARCHAR(767))" );
119+ "groups (name VARCHAR(100) NOT NULL UNIQUE, displayName VARCHAR(100) NOT NULL, prefix VARCHAR(100) NOT NULL, suffix VARCHAR(100) NOT NULL, chatcolor VARCHAR(4) NOT NULL, defaultGroup TINYINT NOT NULL, ladder VARCHAR(767))" );
120120 groupsStatement .execute ();
121121 groupsStatement .close ();
122122
@@ -161,19 +161,6 @@ public void initialize() {
161161 }
162162 }
163163
164- @ Override
165- public boolean connect () {
166- Optional <Connection > connection = getConnection ();
167- boolean connected = connection .isPresent ();
168-
169- connection .ifPresent (c -> {
170- try {
171- c .close ();
172- } catch (SQLException ignored ) {}
173- });
174- return connected ;
175- }
176-
177164 @ Override
178165 public void reload (List <UUID > onlinePlayers ) {
179166 cachedGroups = new HashMap <>();
@@ -426,16 +413,16 @@ public List<Permission> getPermissions(UUID uuid) {
426413 }
427414
428415 @ Override
429- public boolean createGroup (String name , String displayName , String prefix , String suffix , String chatColor ) {
416+ public Tristate createGroup (String name , String displayName , String prefix , String suffix , String chatColor ) {
430417 // Make sure that this group doesn't already exist
431- if (cachedGroups .getOrDefault (name , null ) != null ) return false ;
418+ if (cachedGroups .getOrDefault (name , null ) != null ) return Tristate . NONE ;
432419 // Add the new group to the cache
433420 cachedGroups .put (name , new PermissionGroup (name , displayName , chatColor , prefix , suffix ));
434421
435422 Optional <Connection > connection = getConnection ();
436423 if (!connection .isPresent ()) {
437424 PermissifyAPI .get ().ifPresent (api -> api .getDisplayUtil ().displayError (ConnectionError .REJECTED , Optional .empty ()));
438- return false ;
425+ return Tristate . FALSE ;
439426 }
440427
441428 try {
@@ -455,14 +442,14 @@ public boolean createGroup(String name, String displayName, String prefix, Strin
455442 e .printStackTrace ();
456443 }
457444
458- return true ;
445+ return Tristate . TRUE ;
459446 }
460447
461448 @ Override
462- public boolean deleteGroup (String name ) {
449+ public Tristate deleteGroup (String name ) {
463450 Optional <PermissionGroup > group = getGroups ().entrySet ().stream ().map (Map .Entry ::getValue ).filter (g -> g .getName ().equalsIgnoreCase (name )).findFirst ();
464451 if (!group .isPresent ())
465- return false ;
452+ return Tristate . NONE ;
466453
467454 if (defaultGroup .isPresent () && defaultGroup .get ().getName ().equalsIgnoreCase (name )) {
468455 setDefaultGroup (null );
@@ -475,7 +462,7 @@ public boolean deleteGroup(String name) {
475462 Optional <Connection > connection = getConnection ();
476463 if (!connection .isPresent ()) {
477464 PermissifyAPI .get ().ifPresent (api -> api .getDisplayUtil ().displayError (ConnectionError .REJECTED , Optional .empty ()));
478- return false ;
465+ return Tristate . FALSE ;
479466 }
480467 try {
481468 PreparedStatement statement = connection .get ().prepareStatement ("DELETE FROM groups WHERE name=?" );
@@ -484,12 +471,12 @@ public boolean deleteGroup(String name) {
484471 statement .close ();
485472 connection .get ().close ();
486473
487- return true ;
474+ return Tristate . TRUE ;
488475 } catch (SQLException e ) {
489476 PermissifyAPI .get ().ifPresent (api -> api .getDisplayUtil ().displayError (ConnectionError .DATABASE_EXCEPTION , Optional .of (e )));
490477 e .printStackTrace ();
491478 }
492- return false ;
479+ return Tristate . FALSE ;
493480 }
494481
495482 @ Override
@@ -684,27 +671,27 @@ public boolean removeGroupPermission(String group, String... permissions) {
684671 .filter (permission -> permission .getName ().equalsIgnoreCase (group )).findFirst ();
685672 if (!permissionGroup .isPresent ()) return false ;
686673
687- for (String permission : permissions ) {
688- if (!permissionGroup .get ().hasPermission (permission )) return false ;
689- permissionGroup .get ().removePermission (permission );
690- Optional <Connection > connection = getConnection ();
691- if (!connection .isPresent ()) {
692- PermissifyAPI .get ().ifPresent (api -> api .getDisplayUtil ().displayError (ConnectionError .REJECTED , Optional .empty ()));
693- return false ;
694- }
695- try {
674+ Optional <Connection > connection = getConnection ();
675+ if (!connection .isPresent ()) {
676+ PermissifyAPI .get ().ifPresent (api -> api .getDisplayUtil ().displayError (ConnectionError .REJECTED , Optional .empty ()));
677+ return false ;
678+ }
679+ try {
680+ for (String permission : permissions ) {
681+ if (!permissionGroup .get ().hasPermission (permission )) return false ;
682+ permissionGroup .get ().removePermission (permission );
683+
696684 PreparedStatement statement = connection .get ().prepareStatement ("DELETE FROM groupPermissions WHERE groupName=? AND permission=?" );
697685 statement .setString (1 , group );
698686 statement .setString (2 , permission );
699687 statement .execute ();
700688 statement .close ();
701- connection . get (). close ();
702-
703- return true ;
704- } catch (SQLException e ) {
689+ }
690+ connection . get (). close ();
691+ return true ;
692+ } catch (SQLException e ) {
705693 PermissifyAPI .get ().ifPresent (api -> api .getDisplayUtil ().displayError (ConnectionError .REJECTED , Optional .of (e )));
706694 e .printStackTrace ();
707- }
708695 }
709696 return false ;
710697 }
0 commit comments