Skip to content

Commit 99bc686

Browse files
authored
Merge pull request #54 from ifydev/develop
1.0
2 parents d6977e0 + f314aa7 commit 99bc686

32 files changed

+784
-830
lines changed

API/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,11 @@
1010

1111
<artifactId>PermissifyAPI</artifactId>
1212

13+
<dependencies>
14+
<dependency>
15+
<groupId>com.google.code.gson</groupId>
16+
<artifactId>gson</artifactId>
17+
<version>2.8.0</version>
18+
</dependency>
19+
</dependencies>
1320
</project>

API/src/main/java/me/innectic/permissify/api/PermissifyAPI.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,16 @@
2828
import me.innectic.permissify.api.database.ConnectionInformation;
2929
import me.innectic.permissify.api.database.DatabaseHandler;
3030
import me.innectic.permissify.api.database.handlers.HandlerType;
31+
import me.innectic.permissify.api.module.registry.ModuleLoader;
32+
import me.innectic.permissify.api.module.registry.ModuleProvider;
3133
import me.innectic.permissify.api.profile.ProfileSerializer;
3234
import me.innectic.permissify.api.util.DisplayUtil;
3335

3436
import java.lang.reflect.InvocationTargetException;
3537
import java.util.ArrayList;
3638
import java.util.Optional;
39+
import java.util.logging.Level;
40+
import java.util.logging.Logger;
3741

