mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-10-22 12:29:59 +02: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(
|
@Command(
|
||||||
aliases = { "npc" },
|
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 = "",
|
desc = "",
|
||||||
modifiers = { "command", "cmd" },
|
modifiers = { "command", "cmd" },
|
||||||
min = 1,
|
min = 1,
|
||||||
@ -672,10 +672,14 @@ public class NPCCommands {
|
|||||||
} else if (action.equalsIgnoreCase("permissions") || action.equalsIgnoreCase("perms")) {
|
} else if (action.equalsIgnoreCase("permissions") || action.equalsIgnoreCase("perms")) {
|
||||||
if (!sender.hasPermission("citizens.admin"))
|
if (!sender.hasPermission("citizens.admin"))
|
||||||
throw new NoPermissionsException();
|
throw new NoPermissionsException();
|
||||||
List<String> temporaryPermissions = Arrays.asList(args.getSlice(2));
|
List<String> temporaryPermissions = Arrays.asList(args.getString(2).split(","));
|
||||||
commands.setTemporaryPermissions(temporaryPermissions);
|
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,
|
Messaging.sendTr(sender, Messages.COMMAND_TEMPORARY_PERMISSIONS_SET,
|
||||||
Joiner.on(' ').join(temporaryPermissions));
|
Joiner.on(' ').join(temporaryPermissions), duration);
|
||||||
} else if (action.equalsIgnoreCase("cost")) {
|
} else if (action.equalsIgnoreCase("cost")) {
|
||||||
if (args.argsLength() == 2)
|
if (args.argsLength() == 2)
|
||||||
throw new CommandException(Messages.COMMAND_MISSING_COST);
|
throw new CommandException(Messages.COMMAND_MISSING_COST);
|
||||||
|
@ -84,6 +84,8 @@ public class CommandTrait extends Trait {
|
|||||||
private final Map<UUID, PlayerNPCCommand> playerTracking = Maps.newHashMap();
|
private final Map<UUID, PlayerNPCCommand> playerTracking = Maps.newHashMap();
|
||||||
@Persist
|
@Persist
|
||||||
private final List<String> temporaryPermissions = Lists.newArrayList();
|
private final List<String> temporaryPermissions = Lists.newArrayList();
|
||||||
|
@Persist
|
||||||
|
private int temporaryPermissionsDuration;
|
||||||
|
|
||||||
public CommandTrait() {
|
public CommandTrait() {
|
||||||
super("commandtrait");
|
super("commandtrait");
|
||||||
@ -363,7 +365,12 @@ public class CommandTrait extends Trait {
|
|||||||
attachment.setPermission(permission, true);
|
attachment.setPermission(permission, true);
|
||||||
}
|
}
|
||||||
command.run(npc, player);
|
command.run(npc, player);
|
||||||
|
if (temporaryPermissionsDuration <= 0) {
|
||||||
attachment.remove();
|
attachment.remove();
|
||||||
|
} else {
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(),
|
||||||
|
() -> attachment.remove());
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -481,8 +488,13 @@ public class CommandTrait extends Trait {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setTemporaryPermissions(List<String> permissions) {
|
public void setTemporaryPermissions(List<String> permissions) {
|
||||||
|
setTemporaryPermissions(permissions, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTemporaryPermissions(List<String> permissions, int duration) {
|
||||||
temporaryPermissions.clear();
|
temporaryPermissions.clear();
|
||||||
temporaryPermissions.addAll(permissions);
|
temporaryPermissions.addAll(permissions);
|
||||||
|
temporaryPermissionsDuration = duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum CommandTraitError {
|
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.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.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.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.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-set" : "Commands will now execute at random.",
|
||||||
"citizens.commands.npc.commands.random-unset" : "Commands will no longer execute at random.",
|
"citizens.commands.npc.commands.random-unset" : "Commands will no longer execute at random.",
|
||||||
|
Loading…
Reference in New Issue
Block a user