Fix permissions somewhat for negating with a wildcard for options

This commit is contained in:
libraryaddict 2022-04-01 18:18:55 +13:00
parent 56eaa1c8c4
commit cfc1eb27b9
3 changed files with 38 additions and 11 deletions

View File

@ -733,7 +733,6 @@ public class DisguiseParser {
toSkip++; toSkip++;
} }
} else if (disguisePerm.isMob()) { // Its a mob, use the mob constructor } else if (disguisePerm.isMob()) { // Its a mob, use the mob constructor
if (args.length > 1) { if (args.length > 1) {
boolean adult = true; boolean adult = true;

View File

@ -151,7 +151,7 @@ public class DisguisePermissions {
// If this refers to a specific disguise // If this refers to a specific disguise
if (dPerm != null) { if (dPerm != null) {
return new ParsedPermission(new DisguisePerm[]{dPerm}, options, (byte) 0, split[1].equals("*")); return new ParsedPermission(new DisguisePerm[]{dPerm}, options, (byte) (options.containsKey("*") ? 1 : 0), split[1].equals("*"));
} }
// If the disguise can't be found, it may be refering to a range // If the disguise can't be found, it may be refering to a range
@ -403,34 +403,34 @@ public class DisguisePermissions {
if (permissionName.equals("ageable")) { if (permissionName.equals("ageable")) {
if (Ageable.class.isAssignableFrom(disguiseType.getEntityClass())) { if (Ageable.class.isAssignableFrom(disguiseType.getEntityClass())) {
return 1; return 2;
} }
} else if (permissionName.equals("monster") || permissionName.equals("monsters")) { } else if (permissionName.equals("monster") || permissionName.equals("monsters")) {
if (Monster.class.isAssignableFrom(disguiseType.getEntityClass())) { if (Monster.class.isAssignableFrom(disguiseType.getEntityClass())) {
return 2; return 3;
} }
} else if (permissionName.equals("animal") || permissionName.equals("animals")) { } else if (permissionName.equals("animal") || permissionName.equals("animals")) {
if (Animals.class.isAssignableFrom(disguiseType.getEntityClass())) { if (Animals.class.isAssignableFrom(disguiseType.getEntityClass())) {
return 2; return 3;
} }
} else if (permissionName.equals("mob")) { } else if (permissionName.equals("mob")) {
if (disguiseType.isMob()) { if (disguiseType.isMob()) {
return 3; return 4;
} }
} else if (permissionName.equals("misc")) { } else if (permissionName.equals("misc")) {
if (disguiseType.isMisc()) { if (disguiseType.isMisc()) {
return 3; return 4;
} }
} else if (permissionName.equals("custom")) { } else if (permissionName.equals("custom")) {
if (disguisePerm.isCustomDisguise()) { if (disguisePerm.isCustomDisguise()) {
return 3; return 4;
} }
} else if (permissionName.equals("vanilla")) { } else if (permissionName.equals("vanilla")) {
if (!disguisePerm.isCustomDisguise()) { if (!disguisePerm.isCustomDisguise()) {
return 4; return 5;
} }
} else if (permissionName.equals("*")) { } else if (permissionName.equals("*")) {
return 5; return 6;
} }
return -1; return -1;

View File

@ -1,5 +1,7 @@
package me.libraryaddict.disguise.utilities.parser; package me.libraryaddict.disguise.utilities.parser;
import lombok.SneakyThrows;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import org.bukkit.permissions.Permissible; import org.bukkit.permissions.Permissible;
@ -213,6 +215,33 @@ public class DisguisePermissionsTest {
DisguisePermissions.hasPermissionOption(disguiseOptions, "setBlock", "DIRT")); DisguisePermissions.hasPermissionOption(disguiseOptions, "setBlock", "DIRT"));
} }
@SneakyThrows
@Test
public void testCustomDisguisePermissions() {
DisguiseConfig.getCustomDisguises().put(new DisguisePerm(DisguiseType.BEE, "babybee"), "bee setbaby");
DisguisePermissions permissions = createPermissions("disguise", false, "libsdisguises.disguise.bee.-*", "libsdisguises.disguise.babybee.nooptions");
Assert.assertNotNull("The custom disguise babybee should exist", DisguiseParser.getDisguisePerm("babybee"));
Assert.assertTrue("They should be allowed to disguise as a bee", permissions.isAllowedDisguise(new DisguisePerm(DisguiseType.BEE)));
Assert.assertFalse("They should not be allowed to disguise as a bee and call setbaby",
permissions.isAllowedDisguise(new DisguisePerm(DisguiseType.BEE), Collections.singletonList("setbaby")));
Assert.assertFalse("They should not be allowed to disguise as a burning bee",
permissions.isAllowedDisguise(new DisguisePerm(DisguiseType.BEE), Collections.singletonList("setburning")));
Assert.assertFalse("They should not be allowed to disguise as a slime", permissions.isAllowedDisguise(new DisguisePerm(DisguiseType.SLIME)));
Assert.assertTrue("They should be allowed to disguise as babybee", permissions.isAllowedDisguise(DisguiseParser.getDisguisePerm("babybee")));
Assert.assertFalse("They should not be allowed to disguise as babybee and use setbaby",
permissions.isAllowedDisguise(DisguiseParser.getDisguisePerm("babybee"), Collections.singletonList("setbaby")));
DisguiseAPI.removeCustomDisguise("babybee");
}
@Test @Test
public void testExplictPermissions() { public void testExplictPermissions() {
DisguiseConfig.setExplicitDisguisePermissions(true); DisguiseConfig.setExplicitDisguisePermissions(true);
@ -256,7 +285,6 @@ public class DisguisePermissionsTest {
} }
private Permissible createPermissionsHolder(boolean isOp, String... perms) { private Permissible createPermissionsHolder(boolean isOp, String... perms) {
List<String> permitted = new ArrayList<>(); List<String> permitted = new ArrayList<>();
List<String> negated = new ArrayList<>(); List<String> negated = new ArrayList<>();
Set<PermissionAttachmentInfo> attachments = new HashSet<>(); Set<PermissionAttachmentInfo> attachments = new HashSet<>();