Skip to content

Commit

Permalink
Add permissions for individual color codes
Browse files Browse the repository at this point in the history
Resolves #415
  • Loading branch information
Pokechu22 committed Aug 5, 2017
1 parent 54127fa commit 22f8f7a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Essentials/src/com/earth2me/essentials/utils/FormatUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ public static String formatString(final IUser user, final String permBase, Strin
if (user.isAuthorized(permBase + ".format")) {
supported.addAll(FORMATS);
}
for (ChatColor chatColor : ChatColor.values()) {
if (user.isAuthorized(permBase + "." + chatColor.getChar())) {
supported.add(chatColor);
}
}
EnumSet<ChatColor> strip = EnumSet.complementOf(supported);

if (!supported.isEmpty()) {
Expand Down
14 changes: 14 additions & 0 deletions Essentials/test/com/earth2me/essentials/utils/FormatUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ public void testFormatCategoryPerms() {
checkFormatPerms("§f§ltest", "§f§ltest", "color", "format");
}

public void testFormatCodePerms() {
checkFormatPerms("&1Te&2st", "&1Te&2st");
checkFormatPerms("§1Te§2st", "Test");

checkFormatPerms("&1Te&2st", "§1Te&2st", "code.1");
checkFormatPerms("§1Te§2st", "§1Test", "code.1");

checkFormatPerms("&1Te&2st", "&1Te§2st", "code.2");
checkFormatPerms("§1Te§2st", "Te§2st", "code.2");

checkFormatPerms("&1Te&2st", "§1Te§2st", "code.1", "code.2");
checkFormatPerms("§1Te§2st", "§1Te§2st", "code.1", "code.2");
}

private void checkFormatPerms(String input, String expectedOutput, String... perms) {
IUser user = mock(IUser.class);
for (String perm : perms) {
Expand Down

0 comments on commit 22f8f7a

Please sign in to comment.