From 5d08502bbbd0c32c0b2d5aff7473346f2f52d19e Mon Sep 17 00:00:00 2001 From: Furq Date: Mon, 3 Aug 2026 20:02:25 +0500 Subject: [PATCH] Implement support for true/false permission requirements in FancyDialog --- docs/src/fancydialogs/tutorials/json-schema.md | 4 ++++ .../fancydialogs/dialog/DialogImpl.java | 12 +++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/src/fancydialogs/tutorials/json-schema.md b/docs/src/fancydialogs/tutorials/json-schema.md index f697b45ac..2c02e3fca 100644 --- a/docs/src/fancydialogs/tutorials/json-schema.md +++ b/docs/src/fancydialogs/tutorials/json-schema.md @@ -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`. @@ -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`. @@ -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`. @@ -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`. diff --git a/plugins/fancydialogs/src/main/java/com/fancyinnovations/fancydialogs/dialog/DialogImpl.java b/plugins/fancydialogs/src/main/java/com/fancyinnovations/fancydialogs/dialog/DialogImpl.java index 9595e43fc..b251cf61c 100644 --- a/plugins/fancydialogs/src/main/java/com/fancyinnovations/fancydialogs/dialog/DialogImpl.java +++ b/plugins/fancydialogs/src/main/java/com/fancyinnovations/fancydialogs/dialog/DialogImpl.java @@ -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 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; }