mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-05 02:10:10 +01:00
bug fixes
This commit is contained in:
parent
956ac3a28d
commit
d689e71f96
@ -226,7 +226,7 @@ public class Citizens extends JavaPlugin {
|
||||
}
|
||||
|
||||
private void registerCommands() {
|
||||
cmdManager = new CommandManager(npcManager);
|
||||
cmdManager = new CommandManager();
|
||||
cmdManager.setInjector(new Injector(npcManager, characterManager));
|
||||
|
||||
// cmdManager.register(AdminCommands.class);
|
||||
|
@ -50,6 +50,8 @@ public class EventListen implements Listener {
|
||||
return;
|
||||
|
||||
for (NPC npc : npcManager) {
|
||||
if (!npc.isSpawned())
|
||||
return;
|
||||
Location loc = npc.getBukkitEntity().getLocation();
|
||||
if (event.getWorld().equals(loc.getWorld()) && event.getChunk().getX() == loc.getChunk().getX()
|
||||
&& event.getChunk().getZ() == loc.getChunk().getZ()) {
|
||||
@ -86,6 +88,8 @@ public class EventListen implements Listener {
|
||||
return;
|
||||
|
||||
NPC npc = npcManager.getNPC(event.getEntity());
|
||||
if (npc == null)
|
||||
return;
|
||||
Player player = (Player) event.getTarget();
|
||||
if (!npcManager.npcIsSelectedByPlayer(player, npc)) {
|
||||
if (npcManager.canSelectNPC(player, npc)) {
|
||||
|
@ -45,17 +45,14 @@ import net.citizensnpcs.command.exception.RequirementMissingException;
|
||||
import net.citizensnpcs.command.exception.ServerCommandException;
|
||||
import net.citizensnpcs.command.exception.UnhandledCommandException;
|
||||
import net.citizensnpcs.command.exception.WrappedCommandException;
|
||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class CommandManager {
|
||||
|
||||
// Logger for general errors.
|
||||
private static final Logger logger = Logger.getLogger(CommandManager.class.getCanonicalName());
|
||||
|
||||
/*
|
||||
* Mapping of commands (including aliases) with a description. Root commands
|
||||
* 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.
|
||||
*/
|
||||
private final Map<Method, Map<CommandIdentifier, Method>> commands = new HashMap<Method, Map<CommandIdentifier, Method>>();
|
||||
|
||||
// Used to store the instances associated with a method.
|
||||
private final Map<Method, Object> instances = new HashMap<Method, Object>();
|
||||
|
||||
/*
|
||||
* Mapping of commands (not including aliases) with a description. This is
|
||||
* only for top level commands.
|
||||
*/
|
||||
private final Map<CommandIdentifier, String> descs = new HashMap<CommandIdentifier, String>();
|
||||
|
||||
// Stores the injector used to getInstance.
|
||||
private Injector injector;
|
||||
|
||||
private final Map<Method, Requirements> requirements = new HashMap<Method, Requirements>();
|
||||
|
||||
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
|
||||
* 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) {
|
||||
Requirements cmdRequirements = requirements.get(method);
|
||||
if (cmdRequirements != null) {
|
||||
if (methodArgs[2] instanceof NPC) {
|
||||
NPC npc = npcManager.getSelectedNPC(player);
|
||||
if (npc != null)
|
||||
methodArgs[2] = npc;
|
||||
NPC npc = (NPC) methodArgs[2];
|
||||
|
||||
if (cmdRequirements.selected() && npc == null)
|
||||
throw new RequirementMissingException("You must have an NPC selected to execute that command.");
|
||||
if (cmdRequirements.ownership() && !npc.getTrait(Owner.class).getOwner().equals(player.getName()))
|
||||
throw new RequirementMissingException(
|
||||
"You must be the owner of this NPC to execute that command.");
|
||||
}
|
||||
if (cmdRequirements.selected() && npc == null)
|
||||
throw new RequirementMissingException("You must have an NPC selected to execute that command.");
|
||||
if (cmdRequirements.ownership() && npc != null
|
||||
&& !npc.getTrait(Owner.class).getOwner().equals(player.getName()))
|
||||
throw new RequirementMissingException("You must be the owner of this NPC to execute that command.");
|
||||
} else
|
||||
Messaging.debug("No annotation present.");
|
||||
}
|
||||
|
@ -26,8 +26,13 @@ public class NPCCommands {
|
||||
this.characterManager = characterManager;
|
||||
}
|
||||
|
||||
@Command(aliases = { "npc" }, usage = "create [name] (character)", desc = "Create a new NPC",
|
||||
modifiers = { "create" }, min = 2, max = 3)
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "create [name] (character)",
|
||||
desc = "Create a new NPC",
|
||||
modifiers = { "create" },
|
||||
min = 2,
|
||||
max = 3)
|
||||
@Permission("npc.create")
|
||||
@Requirements
|
||||
public void createNPC(CommandContext args, Player player, NPC npc) {
|
||||
@ -48,10 +53,15 @@ public class NPCCommands {
|
||||
Messaging.send(player, msg);
|
||||
}
|
||||
|
||||
@Command(aliases = { "npc" }, usage = "spawn [id]", desc = "Spawn an existing NPC", modifiers = { "spawn" },
|
||||
min = 2, max = 2)
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "spawn [id]",
|
||||
desc = "Spawn an existing NPC",
|
||||
modifiers = { "spawn" },
|
||||
min = 2,
|
||||
max = 2)
|
||||
@Permission("npc.spawn")
|
||||
@Requirements(ownership = true)
|
||||
@Requirements
|
||||
public void spawnNPC(CommandContext args, Player player, NPC npc) {
|
||||
CitizensNPC respawn = (CitizensNPC) npcManager.getNPC(args.getInteger(1));
|
||||
if (respawn == null) {
|
||||
@ -59,6 +69,11 @@ public class NPCCommands {
|
||||
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())) {
|
||||
npcManager.selectNPC(player, respawn);
|
||||
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.");
|
||||
}
|
||||
|
||||
@Command(aliases = { "npc" }, usage = "despawn", desc = "Despawn an NPC", modifiers = { "despawn" }, min = 1,
|
||||
max = 1)
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "despawn",
|
||||
desc = "Despawn an NPC",
|
||||
modifiers = { "despawn" },
|
||||
min = 1,
|
||||
max = 1)
|
||||
@Permission("npc.despawn")
|
||||
public void despawnNPC(CommandContext args, Player player, NPC npc) {
|
||||
npc.despawn();
|
||||
|
@ -7,7 +7,7 @@ import net.citizensnpcs.api.npc.AbstractNPC;
|
||||
import net.citizensnpcs.api.npc.ai.Navigator;
|
||||
import net.citizensnpcs.api.npc.trait.trait.SpawnLocation;
|
||||
import net.citizensnpcs.npc.ai.CitizensNavigator;
|
||||
import net.citizensnpcs.resources.lib.CraftNPC;
|
||||
import net.citizensnpcs.resource.lib.CraftNPC;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -14,7 +14,7 @@ import net.citizensnpcs.api.npc.NPCManager;
|
||||
import net.citizensnpcs.api.npc.trait.Character;
|
||||
import net.citizensnpcs.api.npc.trait.trait.Owner;
|
||||
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.util.ByIdArray;
|
||||
import net.minecraft.server.ItemInWorldManager;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package net.citizensnpcs.resources.lib;
|
||||
package net.citizensnpcs.resource.lib;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
@ -1,4 +1,4 @@
|
||||
package net.citizensnpcs.resources.lib;
|
||||
package net.citizensnpcs.resource.lib;
|
||||
|
||||
import net.minecraft.server.EntityPlayer;
|
||||
import net.minecraft.server.MinecraftServer;
|
@ -1,4 +1,4 @@
|
||||
package net.citizensnpcs.resources.lib;
|
||||
package net.citizensnpcs.resource.lib;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.Socket;
|
@ -1,4 +1,4 @@
|
||||
package net.citizensnpcs.resources.lib;
|
||||
package net.citizensnpcs.resource.lib;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
Loading…
Reference in New Issue
Block a user