2424 */
2525package me .innectic .permissify .api .database .handlers ;
2626
27+ import me .innectic .permissify .api .PermissifyAPI ;
2728import me .innectic .permissify .api .database .ConnectionError ;
2829import me .innectic .permissify .api .database .DatabaseHandler ;
2930import me .innectic .permissify .api .permission .Permission ;
@@ -56,7 +57,7 @@ private Optional<Connection> getConnection() {
5657 String connectionURL = "jdbc:mysql://" + connectionInformation .get ().getUrl () + ":" + connectionInformation .get ().getPort () + "/" + connectionInformation .get ().getDatabase ();
5758 return Optional .ofNullable (DriverManager .getConnection (connectionURL , connectionInformation .get ().getUsername (), connectionInformation .get ().getPassword ()));
5859 } catch (SQLException e ) {
59- displayError (ConnectionError .DATABASE_EXCEPTION , e );
60+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . of ( e )) );
6061 }
6162 return Optional .empty ();
6263 }
@@ -99,7 +100,7 @@ public void addPermission(UUID uuid, String... permissions) {
99100 playerPermissions .put (permission , true );
100101 Optional <Connection > connection = getConnection ();
101102 if (!connection .isPresent ()) {
102- displayError (ConnectionError .REJECTED );
103+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . empty ()) );
103104 return ;
104105 }
105106 try {
@@ -111,7 +112,7 @@ public void addPermission(UUID uuid, String... permissions) {
111112 statement .close ();
112113 connection .get ().close ();
113114 } catch (SQLException e ) {
114- displayError (ConnectionError .DATABASE_EXCEPTION , e );
115+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . of ( e )) );
115116 return ;
116117 }
117118 }
@@ -128,7 +129,7 @@ public void removePermission(UUID uuid, String... permissions) {
128129 // Attempt to remove from MySQL
129130 Optional <Connection > connection = getConnection ();
130131 if (!connection .isPresent ()) {
131- displayError (ConnectionError .REJECTED );
132+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . empty ()) );
132133 return ;
133134 }
134135
@@ -148,7 +149,7 @@ public void removePermission(UUID uuid, String... permissions) {
148149 statement .close ();
149150 connection .get ().close ();
150151 } catch (SQLException e ) {
151- displayError (ConnectionError .DATABASE_EXCEPTION , e );
152+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . of ( e )) );
152153 }
153154 }
154155 }
@@ -163,7 +164,7 @@ public boolean hasPermission(UUID uuid, String permission) {
163164 // Cache didn't have it, see if the database does.
164165 Optional <Connection > connection = getConnection ();
165166 if (!connection .isPresent ()) {
166- displayError (ConnectionError .REJECTED );
167+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . empty ()) );
167168 return false ;
168169 }
169170
@@ -181,7 +182,7 @@ public boolean hasPermission(UUID uuid, String permission) {
181182 connection .get ().close ();
182183 return granted ;
183184 } catch (SQLException e ) {
184- displayError (ConnectionError .DATABASE_EXCEPTION , e );
185+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . of ( e )) );
185186 }
186187 return false ;
187188 }
@@ -195,7 +196,7 @@ public List<Permission> getPermissions(UUID uuid) {
195196 List <Permission > permissions = new ArrayList <>();
196197
197198 if (!connection .isPresent ()) {
198- displayError (ConnectionError .REJECTED );
199+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . empty ()) );
199200 return permissions ;
200201 }
201202 try {
@@ -212,7 +213,7 @@ public List<Permission> getPermissions(UUID uuid) {
212213 connection .get ().close ();
213214 return permissions ;
214215 } catch (SQLException e ) {
215- displayError (ConnectionError .DATABASE_EXCEPTION , e );
216+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . of ( e )) );
216217 }
217218 return new ArrayList <>();
218219 }
@@ -226,7 +227,7 @@ public boolean createGroup(String name, String prefix, String suffix, String cha
226227
227228 Optional <Connection > connection = getConnection ();
228229 if (!connection .isPresent ()) {
229- displayError (ConnectionError .REJECTED );
230+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . empty ()) );
230231 return false ;
231232 }
232233
@@ -241,7 +242,7 @@ public boolean createGroup(String name, String prefix, String suffix, String cha
241242 statement .close ();
242243 connection .get ().close ();
243244 } catch (SQLException e ) {
244- displayError (ConnectionError .DATABASE_EXCEPTION , e );
245+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . of ( e )) );
245246 }
246247
247248 return true ;
@@ -255,7 +256,7 @@ public boolean deleteGroup(String name) {
255256
256257 Optional <Connection > connection = getConnection ();
257258 if (!connection .isPresent ()) {
258- displayError (ConnectionError .REJECTED );
259+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . empty ()) );
259260 return false ;
260261 }
261262 try {
@@ -265,7 +266,7 @@ public boolean deleteGroup(String name) {
265266 statement .close ();
266267 connection .get ().close ();
267268 } catch (SQLException e ) {
268- displayError (ConnectionError .DATABASE_EXCEPTION , e );
269+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . of ( e )) );
269270 return false ;
270271 }
271272 return true ;
@@ -281,7 +282,7 @@ public boolean addPlayerToGroup(UUID uuid, PermissionGroup group) {
281282
282283 Optional <Connection > connection = getConnection ();
283284 if (!connection .isPresent ()) {
284- displayError (ConnectionError .REJECTED );
285+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . empty ()) );
285286 return false ;
286287 }
287288 try {
@@ -293,7 +294,7 @@ public boolean addPlayerToGroup(UUID uuid, PermissionGroup group) {
293294 connection .get ().close ();
294295 return true ;
295296 } catch (SQLException e ) {
296- displayError (ConnectionError .DATABASE_EXCEPTION , e );
297+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . of ( e )) );
297298 }
298299 return false ;
299300 }
@@ -308,7 +309,7 @@ public boolean removePlayerFromGroup(UUID uuid, PermissionGroup group) {
308309
309310 Optional <Connection > connection = getConnection ();
310311 if (!connection .isPresent ()) {
311- displayError (ConnectionError .REJECTED );
312+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . empty ()) );
312313 return false ;
313314 }
314315 try {
@@ -320,7 +321,7 @@ public boolean removePlayerFromGroup(UUID uuid, PermissionGroup group) {
320321 connection .get ().close ();
321322 return true ;
322323 } catch (SQLException e ) {
323- displayError (ConnectionError .DATABASE_EXCEPTION , e );
324+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . of ( e )) );
324325 }
325326 return false ;
326327 }
@@ -343,7 +344,7 @@ public boolean setPrimaryGroup(PermissionGroup group, UUID uuid) {
343344 group .setPrimaryGroup (uuid , true );
344345 Optional <Connection > connection = getConnection ();
345346 if (!connection .isPresent ()) {
346- displayError (ConnectionError .REJECTED );
347+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . empty ()) );
347348 return false ;
348349 }
349350
@@ -356,7 +357,7 @@ public boolean setPrimaryGroup(PermissionGroup group, UUID uuid) {
356357 statement .close ();
357358 connection .get ().close ();
358359 } catch (SQLException e ) {
359- displayError (ConnectionError .DATABASE_EXCEPTION , e );
360+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . of ( e )) );
360361 }
361362 return true ;
362363 }
@@ -370,7 +371,7 @@ public Optional<PermissionGroup> getPrimaryGroup(UUID uuid) {
370371 public void updateCache (UUID uuid ) {
371372 Optional <Connection > connection = getConnection ();
372373 if (!connection .isPresent ()) {
373- displayError (ConnectionError .REJECTED );
374+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . empty ()) );
374375 return ;
375376 }
376377 try {
@@ -405,7 +406,7 @@ public void updateCache(UUID uuid) {
405406 statement .close ();
406407 connection .get ().close ();
407408 } catch (SQLException e ) {
408- displayError (ConnectionError .DATABASE_EXCEPTION , e );
409+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . of ( e )) );
409410 }
410411 }
411412
@@ -418,7 +419,7 @@ public boolean addGroupPermission(String group, String... permissions) {
418419 for (String permission : permissions ) {
419420 Optional <Connection > connection = getConnection ();
420421 if (!connection .isPresent ()) {
421- displayError (ConnectionError .REJECTED );
422+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . empty ()) );
422423 return false ;
423424 }
424425 try {
@@ -432,7 +433,7 @@ public boolean addGroupPermission(String group, String... permissions) {
432433
433434 permissionGroup .get ().addPermission (permission );
434435 } catch (SQLException e ) {
435- displayError (ConnectionError .DATABASE_EXCEPTION , e );
436+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . of ( e )) );
436437 return false ;
437438 }
438439 }
@@ -449,7 +450,7 @@ public boolean removeGroupPermission(String group, String... permissions) {
449450 permissionGroup .get ().removePermission (permission );
450451 Optional <Connection > connection = getConnection ();
451452 if (!connection .isPresent ()) {
452- displayError (ConnectionError .REJECTED );
453+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . empty ()) );
453454 return false ;
454455 }
455456 try {
@@ -460,7 +461,7 @@ public boolean removeGroupPermission(String group, String... permissions) {
460461 statement .close ();
461462 connection .get ().close ();
462463 } catch (SQLException e ) {
463- displayError (ConnectionError .DATABASE_EXCEPTION , e );
464+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . of ( e )) );
464465 return false ;
465466 }
466467 }
@@ -481,7 +482,7 @@ public void addSuperAdmin(UUID uuid) {
481482 // Update mysql
482483 Optional <Connection > connection = getConnection ();
483484 if (!connection .isPresent ()) {
484- displayError (ConnectionError .REJECTED );
485+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . empty ()) );
485486 return ;
486487 }
487488 try {
@@ -491,7 +492,7 @@ public void addSuperAdmin(UUID uuid) {
491492 statement .close ();
492493 connection .get ().close ();
493494 } catch (SQLException e ) {
494- displayError (ConnectionError .DATABASE_EXCEPTION , e );
495+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . of ( e )) );
495496 }
496497 }
497498
@@ -500,7 +501,7 @@ public boolean isSuperAdmin(UUID uuid) {
500501 if (superAdmins .contains (uuid )) return true ;
501502 Optional <Connection > connection = getConnection ();
502503 if (!connection .isPresent ()) {
503- displayError (ConnectionError .REJECTED );
504+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . empty ()) );
504505 return false ;
505506 }
506507
@@ -517,7 +518,7 @@ public boolean isSuperAdmin(UUID uuid) {
517518 statement .close ();
518519 connection .get ().close ();
519520 } catch (SQLException e ) {
520- displayError (ConnectionError .DATABASE_EXCEPTION , e );
521+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . of ( e )) );
521522 }
522523 return false ;
523524 }
@@ -528,7 +529,7 @@ public void setChatFormat(String format) {
528529
529530 Optional <Connection > connection = getConnection ();
530531 if (!connection .isPresent ()) {
531- displayError (ConnectionError .REJECTED );
532+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . empty ()) );
532533 return ;
533534 }
534535
@@ -540,7 +541,7 @@ public void setChatFormat(String format) {
540541 statement .close ();
541542 connection .get ().close ();
542543 } catch (SQLException e ) {
543- displayError (ConnectionError .DATABASE_EXCEPTION , e );
544+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . of ( e )) );
544545 }
545546 }
546547
@@ -550,7 +551,7 @@ public String getChatFormat(boolean skipCache) {
550551
551552 Optional <Connection > connection = getConnection ();
552553 if (!connection .isPresent ()) {
553- displayError (ConnectionError .REJECTED );
554+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . empty ()) );
554555 return "" ;
555556 }
556557
@@ -576,7 +577,7 @@ public void setWhisperFormat(String format) {
576577
577578 Optional <Connection > connection = getConnection ();
578579 if (!connection .isPresent ()) {
579- displayError (ConnectionError .REJECTED );
580+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . empty ()) );
580581 return ;
581582 }
582583
@@ -588,7 +589,7 @@ public void setWhisperFormat(String format) {
588589 statement .close ();
589590 connection .get ().close ();
590591 } catch (SQLException e ) {
591- displayError (ConnectionError .DATABASE_EXCEPTION , e );
592+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . of ( e )) );
592593 }
593594 }
594595
@@ -598,7 +599,7 @@ public String getWhisperFormat(boolean skipCache) {
598599
599600 Optional <Connection > connection = getConnection ();
600601 if (!connection .isPresent ()) {
601- displayError (ConnectionError .REJECTED );
602+ PermissifyAPI . get (). ifPresent ( api -> api . getDisplayUtil (). displayError (ConnectionError .REJECTED , Optional . empty ()) );
602603 return "" ;
603604 }
604605
0 commit comments