mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-26 20:55:44 +01:00
Add /npc command permissions for temporary permissions during the command
This commit is contained in:
parent
12ffd56981
commit
521c1d3fda
@ -288,7 +288,7 @@ public class NPCCommands {
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "command|cmd (add [command] | remove [id]) (-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]) (-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",
|
||||
modifiers = { "command", "cmd" },
|
||||
min = 1,
|
||||
@ -320,6 +320,11 @@ public class NPCCommands {
|
||||
throw new CommandException(Messages.COMMAND_UNKNOWN_COMMAND_ID, id);
|
||||
commands.removeCommandById(id);
|
||||
Messaging.sendTr(sender, Messages.COMMAND_REMOVED, id);
|
||||
} else if (args.getString(1).equalsIgnoreCase("permissions") || args.getString(1).equalsIgnoreCase("perms")) {
|
||||
List<String> temporaryPermissions = Arrays.asList(args.getSlice(2));
|
||||
commands.setTemporaryPermissions(temporaryPermissions);
|
||||
Messaging.sendTr(sender, Messages.COMMAND_TEMPORARY_PERMISSIONS_SET,
|
||||
Joiner.on(' ').join(temporaryPermissions));
|
||||
} else {
|
||||
throw new CommandUsageException();
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import java.util.Map;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Lists;
|
||||
@ -34,6 +35,8 @@ public class CommandTrait extends Trait {
|
||||
@Persist
|
||||
@DelegatePersistence(PlayerNPCCommandPersister.class)
|
||||
private final Map<String, PlayerNPCCommand> cooldowns = Maps.newHashMap();
|
||||
@Persist
|
||||
private final List<String> temporaryPermissions = Lists.newArrayList();
|
||||
|
||||
public CommandTrait() {
|
||||
super("commandtrait");
|
||||
@ -103,10 +106,17 @@ public class CommandTrait extends Trait {
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PermissionAttachment attachment = new PermissionAttachment(CitizensAPI.getPlugin(), player);
|
||||
if (temporaryPermissions.size() > 0) {
|
||||
for (String permission : temporaryPermissions) {
|
||||
attachment.setPermission(permission, true);
|
||||
}
|
||||
}
|
||||
command.run(npc, player);
|
||||
if (command.cooldown > 0 && info == null) {
|
||||
cooldowns.put(player.getUniqueId().toString(), new PlayerNPCCommand(command));
|
||||
}
|
||||
attachment.remove();
|
||||
}
|
||||
};
|
||||
if (command.delay <= 0) {
|
||||
@ -140,6 +150,11 @@ public class CommandTrait extends Trait {
|
||||
commands.remove(String.valueOf(id));
|
||||
}
|
||||
|
||||
public void setTemporaryPermissions(List<String> permissions) {
|
||||
temporaryPermissions.clear();
|
||||
temporaryPermissions.addAll(permissions);
|
||||
}
|
||||
|
||||
public static enum Hand {
|
||||
BOTH,
|
||||
LEFT,
|
||||
|
@ -62,6 +62,7 @@ public class Messages {
|
||||
public static final String COMMAND_REQUIREMENTS_INVALID_MOB_TYPE = "citizens.commands.requirements.disallowed-mobtype";
|
||||
public static final String COMMAND_RIGHT_HAND_HEADER = "citizens.commands.npc.command.right-hand-header";
|
||||
public static final String COMMAND_SAVE_HELP = "citizens.commands.citizens.save.help";
|
||||
public static final String COMMAND_TEMPORARY_PERMISSIONS_SET = "citizens.commands.npc.command.temporary-permissions-set";
|
||||
public static final String COMMAND_TOO_FEW_ARGUMENTS = "citizens.commands.requirements.too-few-arguments";
|
||||
public static final String COMMAND_TOO_MANY_ARGUMENTS = "citizens.commands.requirements.too-many-arguments";
|
||||
public static final String COMMAND_UNKNOWN_COMMAND_ID = "citizens.commands.npc.command.unknown-id";
|
||||
|
@ -47,6 +47,7 @@ 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.unknown-id=Unknown command id [[{0}]] for this NPC.
|
||||
citizens.commands.npc.command.temporary-permissions-set=Temporary permissions set to [[{0}]].
|
||||
citizens.commands.npc.controllable.not-controllable=[[{0}]] is not controllable.
|
||||
citizens.commands.npc.controllable.removed=[[{0}]] can no longer be controlled.
|
||||
citizens.commands.npc.controllable.set=[[{0}]] can now be controlled.
|
||||
|
Loading…
Reference in New Issue
Block a user