Another attempt to avoid charging costs inappropriately

This commit is contained in:
fullwall 2024-03-07 01:59:47 +08:00
parent 4bfededf7a
commit e757344d41
4 changed files with 13 additions and 7 deletions

View File

@ -271,6 +271,7 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
return shops;
}
@Override
public TemplateRegistry getTemplateRegistry() {
return templateRegistry;
}

View File

@ -472,8 +472,8 @@ public class NPCCommands {
permission = "citizens.npc.command")
public void command(CommandContext args, CommandSender sender, NPC npc,
@Flag(value = { "permissions", "permission" }) String permissions,
@Flag(value = "cost", defValue = "0") Double cost,
@Flag(value = "expcost", defValue = "0") Integer experienceCost,
@Flag(value = "cost", defValue = "-1") Double cost,
@Flag(value = "expcost", defValue = "-1") Integer experienceCost,
@Flag(value = "cooldown", defValue = "0") Duration cooldown,
@Flag(value = "gcooldown", defValue = "0") Duration gcooldown, @Flag(value = "n", defValue = "-1") int n,
@Flag(value = "delay", defValue = "0") Duration delay,

View File

@ -99,7 +99,7 @@ public class CommandTrait extends Trait {
NPCShopAction action = null;
if (player.hasPermission("citizens.npc.command.ignoreerrors.*"))
return Transaction.success();
if (cost != 0 && !player.hasPermission("citizens.npc.command.ignoreerrors.cost")) {
if (nonZeroOrNegativeOne(cost) && !player.hasPermission("citizens.npc.command.ignoreerrors.cost")) {
action = new MoneyAction(cost);
if (!action.take(player, null, 1).isPossible()) {
sendErrorMessage(player, CommandTraitError.MISSING_MONEY, null, cost);
@ -119,8 +119,7 @@ public class CommandTrait extends Trait {
stack.getAmount());
}
}
if (command.cost != -1 && command.cost != 0
&& !player.hasPermission("citizens.npc.command.ignoreerrors.cost")) {
if (nonZeroOrNegativeOne(command.cost) && !player.hasPermission("citizens.npc.command.ignoreerrors.cost")) {
action = new MoneyAction(command.cost);
if (!action.take(player, null, 1).isPossible()) {
sendErrorMessage(player, CommandTraitError.MISSING_MONEY, null, command.cost);
@ -388,6 +387,10 @@ public class CommandTrait extends Trait {
return hideErrorMessages;
}
private boolean nonZeroOrNegativeOne(double value) {
return Math.abs(value) > 0.0001 && Math.abs(-1 - value) > 0.0001;
}
public boolean persistSequence() {
return persistSequence;
}
@ -552,9 +555,9 @@ public class CommandTrait extends Trait {
private static class NPCCommand {
String command;
int cooldown;
double cost;
double cost = -1;
int delay;
int experienceCost;
int experienceCost = -1;
int globalCooldown;
Hand hand;
int id;

View File

@ -490,6 +490,8 @@
"citizens.commands.template.list.description" : "사용 가능한 템플릿 목록",
"citizens.commands.template.list.header" : "사용 가능한 템플릿입니다:",
"citizens.commands.template.missing" : "템플릿을 찾을 수 없습니다.",
"citizens.commands.template.namespace-already-exists" : "네임스페이스 [[{0}]]가 이미 존재합니다",
"citizens.commands.template.qualified-template-required" : "중복된 템플릿 이름 [[{0}]]. 다음 옵션 중에서 선택하세요: [[{1}]]",
"citizens.commands.trait.add.description" : "NPC에 특성을 추가합니다.",
"citizens.commands.trait.added" : "{0}이(가) 성공적으로 추가되었습니다.",
"citizens.commands.traitc.*.description" : "특성을 구성합니다.",