Add libsdisguises.disguise.valid.sheep.setBurning to add extra option

This commit is contained in:
libraryaddict 2022-07-16 21:22:49 +12:00
parent 97df7e160a
commit ddab19973e
2 changed files with 53 additions and 3 deletions

View File

@ -1,5 +1,6 @@
package me.libraryaddict.disguise.utilities.parser;
import lombok.Getter;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import org.bukkit.entity.Ageable;
@ -17,6 +18,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Vector;
import java.util.stream.Collectors;
/**
* Created by libraryaddict on 14/10/2018.
@ -262,14 +264,34 @@ public class DisguisePermissions {
}
for (String valid : valids) {
HashMap<String, Boolean> options = getOptions(valid);
String key = valid.split("\\.")[1];
String[] spl = valid.split("\\.");
String key = spl[1];
if (!key.equals("*") && !key.equalsIgnoreCase(commandName)) {
continue;
}
if (spl.length > 3 && !spl[3].equals("*")) {
List<DisguisePerm> validFor =
Arrays.stream(DisguiseParser.getDisguisePerms()).filter(perm -> getInheritance(perm, spl[3]) >= 0).collect(Collectors.toList());
for (ParsedPermission perms : list) {
if (perms.disguisePerm.stream().anyMatch(p -> !validFor.contains(p))) {
continue;
}
HashMap<String, Boolean> options = getOptions(valid.replaceFirst("\\.valid", ""));
perms.options.putAll(options);
}
if (!validFor.isEmpty()) {
continue;
}
}
HashMap<String, Boolean> options = getOptions(valid);
for (ParsedPermission perms : list) {
perms.options.putAll(options);
}

View File

@ -215,6 +215,34 @@ public class DisguisePermissionsTest {
DisguisePermissions.hasPermissionOption(disguiseOptions, "setBlock", "DIRT"));
}
@Test
public void testDisguiseValidWorksToGiveMore() {
DisguisePermissions permissions =
createPermissions("Disguise", false, "libsdisguises.disguise.falling_block.setCustomName", "libsdisguises.disguise.valid.falling_block.setblock");
Assert.assertFalse("The falling block disguise should not allow setBurning",
permissions.isAllowedDisguise(new DisguisePerm(DisguiseType.FALLING_BLOCK), Arrays.asList("setBurning")));
Assert.assertTrue("The falling block disguise should allow setCustomName",
permissions.isAllowedDisguise(new DisguisePerm(DisguiseType.FALLING_BLOCK), Arrays.asList("setcustomname")));
Assert.assertTrue("The falling block disguise should allow setBlock",
permissions.isAllowedDisguise(new DisguisePerm(DisguiseType.FALLING_BLOCK), Arrays.asList("setBlock")));
}
@Test
public void testDisguiseValidDoesntGiveExtra() {
DisguisePermissions permissions = createPermissions("Disguise", false, "libsdisguises.disguise.valid.falling_block.setblock");
Assert.assertFalse("The falling block disguise should not be allowed", permissions.isAllowedDisguise(new DisguisePerm(DisguiseType.FALLING_BLOCK)));
Assert.assertFalse("The falling block disguise should not allow setBurning",
permissions.isAllowedDisguise(new DisguisePerm(DisguiseType.FALLING_BLOCK), Arrays.asList("setBurning")));
Assert.assertFalse("The falling block disguise should not allow setBlock",
permissions.isAllowedDisguise(new DisguisePerm(DisguiseType.FALLING_BLOCK), Arrays.asList("setBlock")));
}
@SneakyThrows
@Test
public void testCustomDisguisePermissions() {