fancynpcs: Add permissions for adding action types

This commit is contained in:
Oliver
2025-09-14 10:49:48 +02:00
parent f5107067d1
commit 2dad4bc692
3 changed files with 44 additions and 5 deletions

View File

@@ -1 +1 @@
2.7.1.293
2.7.1.294

View File

@@ -34,6 +34,10 @@ public enum ActionCMD {
final @NotNull NpcAction actionType,
final @Nullable @Greedy String value
) {
if (!checkAddPermissions(sender, actionType)) {
return;
}
if (actionType.requiresValue() && (value == null || value.isEmpty())) {
translator
.translate("npc_action_requires_value")
@@ -65,6 +69,10 @@ public enum ActionCMD {
final @NotNull NpcAction actionType,
final @Nullable @Greedy String value
) {
if (!checkAddPermissions(sender, actionType)) {
return;
}
if (actionType.requiresValue() && (value == null || value.isEmpty())) {
translator
.translate("npc_action_requires_value")
@@ -98,6 +106,10 @@ public enum ActionCMD {
final @NotNull NpcAction actionType,
final @Nullable @Greedy String value
) {
if (!checkAddPermissions(sender, actionType)) {
return;
}
if (actionType.requiresValue() && (value == null || value.isEmpty())) {
translator
.translate("npc_action_requires_value")
@@ -131,6 +143,10 @@ public enum ActionCMD {
final @NotNull NpcAction actionType,
final @Nullable @Greedy String value
) {
if (!checkAddPermissions(sender, actionType)) {
return;
}
if (actionType.requiresValue() && (value == null || value.isEmpty())) {
translator
.translate("npc_action_requires_value")
@@ -303,6 +319,21 @@ public enum ActionCMD {
return newActions;
}
private boolean checkAddPermissions(final CommandSender sender, final NpcAction action) {
boolean hasGeneralPerms = sender.hasPermission("fancynpcs.command.npc.action.add.*");
boolean hasSpecificPerms = sender.hasPermission("fancynpcs.command.npc.action.add." + action.getName());
if (hasGeneralPerms || hasSpecificPerms) {
return true;
}
translator
.translate("action_missing_permissions")
.send(sender);
return false;
}
/* PARSERS AND SUGGESTIONS */