2525package me .innectic .permissify .api .database ;
2626
2727import lombok .Getter ;
28- import lombok .Setter ;
2928import me .innectic .permissify .api .permission .Permission ;
3029import me .innectic .permissify .api .permission .PermissionGroup ;
3130import me .innectic .permissify .api .profile .PermissifyProfile ;
4140public abstract class DatabaseHandler {
4241
4342 @ Getter protected Map <UUID , List <Permission >> cachedPermissions = new HashMap <>();
44- @ Getter protected List < PermissionGroup > cachedGroups = new ArrayList <>();
43+ @ Getter protected Map < String , PermissionGroup > cachedGroups = new HashMap <>();
4544 @ Getter protected Optional <PermissionGroup > defaultGroup = Optional .empty ();
4645 @ Getter protected final Optional <ConnectionInformation > connectionInformation ;
4746 @ Getter protected List <UUID > superAdmins = new ArrayList <>();
48- protected String chatFormat = "{group} {username}: {message}" ;
49- protected String whisperFormat = "{senderGroup} {username} > {receiverGroup} {to}: {message}" ;
5047
5148 public DatabaseHandler (ConnectionInformation connectionInformation ) {
5249 this .connectionInformation = Optional .ofNullable (connectionInformation );
@@ -71,6 +68,16 @@ public DatabaseHandler(ConnectionInformation connectionInformation) {
7168 */
7269 public abstract void reload (List <UUID > onlinePlayers );
7370
71+ /**
72+ * Load all groups
73+ */
74+ protected abstract void loadGroups ();
75+
76+ /**
77+ * Load all super admins
78+ */
79+ protected abstract void loadSuperAdmins ();
80+
7481 /**
7582 * Drop all values from the handler.
7683 */
@@ -104,28 +111,38 @@ public DatabaseHandler(ConnectionInformation connectionInformation) {
104111 *
105112 * @param uuid the uuid of the player to check
106113 * @param permission the permission to check
107- * @return if the player has the permission
114+ * @return if the player has the permission, regardless of the granted status
108115 */
109116 public abstract boolean hasPermission (UUID uuid , String permission );
110117
118+ /**
119+ * Does a player have a permission granted to them?
120+ *
121+ * @param uuid the uuid of the player to check
122+ * @param permission the permission to check for
123+ * @return if the player has the permission
124+ */
125+ public abstract boolean isGrantedPermission (UUID uuid , String permission );
126+
111127 /**
112128 * Get the permissions of a uuid
113129 *
114130 * @param uuid the uuid to get the permissions of
115- * @return the permissions the uuid has
131+ * @return the permissions the uuid has
116132 */
117133 public abstract List <Permission > getPermissions (UUID uuid );
118134
119135 /**
120136 * Create a new permission group.
121137 *
122- * @param name the name of the group
123- * @param prefix the prefix of the name
124- * @param suffix the suffix of the name
125- * @param chatColor the color of the chat message
126- * @return if the group was created
138+ * @param name the name of the group
139+ * @param displayName the display name of the group
140+ * @param prefix the prefix of the name
141+ * @param suffix the suffix of the name
142+ * @param chatColor the color of the chat message
143+ * @return if the group was created
127144 */
128- public abstract boolean createGroup (String name , String prefix , String suffix , String chatColor );
145+ public abstract boolean createGroup (String name , String displayName , String prefix , String suffix , String chatColor );
129146
130147 /**
131148 * Delete a permission group
@@ -138,7 +155,7 @@ public DatabaseHandler(ConnectionInformation connectionInformation) {
138155 * Get the permission group from name.
139156 *
140157 * @param name the name of the group.
141- * @return fulfilled if exists, empty otherwise
158+ * @return fulfilled if exists, empty otherwise
142159 */
143160 public abstract Optional <PermissionGroup > getGroup (String name );
144161
@@ -147,7 +164,7 @@ public DatabaseHandler(ConnectionInformation connectionInformation) {
147164 *
148165 * @param uuid the uuid of the player
149166 * @param group the group to add them to
150- * @return if they were added
167+ * @return if they were added
151168 */
152169 public abstract boolean addPlayerToGroup (UUID uuid , PermissionGroup group );
153170
@@ -156,7 +173,7 @@ public DatabaseHandler(ConnectionInformation connectionInformation) {
156173 *
157174 * @param uuid the player to remove
158175 * @param group the group to remove from
159- * @return if the player was removed
176+ * @return if the player was removed
160177 */
161178 public abstract boolean removePlayerFromGroup (UUID uuid , PermissionGroup group );
162179
@@ -165,13 +182,13 @@ public DatabaseHandler(ConnectionInformation connectionInformation) {
165182 *
166183 * @return the registered permission groups
167184 */
168- public abstract List < PermissionGroup > getGroups ();
185+ public abstract Map < String , PermissionGroup > getGroups ();
169186
170187 /**
171188 * Get all permission groups a player is in.
172189 *
173190 * @param uuid the uuid of the player
174- * @return the groups the player is in
191+ * @return the groups the player is in
175192 */
176193 public abstract List <PermissionGroup > getGroups (UUID uuid );
177194
@@ -187,7 +204,7 @@ public DatabaseHandler(ConnectionInformation connectionInformation) {
187204 * Get the primary group of a player.
188205 *
189206 * @param uuid the uuid of the player to get
190- * @return the primary group of the player
207+ * @return the primary group of the player
191208 */
192209 public abstract Optional <PermissionGroup > getPrimaryGroup (UUID uuid );
193210
@@ -203,7 +220,7 @@ public DatabaseHandler(ConnectionInformation connectionInformation) {
203220 *
204221 * @param group the group to add to
205222 * @param permissions the permissions to add
206- * @return if it was added or not
223+ * @return if it was added or not
207224 */
208225 public abstract boolean addGroupPermission (String group , String ... permissions );
209226
@@ -212,7 +229,7 @@ public DatabaseHandler(ConnectionInformation connectionInformation) {
212229 *
213230 * @param group the group to remove from
214231 * @param permissions the permissions to remove
215- * @return if the permissions were removed
232+ * @return if the permissions were removed
216233 */
217234 public abstract boolean removeGroupPermission (String group , String ... permissions );
218235
@@ -221,7 +238,7 @@ public DatabaseHandler(ConnectionInformation connectionInformation) {
221238 *
222239 * @param group the group to check
223240 * @param permission the permission to check
224- * @return if the group has the permission
241+ * @return if the group has the permission
225242 */
226243 public abstract boolean hasGroupPermission (String group , String permission );
227244
@@ -239,40 +256,17 @@ public DatabaseHandler(ConnectionInformation connectionInformation) {
239256 */
240257 public abstract boolean isSuperAdmin (UUID uuid );
241258
242- /**
243- * Set the format for chat messages
244- *
245- * @param format the format for chat.
246- */
247- public abstract void setChatFormat (String format );
248-
249- /**
250- * Get the format for public chat messages
251- *
252- * @param skipCache should the cache be skipped? Forces getting from the database
253- * @return the format
254- */
255- public abstract String getChatFormat (boolean skipCache );
256-
257- /**
258- * Set the format of whispers
259- *
260- * @param format the format for whispers.
261- */
262- public abstract void setWhisperFormat (String format );
263-
264- /**
265- * Get the format for whispers.
259+ /***
260+ * Remove a superadmin.
266261 *
267- * @param skipCache should the cache be skipped? Forces getting from the database
268- * @return the format
262+ * @param uuid the uuid of the player to remove
269263 */
270- public abstract String getWhisperFormat ( boolean skipCache );
264+ public abstract void removeSuperAdmin ( UUID uuid );
271265
272266 /**
273- * Set the default permission group to the one provided.
267+ * Set the default group players are in when they join for the first time
274268 *
275- * @param group the new group to become the default.
269+ * @param group the default group
276270 */
277271 public abstract void setDefaultGroup (PermissionGroup group );
278- }
272+ }
0 commit comments