mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-02-26 09:11:30 +01:00
Move @Requirements to API, move command.command to commands
This commit is contained in:
parent
0fb3757c8d
commit
43c02b72a1
@ -26,15 +26,14 @@ import net.citizensnpcs.api.trait.Trait;
|
||||
import net.citizensnpcs.api.trait.TraitFactory;
|
||||
import net.citizensnpcs.api.util.Messaging;
|
||||
import net.citizensnpcs.api.util.Translator;
|
||||
import net.citizensnpcs.command.command.AdminCommands;
|
||||
import net.citizensnpcs.command.command.EditorCommands;
|
||||
import net.citizensnpcs.command.command.HelpCommands;
|
||||
import net.citizensnpcs.command.command.NPCCommands;
|
||||
import net.citizensnpcs.command.command.RequirementsProcessor;
|
||||
import net.citizensnpcs.command.command.ScriptCommands;
|
||||
import net.citizensnpcs.command.command.TemplateCommands;
|
||||
import net.citizensnpcs.command.command.TraitCommands;
|
||||
import net.citizensnpcs.command.command.WaypointCommands;
|
||||
import net.citizensnpcs.commands.AdminCommands;
|
||||
import net.citizensnpcs.commands.EditorCommands;
|
||||
import net.citizensnpcs.commands.HelpCommands;
|
||||
import net.citizensnpcs.commands.NPCCommands;
|
||||
import net.citizensnpcs.commands.ScriptCommands;
|
||||
import net.citizensnpcs.commands.TemplateCommands;
|
||||
import net.citizensnpcs.commands.TraitCommands;
|
||||
import net.citizensnpcs.commands.WaypointCommands;
|
||||
import net.citizensnpcs.editor.Editor;
|
||||
import net.citizensnpcs.npc.CitizensNPCRegistry;
|
||||
import net.citizensnpcs.npc.CitizensTraitFactory;
|
||||
@ -242,8 +241,6 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
|
||||
|
||||
private void registerCommands() {
|
||||
commands.setInjector(new Injector(this));
|
||||
commands.registerAnnotationProcessor(new RequirementsProcessor());
|
||||
|
||||
// Register command classes
|
||||
commands.register(AdminCommands.class);
|
||||
commands.register(EditorCommands.class);
|
||||
|
@ -163,6 +163,11 @@ public class EventListen implements Listener {
|
||||
Bukkit.getPluginManager().callEvent(new EntityTargetNPCEvent(event, npc));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onNeedsRespawn(NPCNeedsRespawnEvent event) {
|
||||
toRespawn.put(toCoord(event.getSpawnLocation()), event.getNPC().getId());
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {
|
||||
if (!(event.getPlayer() instanceof NPCHolder))
|
||||
@ -329,9 +334,4 @@ public class EventListen implements Listener {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onNeedsRespawn(NPCNeedsRespawnEvent event) {
|
||||
toRespawn.put(toCoord(event.getSpawnLocation()), event.getNPC().getId());
|
||||
}
|
||||
}
|
@ -14,15 +14,15 @@ public class NPCNeedsRespawnEvent extends NPCEvent {
|
||||
this.spawn = at;
|
||||
}
|
||||
|
||||
public Location getSpawnLocation() {
|
||||
return spawn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public Location getSpawnLocation() {
|
||||
return spawn;
|
||||
}
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
|
@ -1,21 +0,0 @@
|
||||
package net.citizensnpcs.command.command;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import net.citizensnpcs.api.trait.Trait;
|
||||
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Requirements {
|
||||
EntityType[] excludedTypes() default { EntityType.UNKNOWN };
|
||||
|
||||
boolean ownership() default false;
|
||||
|
||||
boolean selected() default false;
|
||||
|
||||
Class<? extends Trait>[] traits() default {};
|
||||
|
||||
EntityType[] types() default { EntityType.UNKNOWN };
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
package net.citizensnpcs.command.command;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.command.CommandAnnotationProcessor;
|
||||
import net.citizensnpcs.api.command.CommandContext;
|
||||
import net.citizensnpcs.api.command.exception.CommandException;
|
||||
import net.citizensnpcs.api.command.exception.RequirementMissingException;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.trait.Trait;
|
||||
import net.citizensnpcs.api.trait.trait.MobType;
|
||||
import net.citizensnpcs.api.trait.trait.Owner;
|
||||
import net.citizensnpcs.api.util.Messaging;
|
||||
import net.citizensnpcs.util.Messages;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
public class RequirementsProcessor implements CommandAnnotationProcessor {
|
||||
@Override
|
||||
public Class<? extends Annotation> getAnnotationClass() {
|
||||
return Requirements.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(CommandSender sender, CommandContext context, Annotation instance, Object[] methodArgs)
|
||||
throws CommandException {
|
||||
Requirements requirements = (Requirements) instance;
|
||||
NPC npc = (methodArgs.length >= 3 && methodArgs[2] instanceof NPC) ? (NPC) methodArgs[2] : null;
|
||||
|
||||
// Requirements
|
||||
if (requirements.selected()) {
|
||||
boolean canRedefineSelected = context.hasValueFlag("id") && sender.hasPermission("npc.select");
|
||||
String error = Messaging.tr(Messages.COMMAND_MUST_HAVE_SELECTED);
|
||||
if (canRedefineSelected) {
|
||||
npc = CitizensAPI.getNPCRegistry().getById(context.getFlagInteger("id"));
|
||||
if (npc == null)
|
||||
error += ' ' + Messaging.tr(Messages.COMMAND_ID_NOT_FOUND, context.getFlagInteger("id"));
|
||||
}
|
||||
if (npc == null)
|
||||
throw new RequirementMissingException(error);
|
||||
}
|
||||
|
||||
if (requirements.ownership() && npc != null && !sender.hasPermission("citizens.admin")
|
||||
&& !npc.getTrait(Owner.class).isOwnedBy(sender))
|
||||
throw new RequirementMissingException(Messaging.tr(Messages.COMMAND_MUST_BE_OWNER));
|
||||
|
||||
if (npc == null)
|
||||
return;
|
||||
for (Class<? extends Trait> clazz : requirements.traits()) {
|
||||
if (!npc.hasTrait(clazz))
|
||||
throw new RequirementMissingException(Messaging.tr(Messages.COMMAND_MISSING_TRAIT,
|
||||
clazz.getSimpleName()));
|
||||
}
|
||||
|
||||
Set<EntityType> types = Sets.newEnumSet(Arrays.asList(requirements.types()), EntityType.class);
|
||||
if (types.contains(EntityType.UNKNOWN))
|
||||
types = EnumSet.allOf(EntityType.class);
|
||||
types.removeAll(Sets.newHashSet(requirements.excludedTypes()));
|
||||
|
||||
EntityType type = npc.getTrait(MobType.class).getType();
|
||||
if (!types.contains(type)) {
|
||||
throw new RequirementMissingException(Messaging.tr(Messages.COMMAND_REQUIREMENTS_INVALID_MOB_TYPE,
|
||||
type.getName()));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +1,9 @@
|
||||
package net.citizensnpcs.command.command;
|
||||
package net.citizensnpcs.commands;
|
||||
|
||||
import net.citizensnpcs.Citizens;
|
||||
import net.citizensnpcs.api.command.Command;
|
||||
import net.citizensnpcs.api.command.CommandContext;
|
||||
import net.citizensnpcs.api.command.Requirements;
|
||||
import net.citizensnpcs.api.command.exception.CommandException;
|
||||
import net.citizensnpcs.api.exception.NPCLoadException;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
@ -20,7 +21,7 @@ public class AdminCommands {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Command(aliases = { "citizens" }, desc = "Show basic plugin information", max = 0, permission = "admin")
|
||||
@Command(aliases = { "citizens" }, desc = "Show basic plugin information", max = 0, permission = "citizens.admin")
|
||||
public void citizens(CommandContext args, CommandSender sender, NPC npc) {
|
||||
Messaging.send(sender,
|
||||
" " + StringHelper.wrapHeader("<e>Citizens v" + plugin.getDescription().getVersion()));
|
||||
@ -36,7 +37,7 @@ public class AdminCommands {
|
||||
modifiers = { "reload" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "admin")
|
||||
permission = "citizens.admin")
|
||||
public void reload(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
Messaging.sendTr(sender, Messages.CITIZENS_RELOADING);
|
||||
try {
|
||||
@ -57,7 +58,7 @@ public class AdminCommands {
|
||||
min = 1,
|
||||
max = 1,
|
||||
flags = "a",
|
||||
permission = "admin")
|
||||
permission = "citizens.admin")
|
||||
public void save(CommandContext args, CommandSender sender, NPC npc) {
|
||||
Messaging.sendTr(sender, Messages.CITIZENS_SAVING);
|
||||
plugin.storeNPCs(args);
|
@ -1,7 +1,8 @@
|
||||
package net.citizensnpcs.command.command;
|
||||
package net.citizensnpcs.commands;
|
||||
|
||||
import net.citizensnpcs.api.command.Command;
|
||||
import net.citizensnpcs.api.command.CommandContext;
|
||||
import net.citizensnpcs.api.command.Requirements;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.editor.Editor;
|
||||
import net.citizensnpcs.editor.EquipmentEditor;
|
||||
@ -21,7 +22,7 @@ public class EditorCommands {
|
||||
modifiers = { "equip" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.edit.equip")
|
||||
permission = "citizens.npc.edit.equip")
|
||||
@Requirements(selected = true, ownership = true, types = { EntityType.ENDERMAN, EntityType.PLAYER, EntityType.PIG,
|
||||
EntityType.SHEEP })
|
||||
public void equip(CommandContext args, Player player, NPC npc) {
|
||||
@ -35,7 +36,7 @@ public class EditorCommands {
|
||||
modifiers = { "path" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.edit.path")
|
||||
permission = "citizens.npc.edit.path")
|
||||
@Requirements(selected = true, ownership = true, excludedTypes = { EntityType.BLAZE, EntityType.ENDER_DRAGON,
|
||||
EntityType.GHAST, EntityType.BAT, EntityType.WITHER, EntityType.SQUID })
|
||||
public void path(CommandContext args, Player player, NPC npc) {
|
||||
@ -49,7 +50,7 @@ public class EditorCommands {
|
||||
modifiers = { "text" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.edit.text")
|
||||
permission = "citizens.npc.edit.text")
|
||||
public void text(CommandContext args, Player player, NPC npc) {
|
||||
Editor.enterOrLeave(player, npc.getTrait(Text.class).getEditor(player));
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package net.citizensnpcs.command.command;
|
||||
package net.citizensnpcs.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -8,6 +8,7 @@ import net.citizensnpcs.Citizens;
|
||||
import net.citizensnpcs.api.command.Command;
|
||||
import net.citizensnpcs.api.command.CommandContext;
|
||||
import net.citizensnpcs.api.command.CommandManager.CommandInfo;
|
||||
import net.citizensnpcs.api.command.Requirements;
|
||||
import net.citizensnpcs.api.command.exception.CommandException;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.util.Messaging;
|
||||
@ -35,7 +36,7 @@ public class HelpCommands {
|
||||
modifiers = { "help" },
|
||||
min = 1,
|
||||
max = 2,
|
||||
permission = "help")
|
||||
permission = "citizens.help")
|
||||
@Requirements
|
||||
public void citizensHelp(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
int page = 1;
|
||||
@ -71,7 +72,7 @@ public class HelpCommands {
|
||||
modifiers = { "help" },
|
||||
min = 1,
|
||||
max = 2,
|
||||
permission = "npc.help")
|
||||
permission = "citizens.npc.help")
|
||||
@Requirements
|
||||
public void npcHelp(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
int page = 1;
|
||||
@ -90,7 +91,7 @@ public class HelpCommands {
|
||||
modifiers = { "help" },
|
||||
min = 1,
|
||||
max = 2,
|
||||
permission = "script.help")
|
||||
permission = "citizens.script.help")
|
||||
@Requirements
|
||||
public void scriptHelp(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
int page = 1;
|
||||
@ -129,7 +130,7 @@ public class HelpCommands {
|
||||
modifiers = { "help" },
|
||||
min = 1,
|
||||
max = 2,
|
||||
permission = "templates.help")
|
||||
permission = "citizens.templates.help")
|
||||
@Requirements
|
||||
public void templatesHelp(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
int page = 1;
|
||||
@ -148,7 +149,7 @@ public class HelpCommands {
|
||||
modifiers = { "help" },
|
||||
min = 1,
|
||||
max = 2,
|
||||
permission = "waypoints.help")
|
||||
permission = "citizens.waypoints.help")
|
||||
@Requirements
|
||||
public void waypointsHelp(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
int page = 1;
|
@ -1,4 +1,4 @@
|
||||
package net.citizensnpcs.command.command;
|
||||
package net.citizensnpcs.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@ -11,6 +11,7 @@ import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.ai.speech.SpeechContext;
|
||||
import net.citizensnpcs.api.command.Command;
|
||||
import net.citizensnpcs.api.command.CommandContext;
|
||||
import net.citizensnpcs.api.command.Requirements;
|
||||
import net.citizensnpcs.api.command.exception.CommandException;
|
||||
import net.citizensnpcs.api.command.exception.NoPermissionsException;
|
||||
import net.citizensnpcs.api.command.exception.ServerCommandException;
|
||||
@ -89,7 +90,7 @@ public class NPCCommands {
|
||||
modifiers = { "age" },
|
||||
min = 1,
|
||||
max = 2,
|
||||
permission = "npc.age")
|
||||
permission = "citizens.npc.age")
|
||||
@Requirements(selected = true, ownership = true, types = { EntityType.CHICKEN, EntityType.COW, EntityType.OCELOT,
|
||||
EntityType.PIG, EntityType.SHEEP, EntityType.VILLAGER, EntityType.WOLF })
|
||||
public void age(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
@ -132,7 +133,7 @@ public class NPCCommands {
|
||||
modifiers = { "anchor" },
|
||||
min = 1,
|
||||
max = 3,
|
||||
permission = "npc.anchor")
|
||||
permission = "citizens.npc.anchor")
|
||||
@Requirements(selected = true, ownership = true, types = EntityType.PLAYER)
|
||||
public void anchor(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
Anchors trait = npc.getTrait(Anchors.class);
|
||||
@ -202,7 +203,7 @@ public class NPCCommands {
|
||||
modifiers = { "behaviour", "behavior", "ai" },
|
||||
flags = "r",
|
||||
min = 2,
|
||||
permission = "npc.behaviour")
|
||||
permission = "citizens.npc.behaviour")
|
||||
public void behaviour(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
Iterable<String> files = Splitter.on(',').split(args.getJoinedStrings(1, ','));
|
||||
if (args.hasFlag('r')) {
|
||||
@ -240,7 +241,7 @@ public class NPCCommands {
|
||||
modifiers = { "copy" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.copy")
|
||||
permission = "citizens.npc.copy")
|
||||
public void copy(CommandContext args, CommandSender sender, NPC npc) {
|
||||
EntityType type = npc.getTrait(MobType.class).getType();
|
||||
String name = args.getFlag("name", npc.getFullName());
|
||||
@ -271,7 +272,7 @@ public class NPCCommands {
|
||||
flags = "bu",
|
||||
modifiers = { "create" },
|
||||
min = 2,
|
||||
permission = "npc.create")
|
||||
permission = "citizens.npc.create")
|
||||
@Requirements
|
||||
public void create(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
String name = Colorizer.parseColors(args.getJoinedStrings(1));
|
||||
@ -423,7 +424,7 @@ public class NPCCommands {
|
||||
modifiers = { "despawn" },
|
||||
min = 1,
|
||||
max = 2,
|
||||
permission = "npc.despawn")
|
||||
permission = "citizens.npc.despawn")
|
||||
@Requirements
|
||||
public void despawn(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
if (npc == null || args.argsLength() == 2) {
|
||||
@ -446,7 +447,7 @@ public class NPCCommands {
|
||||
modifiers = { "gravity" },
|
||||
min = 1,
|
||||
max = 2,
|
||||
permission = "npc.gravity")
|
||||
permission = "citizens.npc.gravity")
|
||||
@Requirements(selected = true, ownership = true, types = { EntityType.PLAYER })
|
||||
public void gamemode(CommandContext args, CommandSender sender, NPC npc) {
|
||||
Player player = (Player) npc.getBukkitEntity();
|
||||
@ -480,7 +481,7 @@ public class NPCCommands {
|
||||
modifiers = { "gravity" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.gravity")
|
||||
permission = "citizens.npc.gravity")
|
||||
public void gravity(CommandContext args, CommandSender sender, NPC npc) {
|
||||
boolean enabled = npc.getTrait(Gravity.class).toggle();
|
||||
String key = enabled ? Messages.GRAVITY_ENABLED : Messages.GRAVITY_DISABLED;
|
||||
@ -494,7 +495,7 @@ public class NPCCommands {
|
||||
modifiers = { "id" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.id")
|
||||
permission = "citizens.npc.id")
|
||||
public void id(CommandContext args, CommandSender sender, NPC npc) {
|
||||
Messaging.send(sender, npc.getId());
|
||||
}
|
||||
@ -507,7 +508,7 @@ public class NPCCommands {
|
||||
modifiers = { "list" },
|
||||
min = 1,
|
||||
max = 2,
|
||||
permission = "npc.list")
|
||||
permission = "citizens.npc.list")
|
||||
@Requirements
|
||||
public void list(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
List<NPC> npcs = new ArrayList<NPC>();
|
||||
@ -563,7 +564,7 @@ public class NPCCommands {
|
||||
modifiers = { "lookclose", "look", "rotate" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.lookclose")
|
||||
permission = "citizens.npc.lookclose")
|
||||
public void lookClose(CommandContext args, CommandSender sender, NPC npc) {
|
||||
Messaging.sendTr(sender, npc.getTrait(LookClose.class).toggle() ? Messages.LOOKCLOSE_SET
|
||||
: Messages.LOOKCLOSE_STOPPED, npc.getName());
|
||||
@ -576,7 +577,7 @@ public class NPCCommands {
|
||||
modifiers = { "mount" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.controllable")
|
||||
permission = "citizens.npc.controllable")
|
||||
public void mount(CommandContext args, Player player, NPC npc) {
|
||||
boolean enabled = npc.hasTrait(Controllable.class) && npc.getTrait(Controllable.class).isEnabled();
|
||||
if (!enabled) {
|
||||
@ -594,7 +595,7 @@ public class NPCCommands {
|
||||
desc = "Teleports a NPC to a given location",
|
||||
modifiers = "moveto",
|
||||
min = 1,
|
||||
permission = "npc.moveto")
|
||||
permission = "citizens.npc.moveto")
|
||||
public void moveto(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
// Spawn the NPC if it isn't spawned to prevent NPEs
|
||||
if (!npc.isSpawned())
|
||||
@ -637,7 +638,7 @@ public class NPCCommands {
|
||||
Messaging.sendTr(sender, Messages.MOVETO_TELEPORTED, npc.getName(), to);
|
||||
}
|
||||
|
||||
@Command(aliases = { "npc" }, desc = "Show basic NPC information", max = 0, permission = "npc.info")
|
||||
@Command(aliases = { "npc" }, desc = "Show basic NPC information", max = 0, permission = "citizens.npc.info")
|
||||
public void npc(CommandContext args, CommandSender sender, NPC npc) {
|
||||
Messaging.send(sender, StringHelper.wrapHeader(npc.getName()));
|
||||
Messaging.send(sender, " <a>ID: <e>" + npc.getId());
|
||||
@ -664,7 +665,7 @@ public class NPCCommands {
|
||||
modifiers = { "owner" },
|
||||
min = 1,
|
||||
max = 2,
|
||||
permission = "npc.owner")
|
||||
permission = "citizens.npc.owner")
|
||||
public void owner(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
Owner ownerTrait = npc.getTrait(Owner.class);
|
||||
if (args.argsLength() == 1) {
|
||||
@ -680,7 +681,7 @@ public class NPCCommands {
|
||||
}
|
||||
|
||||
@Command(aliases = { "npc" }, usage = "pathrange [range]", desc = "Sets an NPC's pathfinding range", modifiers = {
|
||||
"pathrange", "pathfindingrange", "prange" }, min = 2, max = 2, permission = "npc.pathfindingrange")
|
||||
"pathrange", "pathfindingrange", "prange" }, min = 2, max = 2, permission = "citizens.npc.pathfindingrange")
|
||||
public void pathfindingRange(CommandContext args, CommandSender sender, NPC npc) {
|
||||
double range = Math.max(1, args.getDouble(1));
|
||||
npc.getNavigator().getDefaultParameters().range((float) range);
|
||||
@ -695,7 +696,7 @@ public class NPCCommands {
|
||||
min = 1,
|
||||
max = 1,
|
||||
flags = "ar",
|
||||
permission = "npc.playerlist")
|
||||
permission = "citizens.npc.playerlist")
|
||||
@Requirements(types = EntityType.PLAYER)
|
||||
public void playerlist(CommandContext args, CommandSender sender, NPC npc) {
|
||||
boolean remove = !npc.data().get("removefromplayerlist", Setting.REMOVE_PLAYERS_FROM_PLAYER_LIST.asBoolean());
|
||||
@ -718,7 +719,7 @@ public class NPCCommands {
|
||||
modifiers = { "pose" },
|
||||
min = 1,
|
||||
max = 2,
|
||||
permission = "npc.pose")
|
||||
permission = "citizens.npc.pose")
|
||||
@Requirements(selected = true, ownership = true, types = EntityType.PLAYER)
|
||||
public void pose(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
Poses trait = npc.getTrait(Poses.class);
|
||||
@ -768,7 +769,7 @@ public class NPCCommands {
|
||||
modifiers = { "power" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.power")
|
||||
permission = "citizens.npc.power")
|
||||
@Requirements(selected = true, ownership = true, types = { EntityType.CREEPER })
|
||||
public void power(CommandContext args, CommandSender sender, NPC npc) {
|
||||
Messaging
|
||||
@ -782,7 +783,7 @@ public class NPCCommands {
|
||||
modifiers = { "profession", "prof" },
|
||||
min = 2,
|
||||
max = 2,
|
||||
permission = "npc.profession")
|
||||
permission = "citizens.npc.profession")
|
||||
@Requirements(selected = true, ownership = true, types = { EntityType.VILLAGER })
|
||||
public void profession(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
String profession = args.getString(1);
|
||||
@ -833,7 +834,7 @@ public class NPCCommands {
|
||||
desc = "Rename a NPC",
|
||||
modifiers = { "rename" },
|
||||
min = 2,
|
||||
permission = "npc.rename")
|
||||
permission = "citizens.npc.rename")
|
||||
public void rename(CommandContext args, CommandSender sender, NPC npc) {
|
||||
String oldName = npc.getName();
|
||||
String newName = args.getJoinedStrings(1);
|
||||
@ -857,7 +858,7 @@ public class NPCCommands {
|
||||
modifiers = { "select", "sel" },
|
||||
min = 1,
|
||||
max = 2,
|
||||
permission = "npc.select")
|
||||
permission = "citizens.npc.select")
|
||||
@Requirements
|
||||
public void select(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
NPC toSelect = null;
|
||||
@ -910,7 +911,7 @@ public class NPCCommands {
|
||||
}
|
||||
|
||||
@Command(aliases = { "npc" }, usage = "skeletontype [type]", desc = "Sets the NPC's skeleton type", modifiers = {
|
||||
"skeletontype", "sktype" }, min = 2, max = 2, permission = "npc.skeletontype")
|
||||
"skeletontype", "sktype" }, min = 2, max = 2, permission = "citizens.npc.skeletontype")
|
||||
@Requirements(selected = true, ownership = true, types = EntityType.SKELETON)
|
||||
public void skeletonType(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
SkeletonType type = (type = SkeletonType.getType(args.getInteger(1))) == null ? SkeletonType.valueOf(args
|
||||
@ -928,7 +929,7 @@ public class NPCCommands {
|
||||
modifiers = { "size" },
|
||||
min = 1,
|
||||
max = 2,
|
||||
permission = "npc.size")
|
||||
permission = "citizens.npc.size")
|
||||
@Requirements(selected = true, ownership = true, types = { EntityType.MAGMA_CUBE, EntityType.SLIME })
|
||||
public void slimeSize(CommandContext args, CommandSender sender, NPC npc) {
|
||||
SlimeSize trait = npc.getTrait(SlimeSize.class);
|
||||
@ -948,7 +949,7 @@ public class NPCCommands {
|
||||
modifiers = { "spawn" },
|
||||
min = 2,
|
||||
max = 2,
|
||||
permission = "npc.spawn")
|
||||
permission = "citizens.npc.spawn")
|
||||
@Requirements(ownership = true)
|
||||
public void spawn(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
NPC respawn = npcRegistry.getById(args.getInteger(1));
|
||||
@ -976,7 +977,7 @@ public class NPCCommands {
|
||||
desc = "Uses the NPCs SpeechController to talk",
|
||||
modifiers = { "speak" },
|
||||
min = 2,
|
||||
permission = "npc.speak")
|
||||
permission = "citizens.npc.speak")
|
||||
public void speak(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
String type = npc.getTrait(Speech.class).getDefaultVocalChord();
|
||||
String message = Colorizer.parseColors(args.getJoinedStrings(1));
|
||||
@ -1016,7 +1017,7 @@ public class NPCCommands {
|
||||
modifiers = { "speed" },
|
||||
min = 2,
|
||||
max = 2,
|
||||
permission = "npc.speed")
|
||||
permission = "citizens.npc.speed")
|
||||
public void speed(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
float newSpeed = (float) Math.abs(args.getDouble(1));
|
||||
if (newSpeed >= Setting.MAX_SPEED.asDouble())
|
||||
@ -1033,7 +1034,7 @@ public class NPCCommands {
|
||||
modifiers = { "tp", "teleport" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.tp")
|
||||
permission = "citizens.npc.tp")
|
||||
public void tp(CommandContext args, Player player, NPC npc) {
|
||||
Location to = npc.getTrait(CurrentLocation.class).getLocation();
|
||||
player.teleport(to, TeleportCause.COMMAND);
|
||||
@ -1041,7 +1042,7 @@ public class NPCCommands {
|
||||
}
|
||||
|
||||
@Command(aliases = { "npc" }, usage = "tphere", desc = "Teleport a NPC to your location", modifiers = { "tphere",
|
||||
"tph", "move" }, min = 1, max = 1, permission = "npc.tphere")
|
||||
"tph", "move" }, min = 1, max = 1, permission = "citizens.npc.tphere")
|
||||
public void tphere(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
if (args.getSenderLocation() == null)
|
||||
throw new ServerCommandException();
|
||||
@ -1060,7 +1061,7 @@ public class NPCCommands {
|
||||
modifiers = { "type" },
|
||||
min = 2,
|
||||
max = 2,
|
||||
permission = "npc.type")
|
||||
permission = "citizens.npc.type")
|
||||
public void type(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
EntityType type = Util.matchEntityType(args.getString(1));
|
||||
if (type == null)
|
||||
@ -1077,7 +1078,7 @@ public class NPCCommands {
|
||||
min = 1,
|
||||
max = 1,
|
||||
flags = "t",
|
||||
permission = "npc.vulnerable")
|
||||
permission = "citizens.npc.vulnerable")
|
||||
public void vulnerable(CommandContext args, CommandSender sender, NPC npc) {
|
||||
boolean vulnerable = !npc.data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
|
||||
if (args.hasFlag('t')) {
|
||||
@ -1097,7 +1098,7 @@ public class NPCCommands {
|
||||
flags = "bv",
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "npc.zombiemodifier")
|
||||
permission = "citizens.npc.zombiemodifier")
|
||||
@Requirements(selected = true, ownership = true, types = EntityType.ZOMBIE)
|
||||
public void zombieModifier(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
ZombieModifier trait = npc.getTrait(ZombieModifier.class);
|
@ -1,4 +1,4 @@
|
||||
package net.citizensnpcs.command.command;
|
||||
package net.citizensnpcs.commands;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@ -29,7 +29,7 @@ public class ScriptCommands {
|
||||
desc = "compile and run a script",
|
||||
min = 2,
|
||||
max = 2,
|
||||
permission = "script.compile")
|
||||
permission = "citizens.script.compile")
|
||||
public void runScript(final CommandContext args, final CommandSender sender, NPC npc) throws CommandException {
|
||||
File file = new File(CitizensAPI.getScriptFolder(), args.getString(1));
|
||||
if (!file.exists())
|
@ -1,4 +1,4 @@
|
||||
package net.citizensnpcs.command.command;
|
||||
package net.citizensnpcs.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package net.citizensnpcs.command.command;
|
||||
package net.citizensnpcs.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -8,6 +8,7 @@ import net.citizensnpcs.Citizens;
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.command.Command;
|
||||
import net.citizensnpcs.api.command.CommandContext;
|
||||
import net.citizensnpcs.api.command.Requirements;
|
||||
import net.citizensnpcs.api.command.exception.CommandException;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.util.Messaging;
|
||||
@ -33,7 +34,7 @@ public class TemplateCommands {
|
||||
desc = "Applies a template to the selected NPC",
|
||||
modifiers = { "apply" },
|
||||
min = 2,
|
||||
permission = "templates.apply")
|
||||
permission = "citizens.templates.apply")
|
||||
@Requirements
|
||||
public void apply(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
Template template = Template.byName(args.getString(1));
|
||||
@ -76,7 +77,7 @@ public class TemplateCommands {
|
||||
min = 2,
|
||||
max = 2,
|
||||
flags = "o",
|
||||
permission = "templates.create")
|
||||
permission = "citizens.templates.create")
|
||||
public void create(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
String name = args.getString(1);
|
||||
if (Template.byName(name) != null)
|
@ -1,4 +1,4 @@
|
||||
package net.citizensnpcs.command.command;
|
||||
package net.citizensnpcs.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -6,6 +6,7 @@ import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.command.Command;
|
||||
import net.citizensnpcs.api.command.CommandConfigurable;
|
||||
import net.citizensnpcs.api.command.CommandContext;
|
||||
import net.citizensnpcs.api.command.Requirements;
|
||||
import net.citizensnpcs.api.command.exception.CommandException;
|
||||
import net.citizensnpcs.api.command.exception.NoPermissionsException;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
@ -22,7 +23,6 @@ import com.google.common.collect.Lists;
|
||||
|
||||
@Requirements(selected = true, ownership = true)
|
||||
public class TraitCommands {
|
||||
|
||||
@Command(aliases = { "trait", "tr" }, usage = "add [trait name]...", desc = "Adds traits to the NPC", modifiers = {
|
||||
"add", "a" }, min = 1, permission = "npc.trait")
|
||||
public void add(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
@ -1,8 +1,9 @@
|
||||
package net.citizensnpcs.command.command;
|
||||
package net.citizensnpcs.commands;
|
||||
|
||||
import net.citizensnpcs.Citizens;
|
||||
import net.citizensnpcs.api.command.Command;
|
||||
import net.citizensnpcs.api.command.CommandContext;
|
||||
import net.citizensnpcs.api.command.Requirements;
|
||||
import net.citizensnpcs.api.command.exception.CommandException;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.util.Messaging;
|
||||
@ -24,7 +25,7 @@ public class WaypointCommands {
|
||||
modifiers = { "disableteleport" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "waypoints.disableteleport")
|
||||
permission = "citizens.waypoints.disableteleport")
|
||||
public void disableTeleporting(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
npc.getNavigator().getDefaultParameters().stuckAction(null);
|
||||
Messaging.sendTr(sender, Messages.WAYPOINT_TELEPORTING_DISABLED);
|
||||
@ -38,7 +39,7 @@ public class WaypointCommands {
|
||||
min = 1,
|
||||
max = 2,
|
||||
flags = "a",
|
||||
permission = "waypoints.provider")
|
||||
permission = "citizens.waypoints.provider")
|
||||
public void provider(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||
Waypoints waypoints = npc.getTrait(Waypoints.class);
|
||||
if (args.argsLength() == 1) {
|
@ -30,15 +30,11 @@ public class Messages {
|
||||
public static final String CITIZENS_SAVING = "citizens.notifications.saving";
|
||||
public static final String COMMAND_AGE_HELP = "citizens.commands.npc.age.help";
|
||||
public static final String COMMAND_HELP_HEADER = "citizens.commands.help.header";
|
||||
public static final String COMMAND_ID_NOT_FOUND = "citizens.commands.id-not-found";
|
||||
public static final String COMMAND_INVALID_MOBTYPE = "citizens.commands.invalid-mobtype";
|
||||
public static final String COMMAND_INVALID_NUMBER = "citizens.commands.invalid-number";
|
||||
public static final String COMMAND_MISSING = "citizens.commands.help.command-missing";
|
||||
public static final String COMMAND_MISSING_TRAIT = "citizens.commands.requirements.missing-required-trait";
|
||||
public static final String COMMAND_MUST_BE_INGAME = "citizens.commands.requirements.must-be-ingame";
|
||||
public static final String COMMAND_MUST_BE_OWNER = "citizens.commands.requirements.must-be-owner";
|
||||
public static final String COMMAND_MUST_HAVE_SELECTED = "citizens.commands.requirements.must-have-selected";
|
||||
public static final String COMMAND_NO_PERMISSION = "citizens.commands.requirements.missing-permission";
|
||||
public static final String COMMAND_PAGE_MISSING = "citizens.commands.page-missing";
|
||||
public static final String COMMAND_REPORT_ERROR = "citizens.commands.console-error";
|
||||
public static final String COMMAND_REQUIREMENTS_INVALID_MOB_TYPE = "citizens.commands.requirements.disallowed-mobtype";
|
||||
|
@ -212,6 +212,11 @@ public class NMS {
|
||||
throw new IllegalArgumentException("unable to find valid entity superclass");
|
||||
}
|
||||
|
||||
public static void removeFromServerPlayerList(Player player) {
|
||||
EntityPlayer handle = ((CraftPlayer) player).getHandle();
|
||||
((CraftServer) Bukkit.getServer()).getHandle().players.remove(handle);
|
||||
}
|
||||
|
||||
public static void sendPacket(Player player, Packet packet) {
|
||||
((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
|
||||
}
|
||||
@ -381,9 +386,4 @@ public class NMS {
|
||||
STAIR_MATERIALS.add(material.getId());
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeFromServerPlayerList(Player player) {
|
||||
EntityPlayer handle = ((CraftPlayer) player).getHandle();
|
||||
((CraftServer) Bukkit.getServer()).getHandle().players.remove(handle);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user