3842
/**
3943
* @author Innectic
@@ -45,15 +49,22 @@ public class PermissifyAPI {
4549

4650
@Getter private Optional<DatabaseHandler> databaseHandler;
4751
@Getter private DisplayUtil displayUtil;
48-
@Getter private ProfileSerializer serializer;
52+
@Getter private ProfileSerializer profileSerializer;
53+
@Getter private Logger logger;
54+
55+
@Getter private ModuleProvider moduleProvider;
56+
@Getter private ModuleLoader moduleLoader;
4957

5058
/**
5159
* Initialize Permissify's API
5260
*/
53-
public void initialize(HandlerType type, Optional<ConnectionInformation> connectionInformation, DisplayUtil displayUtil) throws Exception {
61+
public void initialize(HandlerType type, Optional<ConnectionInformation> connectionInformation, DisplayUtil displayUtil, Logger logger, String moduleLocation, Object plugin) throws Exception {
5462
instance = Optional.of(this);
63+
this.logger = logger;
5564
this.displayUtil = displayUtil;
56-
serializer = new ProfileSerializer();
65+
profileSerializer = new ProfileSerializer();
66+
moduleProvider = new ModuleProvider();
67+
moduleLoader = new ModuleLoader(moduleLocation);
5768

5869
try {
5970
databaseHandler = Optional.of(type.getHandler().getConstructor(ConnectionInformation.class).newInstance(connectionInformation.orElse(null)));
@@ -65,9 +76,11 @@ public void initialize(HandlerType type, Optional<ConnectionInformation> connect
6576
handler.initialize();
6677
handler.reload(new ArrayList<>());
6778
boolean connected = handler.connect();
68-
if (connected) System.out.println("Connected to the database.");
69-
else System.out.println("Unable to connect to the database.");
79+
if (connected) logger.info("Connected to the database.");
80+
else logger.log(Level.SEVERE, "Unable to connect to the database.");
7081
});
82+
logger.info("Registering modules...");
83+
moduleLoader.loadModules(plugin);
7184
}
7285

7386
public static Optional<PermissifyAPI> get() {

API/src/main/java/me/innectic/permissify/api/PermissifyConstants.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
public class PermissifyConstants {
3838
// TODO: Create a language formatter to allow for translating.
3939

40+
public static final int PERMISSIFY_PROFILE_VERSION = 2;
41+
4042
// Chat messages
4143
private static final String PERMISSIFY_PREFIX = "&a&lPermissify> ";
4244

@@ -75,30 +77,30 @@ public class PermissifyConstants {
7577
public static final String PERMISSION_REMOVED_GROUP = PERMISSIFY_PREFIX + "&e&lPermission <PERMISSION> has been removed from <GROUP>!";
7678

7779
public static final String PERMISSION_ADDED_PLAYER = PERMISSIFY_PREFIX + "&e&lPermission <PERMISSION> has been added to <PLAYER>!";
80+
public static final String PERMISSION_ADDED_PLAYER_TIMED = PERMISSIFY_PREFIX + "&e&lPermission <PERMISSION> has been added to <PLAYER>, and will expire in <SECONDS>!";
7881
public static final String PERMISSION_REMOVED_PLAYER = PERMISSIFY_PREFIX + "&e&lPermission <PERMISSION> has been removed from <PLAYER>!";
7982
public static final String PLAYER_ADDED_TO_GROUP = PERMISSIFY_PREFIX + "&e&lAdded <PLAYER> to <GROUP>";
8083
public static final String PLAYER_REMOVED_FROM_GROUP = PERMISSIFY_PREFIX + "&e&lRemoved <PLAYER> from <GROUP>";
81-
public static final String FORMATTER_SET = PERMISSIFY_PREFIX + "&e&lFormatter <FORMATTER> set!";
8284
public static final String MAIN_GROUP_SET = PERMISSIFY_PREFIX + "&e&lSet main group for <PLAYER> to <GROUP>!";
83-
public static final String TOGGLED_CHAT_HANDLE = PERMISSIFY_PREFIX + "&e&l<STATE> chat formatting.";
85+
public static final String PLAYER_ALREADY_HAS_PERMISSION = PERMISSIFY_PREFIX + "&c&lPlayer <PLAYER> already has permission <PERMISSION>";
86+
public static final String PLAYER_DOES_NOT_HAVE_PERMISSION = PERMISSIFY_PREFIX + "&c&lPlayer <PLAYER> does not have permission <PERMISSION>";
8487

8588
public static final String EMPTY_DEFAULT_GROUP_NAME = "&c&lNONE";
8689
public static final String DEFAULT_GROUP_RESPONSE = PERMISSIFY_PREFIX + "&e&lThe current default group is '<GROUP>&e&l'.";
8790
public static final String DEFAULT_GROUP_SET = PERMISSIFY_PREFIX + "&e&lThe default group has been set to '<GROUP>&e&l'.";
8891

8992
public static final String NOT_ENOUGH_ARGUMENTS_GROUP_CREATE = PERMISSIFY_PREFIX + "&c&lNot enough arguments! &e&l/permissify group create [name] [prefix] [suffix] [chat-color]";
9093
public static final String NOT_ENOUGH_ARGUMENTS_GROUP_REMOVE = PERMISSIFY_PREFIX + "&c&lNot enough arguments! &e&l/permissify group remove [name]";
91-
public static final String NOT_ENOUGH_ARGUMENTS_GROUP_PERMISSION_ADD = PERMISSIFY_PREFIX + "&c&lNot enough arguments! &e&l/permissify group addpermission [name] [permission]";
92-
public static final String NOT_ENOUGH_ARGUMENTS_GROUP_PERMISSION_REMOVE = PERMISSIFY_PREFIX + "&c&lNot enough arguments! &e&l/permissify group removepermission [name] [permission]";
94+
public static final String NOT_ENOUGH_ARGUMENTS_GROUP_PERMISSION_ADD = PERMISSIFY_PREFIX + "&c&lNot enough arguments! &e&l/permissify group addpermission [group] [permission]";
95+
public static final String NOT_ENOUGH_ARGUMENTS_GROUP_PERMISSION_REMOVE = PERMISSIFY_PREFIX + "&c&lNot enough arguments! &e&l/permissify group removepermission [group] [permission]";
9396
public static final String NOT_ENOUGH_ARGUMENTS_GROUP_PERMISSION_LIST = PERMISSIFY_PREFIX + "&c&lNot enough arguments! &e&l/permissify group listpermissions [group]";
9497
public static final String NOT_ENOUGH_ARGUMENTS_PLAYER = PERMISSIFY_PREFIX + "&c&lNot enough arguments! &e&l/permissify player [addgroup|removegroup|listpermissions|listgroups|addpermission|removepermission] [player]";
95-
public static final String NOT_ENOUGH_ARGUMENTS_PLAYER_ADD_PERMISSION = PERMISSIFY_PREFIX + "&c&lNot enough arguments! &e&l/permissify player addpermission [permission] [player]";
96-
public static final String NOT_ENOUGH_ARGUMENTS_PLAYER_REMOVE_PERMISSION = PERMISSIFY_PREFIX + "&c&lNot enough arguments! &e&l/permissify player removepermission [permission] [player]";
98+
public static final String NOT_ENOUGH_ARGUMENTS_PLAYER_ADD_PERMISSION = PERMISSIFY_PREFIX + "&c&lNot enough arguments! &e&l/permissify player addpermission [player] [permission]";
99+
public static final String NOT_ENOUGH_ARGUMENTS_PLAYER_REMOVE_PERMISSION = PERMISSIFY_PREFIX + "&c&lNot enough arguments! &e&l/permissify player removepermission [player] [permission]";
97100
public static final String NOT_ENOUGH_ARGUMENTS_PLAYER_LIST_PERMISSIONS = PERMISSIFY_PREFIX + "&c&lNot enough arguments! &e&l/permissify player listpermissions [player]";
98-
public static final String NOT_ENOUGH_ARGUMENTS_PLAYER_ADD_GROUP= PERMISSIFY_PREFIX + "&c&lNot enough arguments! &e&l/permissify player addgroup [group] [player]";
99-
public static final String NOT_ENOUGH_ARGUMENTS_PLAYER_REMOVE_GROUP= PERMISSIFY_PREFIX + "&c&lNot enough arguments! &e&l/permissify player removegroup [group] [player]";
101+
public static final String NOT_ENOUGH_ARGUMENTS_PLAYER_ADD_GROUP= PERMISSIFY_PREFIX + "&c&lNot enough arguments! &e&l/permissify player addgroup [player] [group]";
102+
public static final String NOT_ENOUGH_ARGUMENTS_PLAYER_REMOVE_GROUP= PERMISSIFY_PREFIX + "&c&lNot enough arguments! &e&l/permissify player removegroup [player] [group]";
100103
public static final String NOT_ENOUGH_ARGUMENTS_PLAYER_LIST_GROUP = PERMISSIFY_PREFIX + "&c&lNot enough arguments! &e&l/permissify player listgroup [player]";
101-
public static final String NOT_ENOUGH_ARGUMENTS_SET_FORMAT = PERMISSIFY_PREFIX + "&c&lNot enough arguments! &e&l/permissify format [whisper|chat|disable|enable] [format?...]";
102104
public static final String NOT_ENOUGH_ARGUMENTS_SET_MAIN_GROUP = PERMISSIFY_PREFIX + "&c&lNot enough arguments! &e&l/permissify player setmain [player] [group]";
103105
public static final String NOT_ENOUGH_ARGUMENTS_PROFILE = PERMISSIFY_PREFIX + "&c&lNot enough arguments! &e&l/permissify profile [save|load] [profile]";
104106
public static final String NOT_ENOUGH_ARGUMENTS_PROFILE_SAVE = PERMISSIFY_PREFIX + "&c&lNot enough arguments! &e&l/permissify profile save [fileName]";
@@ -132,24 +134,19 @@ public class PermissifyConstants {
132134
"&a&l/permissify superadmin [player] - &c&lWARNING: &e&lSUPERADMIN GIVES PERMISSION FOR EVERYTHING!",
133135
"&a&l/permissify cache",
134136
"&a&l/permissify cache purge",
135-
"&a&l/permissify format chat [format]",
136-
"&a&l/permissify format whisper [format]",
137-
"&a&l/permissify format enable",
138-
"&a&l/permissify format disable",
139137
"&a&l/permissify group create [name] [prefix] [suffix] [chatcolor]",
140-
"&a&l/permissify group remove [name]"
138+
"&a&l/permissify group remove [name]",
139+
"&a&l/permissify group addpermission [group] [permissions...] [(optional) lifespan]",
140+
"&a&l/permissify group removepermission [group] [permissions...]"
141141
), Arrays.asList(
142-
"&a&l/permissify group addpermission [group] [permissions...]",
143-
"&a&l/permissify group removepermission [group] [permissions...]",
144142
"&a&l/permissify group listpermissions [group]",
145143
"&a&l/permissify group list",
146144
"&a&l/permissify player addpermission [permission] [player]",
147145
"&a&l/permissify player removepermission [permission] [player]",
148146
"&a&l/permissify player addgroup [player] [group]",
149147
"&a&l/permissify player listpermissions [player]",
150148
"&a&l/permissify player listgroups [player]",
151-
"&a&l/permissify player removegroup [player] [group]"
152-
), Arrays.asList(
149+
"&a&l/permissify player removegroup [player] [group]",
153150
"&a&l/permissify player setmain [player] [group]",
154151
"&a&l/permissify group default [group?]"
155152
)));

API/src/main/java/me/innectic/permissify/api/database/DatabaseHandler.java

Lines changed: 45 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
package me.innectic.permissify.api.database;
2626

2727
import lombok.Getter;
28-
import lombok.Setter;
2928
import me.innectic.permissify.api.permission.Permission;
3029
import me.innectic.permissify.api.permission.PermissionGroup;
3130
import me.innectic.permissify.api.profile.PermissifyProfile;
@@ -41,12 +40,10 @@
4140
public 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

Comments
 (0)