Skip to content

Commit

Permalink
Add some basic command permissions to ignore errors
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed May 14, 2023
1 parent 8df17d2 commit 3086908
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions main/src/main/java/net/citizensnpcs/trait/CommandTrait.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,21 @@ public int addCommand(NPCCommandBuilder builder) {

private Transaction chargeCommandCosts(Player player, Hand hand) {
NPCShopAction action = null;
if (cost > 0) {
if (player.hasPermission("citizens.npc.command.ignoreerrors.*"))
return Transaction.success();
if (cost > 0 && !player.hasPermission("citizens.npc.command.ignoreerrors.cost")) {
action = new MoneyAction(cost);
if (!action.take(player, 1).isPossible()) {
sendErrorMessage(player, CommandTraitError.MISSING_MONEY, null, cost);
}
}
if (experienceCost > 0) {
if (experienceCost > 0 && !player.hasPermission("citizens.npc.command.ignoreerrors.expcost")) {
action = new ExperienceAction(experienceCost);
if (!action.take(player, 1).isPossible()) {
sendErrorMessage(player, CommandTraitError.MISSING_EXPERIENCE, null, experienceCost);
}
}
if (itemRequirements.size() > 0) {
if (itemRequirements.size() > 0 && !player.hasPermission("citizens.npc.command.ignoreerrors.itemcost")) {
action = new ItemAction(itemRequirements);
if (!action.take(player, 1).isPossible()) {
ItemStack stack = itemRequirements.get(0);
Expand Down Expand Up @@ -666,7 +668,8 @@ public boolean canUse(CommandTrait trait, Player player, NPCCommand command) {
long globalDelay = Setting.NPC_COMMAND_GLOBAL_COMMAND_COOLDOWN.asSeconds();
long currentTimeSec = System.currentTimeMillis() / 1000;
String commandKey = command.getEncodedKey();
if (lastUsed.containsKey(commandKey)) {
if (!player.hasPermission("citizens.npc.command.ignoreerrors.cooldown")
&& lastUsed.containsKey(commandKey)) {
long deadline = ((Number) lastUsed.get(commandKey)).longValue()
+ (command.cooldown != 0 ? command.cooldown : globalDelay);
if (currentTimeSec < deadline) {
Expand All @@ -677,7 +680,8 @@ public boolean canUse(CommandTrait trait, Player player, NPCCommand command) {
}
lastUsed.remove(commandKey);
}
if (command.globalCooldown > 0 && trait.globalCooldowns.containsKey(commandKey)) {
if (!player.hasPermission("citizens.npc.command.ignoreerrors.globalcooldown") && command.globalCooldown > 0
&& trait.globalCooldowns.containsKey(commandKey)) {
long deadline = ((Number) trait.globalCooldowns.get(commandKey)).longValue() + command.globalCooldown;
if (currentTimeSec < deadline) {
long seconds = deadline - currentTimeSec;
Expand All @@ -688,7 +692,8 @@ public boolean canUse(CommandTrait trait, Player player, NPCCommand command) {
trait.globalCooldowns.remove(commandKey);
}
int timesUsed = nUsed.getOrDefault(commandKey, 0);
if (command.n > 0 && command.n <= timesUsed) {
if (!player.hasPermission("citizens.npc.command.ignoreerrors.nused") && command.n > 0
&& command.n <= timesUsed) {
trait.sendErrorMessage(player, CommandTraitError.MAXIMUM_TIMES_USED, null, command.n);
return false;
}
Expand Down

0 comments on commit 3086908

Please sign in to comment.