mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-02-27 09:42:37 +01:00
Fix gcooldown not working when used in isolation
This commit is contained in:
parent
2341ccfbf9
commit
97da84c192
@ -391,11 +391,16 @@ public class NPCCommands {
|
||||
if (args.hasValueFlag("permissions")) {
|
||||
perms.addAll(Arrays.asList(args.getFlag("permissions").split(",")));
|
||||
}
|
||||
int id = commands.addCommand(new NPCCommandBuilder(command, hand).addPerms(perms)
|
||||
.player(args.hasFlag('p') || args.hasFlag('o')).op(args.hasFlag('o'))
|
||||
.cooldown(args.getFlagInteger("cooldown", 0)).globalCooldown(args.getFlagInteger("gcooldown", 0))
|
||||
.n(args.getFlagInteger("n", -1)).delay(args.getFlagInteger("delay", 0)));
|
||||
Messaging.sendTr(sender, Messages.COMMAND_ADDED, command, id);
|
||||
try {
|
||||
int id = commands.addCommand(new NPCCommandBuilder(command, hand).addPerms(perms)
|
||||
.player(args.hasFlag('p') || args.hasFlag('o')).op(args.hasFlag('o'))
|
||||
.cooldown(args.getFlagInteger("cooldown", 0))
|
||||
.globalCooldown(args.getFlagInteger("gcooldown", 0)).n(args.getFlagInteger("n", -1))
|
||||
.delay(args.getFlagTicks("delay", 0)));
|
||||
Messaging.sendTr(sender, Messages.COMMAND_ADDED, command, id);
|
||||
} catch (NumberFormatException ex) {
|
||||
throw new CommandException(CommandMessages.INVALID_NUMBER);
|
||||
}
|
||||
} else if (args.getString(1).equalsIgnoreCase("sequential")) {
|
||||
commands.setExecutionMode(commands.getExecutionMode() == ExecutionMode.SEQUENTIAL ? ExecutionMode.LINEAR
|
||||
: ExecutionMode.SEQUENTIAL);
|
||||
@ -455,6 +460,7 @@ public class NPCCommands {
|
||||
if (!npc.hasTrait(Controllable.class)) {
|
||||
npc.addTrait(new Controllable(false));
|
||||
}
|
||||
|
||||
Controllable trait = npc.getOrAddTrait(Controllable.class);
|
||||
boolean enabled = trait.toggle();
|
||||
if (args.hasFlag('y')) {
|
||||
@ -462,6 +468,7 @@ public class NPCCommands {
|
||||
} else if (args.hasFlag('n')) {
|
||||
enabled = trait.setEnabled(false);
|
||||
}
|
||||
|
||||
trait.setOwnerRequired(args.hasFlag('o'));
|
||||
String key = enabled ? Messages.CONTROLLABLE_SET : Messages.CONTROLLABLE_REMOVED;
|
||||
Messaging.sendTr(sender, key, npc.getName());
|
||||
@ -1187,7 +1194,7 @@ public class NPCCommands {
|
||||
toggle = false;
|
||||
}
|
||||
if (args.hasAnyValueFlag("randomlookdelay", "rlookdelay")) {
|
||||
int delay = Integer.parseInt(args.getFlag("randomlookdelay", args.getFlag("rlookdelay")));
|
||||
int delay = args.getFlagTicks("randomlookdelay", args.getFlagTicks("rlookdelay", 1));
|
||||
delay = Math.max(1, delay);
|
||||
trait.setRandomLookDelay(delay);
|
||||
Messaging.sendTr(sender, Messages.LOOKCLOSE_RANDOM_DELAY_SET, npc.getName(), delay);
|
||||
@ -1911,15 +1918,15 @@ public class NPCCommands {
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "respawn [delay in ticks]",
|
||||
desc = "Sets an NPC's respawn delay in ticks",
|
||||
usage = "respawn [delay]",
|
||||
desc = "Sets an NPC's respawn delay",
|
||||
modifiers = { "respawn" },
|
||||
min = 1,
|
||||
max = 2,
|
||||
permission = "citizens.npc.respawn")
|
||||
public void respawn(CommandContext args, CommandSender sender, NPC npc) {
|
||||
if (args.argsLength() > 1) {
|
||||
int delay = args.getInteger(1);
|
||||
int delay = args.getTicks(1);
|
||||
npc.data().setPersistent(NPC.RESPAWN_DELAY_METADATA, delay);
|
||||
Messaging.sendTr(sender, Messages.RESPAWN_DELAY_SET, delay);
|
||||
} else {
|
||||
|
@ -52,12 +52,11 @@ public class WaypointCommands {
|
||||
Messaging.sendTr(sender, Messages.WAYPOINT_ADDED, Util.prettyPrintLocation(loc), index);
|
||||
}
|
||||
|
||||
// TODO: refactor into a policy style system
|
||||
@Command(
|
||||
aliases = { "waypoints", "waypoint", "wp" },
|
||||
usage = "disableteleport",
|
||||
desc = "Disables teleportation when stuck (temporary command)",
|
||||
modifiers = { "disableteleport" },
|
||||
desc = "Disables teleportation when stuck",
|
||||
modifiers = { "disableteleport", "dt" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "citizens.waypoints.disableteleport")
|
||||
@ -90,7 +89,7 @@ public class WaypointCommands {
|
||||
aliases = { "waypoints", "waypoint", "wp" },
|
||||
usage = "opendoors",
|
||||
desc = "Enables opening doors when pathfinding",
|
||||
modifiers = { "opendoors" },
|
||||
modifiers = { "opendoors", "od" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "citizens.waypoints.opendoors")
|
||||
|
@ -300,6 +300,7 @@ public class CitizensNPC extends AbstractNPC {
|
||||
public void run() {
|
||||
if (timer++ > 10) {
|
||||
cancel();
|
||||
Messaging.debug("Couldn't spawn", CitizensNPC.this, "entity not added to world");
|
||||
return;
|
||||
}
|
||||
if (getEntity() == null || !getEntity().isValid())
|
||||
@ -314,7 +315,8 @@ public class CitizensNPC extends AbstractNPC {
|
||||
|
||||
if (spawnEvent.isCancelled()) {
|
||||
entityController.remove();
|
||||
Messaging.debug("Couldn't spawn", this, "SpawnReason." + reason, "due to event cancellation.");
|
||||
Messaging.debug("Couldn't spawn", CitizensNPC.this, "SpawnReason." + reason,
|
||||
"due to event cancellation.");
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
|
@ -65,12 +65,12 @@ public class CommandTrait extends Trait {
|
||||
private ExecutionMode executionMode = ExecutionMode.LINEAR;
|
||||
@Persist
|
||||
private float experienceCost = -1;
|
||||
@Persist
|
||||
@Persist(valueType = Long.class)
|
||||
private final Map<String, Long> globalCooldowns = Maps.newHashMap();
|
||||
@Persist
|
||||
private boolean hideErrorMessages;
|
||||
@Persist
|
||||
private List<ItemStack> itemRequirements = Lists.newArrayList();
|
||||
private final List<ItemStack> itemRequirements = Lists.newArrayList();
|
||||
@Persist
|
||||
private final List<String> temporaryPermissions = Lists.newArrayList();
|
||||
|
||||
@ -144,7 +144,7 @@ public class CommandTrait extends Trait {
|
||||
right.add(command);
|
||||
}
|
||||
}
|
||||
String output = Util.prettyEnum(executionMode) + " ";
|
||||
String output = executionMode + " ";
|
||||
if (cost > 0) {
|
||||
output += "Cost: " + StringHelper.wrap(cost);
|
||||
}
|
||||
@ -383,6 +383,11 @@ public class CommandTrait extends Trait {
|
||||
LINEAR,
|
||||
RANDOM,
|
||||
SEQUENTIAL;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name().charAt(1) + name().substring(1).toLowerCase();
|
||||
}
|
||||
}
|
||||
|
||||
public static enum Hand {
|
||||
@ -427,7 +432,8 @@ public class CommandTrait extends Trait {
|
||||
requirements.add(stack);
|
||||
}
|
||||
}
|
||||
this.trait.itemRequirements = requirements;
|
||||
this.trait.itemRequirements.clear();
|
||||
this.trait.itemRequirements.addAll(requirements);
|
||||
}
|
||||
}
|
||||
|
||||
@ -499,7 +505,7 @@ public class CommandTrait extends Trait {
|
||||
String command;
|
||||
int cooldown;
|
||||
int delay;
|
||||
private int globalCooldown;
|
||||
int globalCooldown;
|
||||
Hand hand;
|
||||
int n = -1;
|
||||
boolean op;
|
||||
@ -643,18 +649,19 @@ public class CommandTrait extends Trait {
|
||||
if (command.cooldown > 0) {
|
||||
lastUsed.put(commandKey, currentTimeSec);
|
||||
}
|
||||
if (command.n > 0) {
|
||||
nUsed.put(commandKey, previouslyUsed + 1);
|
||||
}
|
||||
if (command.globalCooldown > 0) {
|
||||
trait.globalCooldowns.put(commandKey, currentTimeSec);
|
||||
}
|
||||
if (command.n > 0) {
|
||||
nUsed.put(commandKey, previouslyUsed + 1);
|
||||
}
|
||||
lastUsedId = command.id;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean requiresTracking(NPCCommand command) {
|
||||
return command.cooldown > 0 || command.n > 0 || (command.perms != null && command.perms.size() > 0);
|
||||
return command.globalCooldown > 0 || command.cooldown > 0 || command.n > 0
|
||||
|| (command.perms != null && command.perms.size() > 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -202,7 +202,7 @@ citizens.commands.npc.remove.incorrect-syntax=Incorrect syntax. /npc remove (all
|
||||
citizens.commands.npc.remove.removed-all=You permanently removed all NPCs.
|
||||
citizens.commands.npc.remove.removed=You permanently removed [[{0}]].
|
||||
citizens.commands.npc.rename.renamed=You renamed [[{0}]] to [[{1}]].
|
||||
citizens.commands.npc.respawn.delay-set=Respawn delay set to [[{0}]].
|
||||
citizens.commands.npc.respawn.delay-set=Respawn delay set to [[{0}]] ticks.
|
||||
citizens.commands.npc.respawn.describe=Respawn delay is currently [[{0}]].
|
||||
citizens.commands.npc.select.already-selected=You already have that NPC selected.
|
||||
citizens.commands.npc.script.invalid-file=Unknown or unavailable script ''[[{0}]]''.
|
||||
|
Loading…
Reference in New Issue
Block a user