bug fixes

This commit is contained in:
aPunch 2012-01-28 14:16:30 -06:00
parent 55c1dc7be0
commit 6837ac11ea
10 changed files with 44 additions and 38 deletions

View File

@ -226,7 +226,7 @@ public class Citizens extends JavaPlugin {
} }
private void registerCommands() { private void registerCommands() {
cmdManager = new CommandManager(npcManager); cmdManager = new CommandManager();
cmdManager.setInjector(new Injector(npcManager, characterManager)); cmdManager.setInjector(new Injector(npcManager, characterManager));
// cmdManager.register(AdminCommands.class); // cmdManager.register(AdminCommands.class);

View File

@ -50,6 +50,8 @@ public class EventListen implements Listener {
return; return;
for (NPC npc : npcManager) { for (NPC npc : npcManager) {
if (!npc.isSpawned())
return;
Location loc = npc.getBukkitEntity().getLocation(); Location loc = npc.getBukkitEntity().getLocation();
if (event.getWorld().equals(loc.getWorld()) && event.getChunk().getX() == loc.getChunk().getX() if (event.getWorld().equals(loc.getWorld()) && event.getChunk().getX() == loc.getChunk().getX()
&& event.getChunk().getZ() == loc.getChunk().getZ()) { && event.getChunk().getZ() == loc.getChunk().getZ()) {
@ -86,6 +88,8 @@ public class EventListen implements Listener {
return; return;
NPC npc = npcManager.getNPC(event.getEntity()); NPC npc = npcManager.getNPC(event.getEntity());
if (npc == null)
return;
Player player = (Player) event.getTarget(); Player player = (Player) event.getTarget();
if (!npcManager.npcIsSelectedByPlayer(player, npc)) { if (!npcManager.npcIsSelectedByPlayer(player, npc)) {
if (npcManager.canSelectNPC(player, npc)) { if (npcManager.canSelectNPC(player, npc)) {

View File

@ -45,17 +45,14 @@ import net.citizensnpcs.command.exception.RequirementMissingException;
import net.citizensnpcs.command.exception.ServerCommandException; import net.citizensnpcs.command.exception.ServerCommandException;
import net.citizensnpcs.command.exception.UnhandledCommandException; import net.citizensnpcs.command.exception.UnhandledCommandException;
import net.citizensnpcs.command.exception.WrappedCommandException; import net.citizensnpcs.command.exception.WrappedCommandException;
import net.citizensnpcs.npc.CitizensNPCManager;
import net.citizensnpcs.util.Messaging; import net.citizensnpcs.util.Messaging;
import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class CommandManager { public class CommandManager {
// Logger for general errors. // Logger for general errors.
private static final Logger logger = Logger.getLogger(CommandManager.class.getCanonicalName()); private static final Logger logger = Logger.getLogger(CommandManager.class.getCanonicalName());
/* /*
* Mapping of commands (including aliases) with a description. Root commands * Mapping of commands (including aliases) with a description. Root commands
* are stored under a key of null, whereas child commands are cached under * are stored under a key of null, whereas child commands are cached under
@ -63,29 +60,18 @@ public class CommandManager {
* (one for each alias) with the method. * (one for each alias) with the method.
*/ */
private final Map<Method, Map<CommandIdentifier, Method>> commands = new HashMap<Method, Map<CommandIdentifier, Method>>(); private final Map<Method, Map<CommandIdentifier, Method>> commands = new HashMap<Method, Map<CommandIdentifier, Method>>();
// Used to store the instances associated with a method. // Used to store the instances associated with a method.
private final Map<Method, Object> instances = new HashMap<Method, Object>(); private final Map<Method, Object> instances = new HashMap<Method, Object>();
/* /*
* Mapping of commands (not including aliases) with a description. This is * Mapping of commands (not including aliases) with a description. This is
* only for top level commands. * only for top level commands.
*/ */
private final Map<CommandIdentifier, String> descs = new HashMap<CommandIdentifier, String>(); private final Map<CommandIdentifier, String> descs = new HashMap<CommandIdentifier, String>();
// Stores the injector used to getInstance. // Stores the injector used to getInstance.
private Injector injector; private Injector injector;
private final Map<Method, Requirements> requirements = new HashMap<Method, Requirements>(); private final Map<Method, Requirements> requirements = new HashMap<Method, Requirements>();
private final Map<Method, ServerCommand> serverCommands = new HashMap<Method, ServerCommand>(); private final Map<Method, ServerCommand> serverCommands = new HashMap<Method, ServerCommand>();
private final CitizensNPCManager npcManager;
public CommandManager(CitizensNPCManager npcManager) {
this.npcManager = npcManager;
}
/* /*
* Register an class that contains commands (denoted by Command. If no * Register an class that contains commands (denoted by Command. If no
* dependency injector is specified, then the methods of the class will be * dependency injector is specified, then the methods of the class will be
@ -324,17 +310,13 @@ public class CommandManager {
else if (methodArgs[1] instanceof Player) { else if (methodArgs[1] instanceof Player) {
Requirements cmdRequirements = requirements.get(method); Requirements cmdRequirements = requirements.get(method);
if (cmdRequirements != null) { if (cmdRequirements != null) {
if (methodArgs[2] instanceof NPC) { NPC npc = (NPC) methodArgs[2];
NPC npc = npcManager.getSelectedNPC(player);
if (npc != null)
methodArgs[2] = npc;
if (cmdRequirements.selected() && npc == null) if (cmdRequirements.selected() && npc == null)
throw new RequirementMissingException("You must have an NPC selected to execute that command."); throw new RequirementMissingException("You must have an NPC selected to execute that command.");
if (cmdRequirements.ownership() && !npc.getTrait(Owner.class).getOwner().equals(player.getName())) if (cmdRequirements.ownership() && npc != null
throw new RequirementMissingException( && !npc.getTrait(Owner.class).getOwner().equals(player.getName()))
"You must be the owner of this NPC to execute that command."); throw new RequirementMissingException("You must be the owner of this NPC to execute that command.");
}
} else } else
Messaging.debug("No annotation present."); Messaging.debug("No annotation present.");
} }

View File

@ -26,8 +26,13 @@ public class NPCCommands {
this.characterManager = characterManager; this.characterManager = characterManager;
} }
@Command(aliases = { "npc" }, usage = "create [name] (character)", desc = "Create a new NPC", @Command(
modifiers = { "create" }, min = 2, max = 3) aliases = { "npc" },
usage = "create [name] (character)",
desc = "Create a new NPC",
modifiers = { "create" },
min = 2,
max = 3)
@Permission("npc.create") @Permission("npc.create")
@Requirements @Requirements
public void createNPC(CommandContext args, Player player, NPC npc) { public void createNPC(CommandContext args, Player player, NPC npc) {
@ -48,10 +53,15 @@ public class NPCCommands {
Messaging.send(player, msg); Messaging.send(player, msg);
} }
@Command(aliases = { "npc" }, usage = "spawn [id]", desc = "Spawn an existing NPC", modifiers = { "spawn" }, @Command(
min = 2, max = 2) aliases = { "npc" },
usage = "spawn [id]",
desc = "Spawn an existing NPC",
modifiers = { "spawn" },
min = 2,
max = 2)
@Permission("npc.spawn") @Permission("npc.spawn")
@Requirements(ownership = true) @Requirements
public void spawnNPC(CommandContext args, Player player, NPC npc) { public void spawnNPC(CommandContext args, Player player, NPC npc) {
CitizensNPC respawn = (CitizensNPC) npcManager.getNPC(args.getInteger(1)); CitizensNPC respawn = (CitizensNPC) npcManager.getNPC(args.getInteger(1));
if (respawn == null) { if (respawn == null) {
@ -59,6 +69,11 @@ public class NPCCommands {
return; return;
} }
if (!respawn.getTrait(Owner.class).getOwner().equals(player.getName())) {
Messaging.sendError(player, "You must be the owner of this NPC to execute that command.");
return;
}
if (respawn.spawn(player.getLocation())) { if (respawn.spawn(player.getLocation())) {
npcManager.selectNPC(player, respawn); npcManager.selectNPC(player, respawn);
Messaging.send(player, ChatColor.GREEN + "You respawned " + StringHelper.wrap(respawn.getName()) Messaging.send(player, ChatColor.GREEN + "You respawned " + StringHelper.wrap(respawn.getName())
@ -68,8 +83,13 @@ public class NPCCommands {
+ " is already spawned at another location. Use '/npc tp' to teleport the NPC to your location."); + " is already spawned at another location. Use '/npc tp' to teleport the NPC to your location.");
} }
@Command(aliases = { "npc" }, usage = "despawn", desc = "Despawn an NPC", modifiers = { "despawn" }, min = 1, @Command(
max = 1) aliases = { "npc" },
usage = "despawn",
desc = "Despawn an NPC",
modifiers = { "despawn" },
min = 1,
max = 1)
@Permission("npc.despawn") @Permission("npc.despawn")
public void despawnNPC(CommandContext args, Player player, NPC npc) { public void despawnNPC(CommandContext args, Player player, NPC npc) {
npc.despawn(); npc.despawn();

View File

@ -7,7 +7,7 @@ import net.citizensnpcs.api.npc.AbstractNPC;
import net.citizensnpcs.api.npc.ai.Navigator; import net.citizensnpcs.api.npc.ai.Navigator;
import net.citizensnpcs.api.npc.trait.trait.SpawnLocation; import net.citizensnpcs.api.npc.trait.trait.SpawnLocation;
import net.citizensnpcs.npc.ai.CitizensNavigator; import net.citizensnpcs.npc.ai.CitizensNavigator;
import net.citizensnpcs.resources.lib.CraftNPC; import net.citizensnpcs.resource.lib.CraftNPC;
import net.citizensnpcs.util.Messaging; import net.citizensnpcs.util.Messaging;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;

View File

@ -14,7 +14,7 @@ import net.citizensnpcs.api.npc.NPCManager;
import net.citizensnpcs.api.npc.trait.Character; import net.citizensnpcs.api.npc.trait.Character;
import net.citizensnpcs.api.npc.trait.trait.Owner; import net.citizensnpcs.api.npc.trait.trait.Owner;
import net.citizensnpcs.api.npc.trait.trait.SpawnLocation; import net.citizensnpcs.api.npc.trait.trait.SpawnLocation;
import net.citizensnpcs.resources.lib.CraftNPC; import net.citizensnpcs.resource.lib.CraftNPC;
import net.citizensnpcs.storage.Storage; import net.citizensnpcs.storage.Storage;
import net.citizensnpcs.util.ByIdArray; import net.citizensnpcs.util.ByIdArray;
import net.minecraft.server.ItemInWorldManager; import net.minecraft.server.ItemInWorldManager;

View File

@ -1,4 +1,4 @@
package net.citizensnpcs.resources.lib; package net.citizensnpcs.resource.lib;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;

View File

@ -1,4 +1,4 @@
package net.citizensnpcs.resources.lib; package net.citizensnpcs.resource.lib;
import net.minecraft.server.EntityPlayer; import net.minecraft.server.EntityPlayer;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;

View File

@ -1,4 +1,4 @@
package net.citizensnpcs.resources.lib; package net.citizensnpcs.resource.lib;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.net.Socket; import java.net.Socket;

View File

@ -1,4 +1,4 @@
package net.citizensnpcs.resources.lib; package net.citizensnpcs.resource.lib;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;