Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/src/fancydialogs/tutorials/json-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ Items will be supported in the body section in a future release.
`requirements`: The requirement for this field to display
- `type`: Either `permission` or `stringMatch`.
- `permission`: If type is `permission`, this is the permission to check for.
- `value`: If type is `permission`, whether the player should have the permission. `true` (default) requires the player to have the permission, `false` requires the player to NOT have it.
- `input`: If type is `stringMatch`, this is the string being matched against `output`.
- `output`: If type is `stringMatch`, this is the string being matched against `input`.

Expand All @@ -130,6 +131,7 @@ More input types will be added in future releases, such as checkboxes and number
`requirements`: The requirement for this field to display
- `type`: Either `permission` or `stringMatch`.
- `permission`: If type is `permission`, this is the permission to check for.
- `value`: If type is `permission`, whether the player should have the permission. `true` (default) requires the player to have the permission, `false` requires the player to NOT have it.
- `input`: If type is `stringMatch`, this is the string being matched against `output`.
- `output`: If type is `stringMatch`, this is the string being matched against `input`.

Expand All @@ -151,6 +153,7 @@ More input types will be added in future releases, such as checkboxes and number
`requirements`: The requirement for this field to display
- `type`: Either `permission` or `stringMatch`.
- `permission`: If type is `permission`, this is the permission to check for.
- `value`: If type is `permission`, whether the player should have the permission. `true` (default) requires the player to have the permission, `false` requires the player to NOT have it.
- `input`: If type is `stringMatch`, this is the string being matched against `output`.
- `output`: If type is `stringMatch`, this is the string being matched against `input`.

Expand All @@ -165,6 +168,7 @@ More input types will be added in future releases, such as checkboxes and number
- `requirements`: The requirement for this field to display
- `type`: Either `permission` or `stringMatch`.
- `permission`: If type is `permission`, this is the permission to check for.
- `value`: If type is `permission`, whether the player should have the permission. `true` (default) requires the player to have the permission, `false` requires the player to NOT have it.
- `input`: If type is `stringMatch`, this is the string being matched against `output`.
- `output`: If type is `stringMatch`, this is the string being matched against `input`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,19 @@ private String replaceArgs(String text, String[] args) {
return result;
}

private boolean checkPerm(Player player, String perm) {
if (perm == null) {
private boolean checkPerm(Player player, String perm, String valueStr) {
if (perm == null || perm.isEmpty()) {
return true;
}
if (!perm.equals("") && !player.hasPermission(perm)) {
return false;
}
return true;
boolean expectedValue = valueStr == null || Boolean.parseBoolean(valueStr);
return player.hasPermission(perm) == expectedValue;
}

private boolean checkRequirements(Player player, Map<String, String> requirements) {
if (requirements == null) { return true; }
if (requirements.get("type") == null) { return true; }
if (requirements.get("type").equals("permission")) {
return checkPerm(player, requirements.get("permission"));
return checkPerm(player, requirements.get("permission"), requirements.get("value"));
}
if (requirements.get("type").equals("stringMatch")) {
if (requirements.get("input") == null || requirements.get("output") == null) { return true; }
Expand Down