Add /npc command expcost

This commit is contained in:
fullwall 2021-11-01 20:56:54 +08:00
parent 57adea419a
commit 7c8b136e1d
5 changed files with 27 additions and 2 deletions

View File

@ -131,6 +131,8 @@ public class Settings {
NPC_COMMAND_MISSING_ITEM_MESSAGE("npc.commands.error-messages.missing-item", "Missing {1} {0}"),
NPC_COMMAND_NO_PERMISSION_MESSAGE("npc.commands.error-messages.no-permission",
"You don't have permission to do that."),
NPC_COMMAND_NOT_ENOUGH_EXPERIENCE_MESSAGE("npc.commands.error-messages.not-enough-experience",
"You need at least {0} experience."),
NPC_COMMAND_NOT_ENOUGH_MONEY_MESSAGE("npc.commands.error-messages.not-enough-money", "You need at least ${0}."),
NPC_COMMAND_ON_COOLDOWN_MESSAGE("npc.commands.error-messages.on-cooldown",
"Please wait for {minutes} minutes and {seconds_over} seconds."),

View File

@ -343,7 +343,7 @@ public class NPCCommands {
@Command(
aliases = { "npc" },
usage = "command|cmd (add [command] | remove [id] | permissions [permissions] | sequential | random | cost [cost]) (-l[eft]/-r[ight]) (-p[layer] -o[p]), --cooldown [seconds] --delay [ticks] --permissions [perms] --n [max # of uses]",
usage = "command|cmd (add [command] | remove [id] | permissions [permissions] | sequential | random | (exp|item)cost [cost]) (-l[eft]/-r[ight]) (-p[layer] -o[p]), --cooldown [seconds] --delay [ticks] --permissions [perms] --n [max # of uses]",
desc = "Controls commands which will be run when clicking on an NPC",
help = Messages.NPC_COMMAND_HELP,
modifiers = { "command", "cmd" },
@ -391,6 +391,9 @@ public class NPCCommands {
} else if (args.getString(1).equalsIgnoreCase("cost")) {
commands.setCost(args.getDouble(2));
Messaging.sendTr(sender, Messages.COMMAND_COST_SET, args.getDouble(2));
} else if (args.getString(1).equalsIgnoreCase("expcost")) {
commands.setExperienceCost((float) args.getDouble(2));
Messaging.sendTr(sender, Messages.COMMAND_EXPERIENCE_COST_SET, args.getDouble(2));
} else if (args.getString(1).equalsIgnoreCase("random")) {
commands.setExecutionMode(
commands.getExecutionMode() == ExecutionMode.RANDOM ? ExecutionMode.LINEAR : ExecutionMode.RANDOM);

View File

@ -64,6 +64,8 @@ public class CommandTrait extends Trait {
@Persist
private ExecutionMode executionMode = ExecutionMode.LINEAR;
@Persist
private float experienceCost = -1;
@Persist
private final Map<String, Long> globalCooldowns = Maps.newHashMap();
@Persist
private List<ItemStack> itemRequirements = Lists.newArrayList();
@ -97,6 +99,13 @@ public class CommandTrait extends Trait {
Messaging.severe("Unable to find Vault when checking command cost - is it installed?");
}
}
if (experienceCost > 0) {
if (player.getExp() < experienceCost) {
sendErrorMessage(player, CommandTraitMessages.MISSING_EXPERIENCE, null, experienceCost);
return false;
}
player.setExp(player.getExp() - experienceCost);
}
if (itemRequirements.size() > 0) {
List<ItemStack> req = Lists.newArrayList(itemRequirements);
Inventory tempInventory = Bukkit.createInventory(null, 54);
@ -271,6 +280,10 @@ public class CommandTrait extends Trait {
return executionMode;
}
public float getExperienceCost() {
return experienceCost;
}
private int getNewId() {
int i = 0;
while (commands.containsKey(String.valueOf(i))) {
@ -312,6 +325,10 @@ public class CommandTrait extends Trait {
this.executionMode = mode;
}
public void setExperienceCost(float experienceCost) {
this.experienceCost = experienceCost;
}
public void setTemporaryPermissions(List<String> permissions) {
temporaryPermissions.clear();
temporaryPermissions.addAll(permissions);
@ -319,6 +336,7 @@ public class CommandTrait extends Trait {
private enum CommandTraitMessages {
MAXIMUM_TIMES_USED(Setting.NPC_COMMAND_MAXIMUM_TIMES_USED_MESSAGE),
MISSING_EXPERIENCE(Setting.NPC_COMMAND_NOT_ENOUGH_EXPERIENCE_MESSAGE),
MISSING_ITEM(Setting.NPC_COMMAND_MISSING_ITEM_MESSAGE),
MISSING_MONEY(Setting.NPC_COMMAND_NOT_ENOUGH_MONEY_MESSAGE),
NO_PERMISSION(Setting.NPC_COMMAND_NO_PERMISSION_MESSAGE),

View File

@ -57,6 +57,7 @@ public class Messages {
public static final String COMMAND_ADDED = "citizens.commands.npc.command.command-added";
public static final String COMMAND_AGE_HELP = "citizens.commands.npc.age.help";
public static final String COMMAND_COST_SET = "citizens.commands.npc.command.cost-set";
public static final String COMMAND_EXPERIENCE_COST_SET = "citizens.commands.npc.command.experience-cost-set";
public static final String COMMAND_HELP_HEADER = "citizens.commands.help.header";
public static final String COMMAND_INVALID_MOBTYPE = "citizens.commands.invalid-mobtype";
public static final String COMMAND_LEFT_HAND_HEADER = "citizens.commands.npc.command.left-hand-header";

View File

@ -51,11 +51,12 @@ citizens.commands.npc.collidable.set=[[{0}]] will now collide with entities.
citizens.commands.npc.collidable.unset=[[{0}]] will no longer collide with entities.
citizens.commands.npc.command.none-added=No commands have been added.
citizens.commands.npc.command.cost-set=Set cost per click to [[{0}]].
citizens.commands.npc.command.experience-cost-set=Set experience cost per click to [[{0}]].
citizens.commands.npc.command.left-hand-header=Commands to run on [[left click]]:
citizens.commands.npc.command.right-hand-header=Commands to run on [[right click]]:
citizens.commands.npc.command.command-removed=Command [[{0}]] removed.
citizens.commands.npc.command.command-added=Command [[{0}]] added with id [[{1}]].
citizens.commands.npc.command.help=<br>Use the [[-l]] flag to make the command run on left click, [[-r]] on right click (default).<br>Set the per-player cooldown before the command can be used again using [[--cooldown]] (in [[seconds]]).<br>Set the server-wide cooldown in seconds using [[--gcooldown]].<br>[[--delay]] will wait the specified amount in [[ticks]] before executing the command.<br>[[--permissions]] will set the command to require specific permissions (separate multiple with commas).<br>[[--n]] will only let the player run the command that number of times.<br>Use [[-o]] to temporarily execute the command as an op and [[-p]] to run the command as the clicking player instead of the server.<br>To give the player temporary permissions instead of op, use [[/npc command permissions]].<br>Set the cost of each click with [[/npc command cost]].<br>Commands can be executed one by one instead of all at once by using [[/npc command sequential]].
citizens.commands.npc.command.help=<br>Use the [[-l]] flag to make the command run on left click, [[-r]] on right click (default).<br>Set the per-player cooldown before the command can be used again using [[--cooldown]] (in [[seconds]]).<br>Set the server-wide cooldown in seconds using [[--gcooldown]].<br>[[--delay]] will wait the specified amount in [[ticks]] before executing the command.<br>[[--permissions]] will set the command to require specific permissions (separate multiple with commas).<br>[[--n]] will only let the player run the command that number of times.<br>Use [[-o]] to temporarily execute the command as an op and [[-p]] to run the command as the clicking player instead of the server.<br>To give the player temporary permissions instead of op, use [[/npc command permissions]].<br>Set the cost of each click with [[/npc command cost/expcost/itemcost]].<br>Commands can be executed one by one instead of all at once by using [[/npc command sequential]].
citizens.commands.npc.command.unknown-id=Unknown command id [[{0}]] for this NPC.
citizens.commands.npc.command.temporary-permissions-set=Temporary permissions set to [[{0}]].
citizens.commands.npc.commands.sequential-set=Commands will now execute sequentially.