Skip to content

Commit fbe51f8

Browse files
authored
Merge pull request #49 from ifydev/feature/group-display-names
Add group display names
2 parents b91d3e8 + 6ee7713 commit fbe51f8

File tree

4 files changed

+19
-16
lines changed

4 files changed

+19
-16
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,14 @@ public DatabaseHandler(ConnectionInformation connectionInformation) {
136136
/**
137137
* Create a new permission group.
138138
*
139-
* @param name the 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
144-
*/
145-
public abstract boolean createGroup(String name, String prefix, String suffix, String chatColor);
139+
* @param name the name of the group
140+
* @param displayName the display name of the group
141+
* @param prefix the prefix of the name
142+
* @param suffix the suffix of the name
143+
* @param chatColor the color of the chat message
144+
* @return if the group was created
145+
*/
146+
public abstract boolean createGroup(String name, String displayName, String prefix, String suffix, String chatColor);
146147

147148
/**
148149
* Delete a permission group

API/src/main/java/me/innectic/permissify/api/database/handlers/SQLHandler.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public void initialize() {
113113
groupPermissionsStatement.close();
114114

115115
PreparedStatement groupsStatement = connection.get().prepareStatement("CREATE TABLE IF NOT EXISTS " + database +
116-
"groups (name 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))");
116+
"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))");
117117
groupsStatement.execute();
118118
groupsStatement.close();
119119

@@ -200,7 +200,9 @@ protected void loadGroups() {
200200
ResultSet groupResults = groupStatement.executeQuery();
201201
while (groupResults.next()) {
202202
String groupName = groupResults.getString("name");
203+
String displayName = groupResults.getString("displayName");
203204
PermissionGroup group = new PermissionGroup(groupName,
205+
displayName,
204206
groupResults.getString("chatcolor"),
205207
groupResults.getString("prefix"),
206208
groupResults.getString("suffix"), getGroupLadder(groupName).orElse(new DefaultLadder()));
@@ -321,7 +323,7 @@ public void loadProfile(PermissifyProfile profile) {
321323
}));
322324
// Create groups
323325
profile.getGroups().forEach((key, group) -> {
324-
createGroup(group.getName(), group.getPrefix(), group.getSuffix(), group.getChatColor());
326+
createGroup(group.getName(), group.getDisplayName(), group.getPrefix(), group.getSuffix(), group.getChatColor());
325327
Optional<PermissionGroup> created = getGroup(group.getName());
326328
if (!created.isPresent()) {
327329
PermissifyAPI.get().ifPresent(api -> api.getLogger().log(Level.WARNING, "Profile group was never created?"));
@@ -471,11 +473,11 @@ public List<Permission> getPermissions(UUID uuid) {
471473
}
472474

473475
@Override
474-
public boolean createGroup(String name, String prefix, String suffix, String chatColor) {
476+
public boolean createGroup(String name, String displayName, String prefix, String suffix, String chatColor) {
475477
// Make sure that this group doesn't already exist
476478
if (cachedGroups.getOrDefault(name, null) != null) return false;
477479
// Add the new group to the cache
478-
cachedGroups.put(name, new PermissionGroup(name, chatColor, prefix, suffix, new DefaultLadder()));
480+
cachedGroups.put(name, new PermissionGroup(name, displayName, chatColor, prefix, suffix, new DefaultLadder()));
479481

480482
Optional<Connection> connection = getConnection();
481483
if (!connection.isPresent()) {
@@ -647,7 +649,7 @@ public void updateCache(UUID uuid) {
647649
ResultSet groupResults = groupStatement.executeQuery();
648650
if (!groupResults.next()) return;
649651
PermissionGroup permissionGroup = new PermissionGroup(
650-
groupName, groupResults.getString("chatcolor"), groupResults.getString("prefix"),
652+
groupName, groupResults.getString("displayName"), groupResults.getString("chatcolor"), groupResults.getString("prefix"),
651653
groupResults.getString("suffix"), getGroupLadder(groupName).orElse(new DefaultLadder()));
652654
groupResults.close();
653655
groupStatement.close();

API/src/main/java/me/innectic/permissify/api/group/group/PermissionGroup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import me.innectic.permissify.api.group.Permission;
3232
import me.innectic.permissify.api.group.ladder.AbstractLadder;
3333

34-
import java.io.Serializable;
3534
import java.util.*;
3635

3736
/**
@@ -41,6 +40,7 @@
4140
@RequiredArgsConstructor
4241
public class PermissionGroup {
4342
@Getter private final String name;
43+
@Getter private final String displayName;
4444
@Getter private final String chatColor;
4545
@Getter private final String prefix;
4646
@Getter private final String suffix;

Spigot/src/main/java/me/innectic/permissify/spigot/commands/permissify/GroupCommand.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ public String handleAddGroup(CommandSender sender, String[] args) {
6161
if (!plugin.getPermissifyAPI().getDatabaseHandler().isPresent())
6262
return PermissifyConstants.UNABLE_TO_CREATE.replace("<TYPE>", "group").replace("<REASON>", "No database handler.");
6363

64-
if (args.length < 4) return PermissifyConstants.NOT_ENOUGH_ARGUMENTS_GROUP_CREATE;
65-
if (!ColorUtil.isValidChatColor(args[3])) return PermissifyConstants.INVALID_CHATCOLOR.replace("<COLOR>", args[3]);
64+
if (args.length < 5) return PermissifyConstants.NOT_ENOUGH_ARGUMENTS_GROUP_CREATE;
65+
if (!ColorUtil.isValidChatColor(args[4])) return PermissifyConstants.INVALID_CHATCOLOR.replace("<COLOR>", args[4]);
6666

6767
// Create the new group
68-
boolean created = plugin.getPermissifyAPI().getDatabaseHandler().get().createGroup(args[0], args[1], args[2], args[3]);
68+
boolean created = plugin.getPermissifyAPI().getDatabaseHandler().get().createGroup(args[0], args[1], args[2], args[3], args[4]);
6969
if (created) return PermissifyConstants.GROUP_CREATED.replace("<GROUP>", args[0]);
7070
return PermissifyConstants.UNABLE_TO_CREATE.replace("<TYPE>", "group").replace("<REASON>", "Unable to connect to database.");
7171
}

0 commit comments

Comments
 (0)