mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-21 18:15:51 +01:00
Add duration argument to /npc command permission
This commit is contained in:
parent
46f3c31832
commit
bf845289c2
@ -547,7 +547,7 @@ public class NPCCommands {
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "command (add [command] | remove [id|all] | permissions [permissions] | sequential | cycle | random | forgetplayer (uuid) | clearerror [type] (name|uuid) | errormsg [type] [msg] | persistsequence [true|false] | cost [cost] (id) | expcost [cost] (id) | itemcost (id)) (-s(hift)) (-l[eft]/-r[ight]) (-p[layer] -o[p]), --cooldown --gcooldown [seconds] --delay [ticks] --permissions [perms] --n [max # of uses]",
|
||||
usage = "command (add [command] | remove [id|all] | permissions [permissions] (duration) | sequential | cycle | random | forgetplayer (uuid) | clearerror [type] (name|uuid) | errormsg [type] [msg] | persistsequence [true|false] | cost [cost] (id) | expcost [cost] (id) | itemcost (id)) (-s(hift)) (-l[eft]/-r[ight]) (-p[layer] -o[p]), --cooldown --gcooldown [seconds] --delay [ticks] --permissions [perms] --n [max # of uses]",
|
||||
desc = "",
|
||||
modifiers = { "command", "cmd" },
|
||||
min = 1,
|
||||
@ -672,10 +672,14 @@ public class NPCCommands {
|
||||
} else if (action.equalsIgnoreCase("permissions") || action.equalsIgnoreCase("perms")) {
|
||||
if (!sender.hasPermission("citizens.admin"))
|
||||
throw new NoPermissionsException();
|
||||
List<String> temporaryPermissions = Arrays.asList(args.getSlice(2));
|
||||
commands.setTemporaryPermissions(temporaryPermissions);
|
||||
List<String> temporaryPermissions = Arrays.asList(args.getString(2).split(","));
|
||||
int duration = -1;
|
||||
if (args.argsLength() == 4) {
|
||||
duration = Util.parseTicks(args.getString(3));
|
||||
}
|
||||
commands.setTemporaryPermissions(temporaryPermissions, duration);
|
||||
Messaging.sendTr(sender, Messages.COMMAND_TEMPORARY_PERMISSIONS_SET,
|
||||
Joiner.on(' ').join(temporaryPermissions));
|
||||
Joiner.on(' ').join(temporaryPermissions), duration);
|
||||
} else if (action.equalsIgnoreCase("cost")) {
|
||||
if (args.argsLength() == 2)
|
||||
throw new CommandException(Messages.COMMAND_MISSING_COST);
|
||||
|
@ -84,6 +84,8 @@ public class CommandTrait extends Trait {
|
||||
private final Map<UUID, PlayerNPCCommand> playerTracking = Maps.newHashMap();
|
||||
@Persist
|
||||
private final List<String> temporaryPermissions = Lists.newArrayList();
|
||||
@Persist
|
||||
private int temporaryPermissionsDuration;
|
||||
|
||||
public CommandTrait() {
|
||||
super("commandtrait");
|
||||
@ -363,7 +365,12 @@ public class CommandTrait extends Trait {
|
||||
attachment.setPermission(permission, true);
|
||||
}
|
||||
command.run(npc, player);
|
||||
attachment.remove();
|
||||
if (temporaryPermissionsDuration <= 0) {
|
||||
attachment.remove();
|
||||
} else {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
||||
() -> attachment.remove());
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -481,8 +488,13 @@ public class CommandTrait extends Trait {
|
||||
}
|
||||
|
||||
public void setTemporaryPermissions(List<String> permissions) {
|
||||
setTemporaryPermissions(permissions, -1);
|
||||
}
|
||||
|
||||
public void setTemporaryPermissions(List<String> permissions, int duration) {
|
||||
temporaryPermissions.clear();
|
||||
temporaryPermissions.addAll(permissions);
|
||||
temporaryPermissionsDuration = duration;
|
||||
}
|
||||
|
||||
public enum CommandTraitError {
|
||||
|
@ -134,7 +134,7 @@
|
||||
"citizens.commands.npc.command.persist-sequence-unset" : "Command sequences will no longer be saved across server restarts.",
|
||||
"citizens.commands.npc.command.player-forgotten" : "Forgot player command history for [[{0}]].",
|
||||
"citizens.commands.npc.command.right-hand-header" : "Commands to run on [[right click]]:",
|
||||
"citizens.commands.npc.command.temporary-permissions-set" : "Temporary permissions set to [[{0}]].",
|
||||
"citizens.commands.npc.command.temporary-permissions-set" : "Temporary permissions set to [[{0}]] for [[{1}]] ticks.",
|
||||
"citizens.commands.npc.command.unknown-id" : "Unknown command id [[{0}]] for this NPC.",
|
||||
"citizens.commands.npc.commands.random-set" : "Commands will now execute at random.",
|
||||
"citizens.commands.npc.commands.random-unset" : "Commands will no longer execute at random.",
|
||||
|
Loading…
Reference in New Issue
Block a user