NpcSpawner lib - spawn basic NPCs

Discussion in 'Resources' started by Redecouverte, Feb 3, 2011.

Thread Status:
Not open for further replies.
  1. Offline


    With the last Dev-Build, it is not working anymore, change this in the to get it work:
    public NPCManager(JavaPlugin plugin) {
            server = BServer.getInstance();
            npcNetworkManager = new NPCNetworkManager();
            NPCManager.plugin = plugin;
            taskid = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
                public void run() {
                    HashSet<String> toRemove = new HashSet<String>();
                    for (String i : npcs.keySet()) {
                        Entity j = npcs.get(i).getEntity();
                        if (j.dead) {
                    for (String n : toRemove) {
            }, 1L, 1L);
            Bukkit.getServer().getPluginManager().registerEvents(new SL(), plugin);
            Bukkit.getServer().getPluginManager().registerEvents(new WL(), plugin);
    The; in the old is not working anymore, so it must be replaced with j.aA();

    Top_Cat Maybe you could update it ;)
  2. I'm using this lib since about two days or so and most of the things do work and do work really well. There are still some things that I have a problem with:
    1) Setting the yaw does only rotate the body, not the head. Though changing the pitch does rotate it (up and down ofc.). See PR.
    2) (This might be spout related) I tried lots of things but nothing worked to set the skin. Neither getting the npc as a spout player nor setting it through a real player. Does somebody might have an idea?
  3. Offline


    Pretty sure only spout clients can see the skin changes. The skins for a player are retrieved by the client.
  4. I think I tested it with both, normal and spoutcraft, clients and neither worked. I'm gonna test the experimental builds for 1.2.5 from spout though.

    However, I have a new issue. NPC_BOUNCED does not get triggered at all. Maybe it isn't c() anymore?
  5. Offline

    Sir Savary

    How can I get an NPC to attack an entity?
  6. You were correct, but it took me some time figuring out which method you need to use to get the skin right. It's not working for me using the code of post #336 because I don't have a player all the time. So using this code should do it:
    SpoutPlayer sp = <HumanNPC>.getSpoutPlayer();
    Moreover I've a solution/workaround for the NPC_BOUNCED event, which is not working for me, because it doesn't get called. To make it working again you need to copy the code from the c() method in the a_() method and check if the (square)distance is 1 (you can adjust it to your liking). Basically you can use this:
    if ((lastBounceId != || System.currentTimeMillis() - lastBounceTick > 1000) && entity.getBukkitEntity().getLocation().distanceSquared(getBukkitEntity().getLocation()) <= 1) {
        EntityTargetEvent event = new NpcEntityTargetEvent(getBukkitEntity(), entity.getBukkitEntity(), NpcEntityTargetEvent.NpcTargetReason.NPC_BOUNCED);
        CraftServer server = ((WorldServer) world).getServer();
        lastBounceTick = System.currentTimeMillis();
        lastBounceId =;
    just put it somewhere in the a_() method.

    I don't think there's a method for that but maybe you want to make a scheduler that does the following:
    if target is in range
        animate arm swing
        damage target
        walk towards target
  7. Offline


    Has anyone has any luck with the lookAtPoint method?

    When I use it, it only looks at my location when I first spawn it (I'm calling it whenever I move near it), after that the NPC refuses to look anywhere else.

    I tried getting it to move but only changing the pitch and yaw, with a bit more success:

    As you can see, the body looks at me, but not the head. Anyone got any ideas?
  8. Neodork likes this.
  9. Offline


    How do I get to use the lookAtPoint Method?

    Manager. ?? . ??

    Edit: Found it sorry for being lazy :)

    1. HumanNPC npc = (HumanNPC)plugin.m.getHumanNPCByName(input[0]);
  10. Offline


    Where can I download this? I cant seem to find a link anywhere!
  11. TopCat has a repo for it, let me look for the git link.
  12. Offline


    I bet this sounds weird. Does anyone know how fast npcs walk? I'm trying to use the path functions to make npc walk around and need to set up timers.
  13. Offline


    NPCs don't like walking up blocks. The walk down them fine but walking up just makes them teleport.
  14. Offline


    Hey all, I am kinda lost here. I read through the other posts, and this is what I came up with for spawning an npc,

    1. package me.IronCrystal.NPCWorkers;
    3. import java.util.logging.Logger;
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.plugin.PluginDescriptionFile;
    9. import org.bukkit.plugin.PluginManager;
    10. import;
    12. import com.topcat.npclib.NPCManager;
    15. public class NPCWorkers extends JavaPlugin{
    17. public final Logger logger = Logger.getLogger("Minecraft");
    19. public static NPCWorkers plugin;
    21. NPCManager m = new NPCManager(plugin);
    23. @Override
    24. public void onDisable() {
    25. PluginDescriptionFile pdfFile = this.getDescription();
    26. + " is now disabled!");
    27. }
    29. @Override
    30. public void onEnable() {
    31. PluginDescriptionFile pdfFile = this.getDescription();
    32. + " version " + pdfFile.getVersion() + " has been enabled.");
    33. PluginManager pm = getServer().getPluginManager();
    34. }
    36. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
    37. {
    38. Player player = null;
    40. if (sender instanceof Player)
    41. {
    42. player = (Player) sender;
    43. }
    44. else
    45. {
    46. sender.sendMessage("You must be a player to use this command!");
    47. return true;
    48. }
    50. if (cmd.getName().equalsIgnoreCase("npc"))
    51. {
    52. m.spawnHumanNPC("name of npc", player.getLocation());
    53. }
    54. return false;
    55. }
    56. }

    But it comes up with this error upon onEnable

    1. 03:29:59 [SEVERE] Could not load 'plugins/NPCWorkers.jar' in folder 'plugins'
    2. org.bukkit.plugin.InvalidPluginException: java.lang.IllegalArgumentException: Plugin cannot be null
    3. at
    4. at org.bukkit.plugin.SimplePluginManager.loadPlugin(
    5. at org.bukkit.plugin.SimplePluginManager.loadPlugins(
    6. at org.bukkit.craftbukkit.CraftServer.loadPlugins(
    7. at org.bukkit.craftbukkit.CraftServer.<init>(
    8. at net.minecraft.server.ServerConfigurationManager.<init>(
    9. at net.minecraft.server.MinecraftServer.init(
    10. at
    11. at
    12. Caused by: java.lang.IllegalArgumentException: Plugin cannot be null
    13. at org.bukkit.craftbukkit.scheduler.CraftScheduler.scheduleSyncRepeatingTask(
    14. at com.topcat.npclib.NPCManager.<init>(
    15. at me.IronCrystal.NPCWorkers.NPCWorkers.<init>(
    16. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    17. at sun.reflect.NativeConstructorAccessorImpl.newInstance(
    18. at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(
    19. at java.lang.reflect.Constructor.newInstance(
    20. at
    21. ... 8 more

    What is going wrong?
  15. Offline


    You should change NPCManager initialization

    public class NPCWorkers extends JavaPlugin{
        public final Logger logger = Logger.getLogger("Minecraft");
        public static NPCWorkers plugin;   
        NPCManager m;
        public void onDisable() {
            PluginDescriptionFile pdfFile = this.getDescription();
   + " is now disabled!");
            plugin = this;
            m = new NPCManager(plugin);
    Iron_Crystal likes this.
  16. Offline


    Add this to your onEnable method and not onDisable like shown above..

    1. m = new NPCManager(this)

    +be sure to call it before you call any npc methods.
    Iron_Crystal likes this.
  17. Offline


  18. Offline


    Ups and ty
  19. Offline


    So if I understand this right, I have to check if the CraftPlayer players contains the NPC's name. and whenever getBukkitEntity() is called I'm supposed to remove it from the CraftPlayer player?

    Anyone cares to enlighten me ?
  20. Offline


    Neodork - the cache has been removed as of the latest version of bukkit.
    Neodork likes this.
  21. Offline


    Thanks for the information!

    Edit: This makes my day ^^.
  22. Wow this is awesome! Without this my plugin wouldn't be possible!
  23. Offline


    Thank you!!! I'm making a cop plugin and this will work out just fine :D
    Now I want to hide the name and this code doesn't even work when I paste it into Eclipse.
  24. Offline


    Whats wrong with Spout code?
  25. No other way than spout since it's actually a player which ALWAYS has a nameplate.
  26. Offline


    Sorry I'm just a little bit confused, I'll leave the name in, I just want it to work like Citizens, does Citizens use Spout? I didn't fully skim through the plugin. >.>
  27. Not necessarily. But to be able to use skins, without using the skin provided by a player with that name, you'll probably need spout since there's no other way.
  28. Offline


    For some reason I can't cast an NPC to a human npc. Am I suppose to not be able to?

    How did you do it?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 8, 2016
  29. Offline


    HumanNPC npc = (HumanNPC)plugin.m.getHumanNPCByName(input).get(0);
    The .get(0); should do the trick for you.
  30. Offline


    I can't get it work...
    I included the latest craftbukkit RB, Spout and i put the classes from this link into my project (, but i still get errors, when i paste the listeners from the first poste into my code. Eclipse tells me that it can't find "BasicHumanNpc" and "NpcSpawner". Could you give me a link where this classes are included?
Thread Status:
Not open for further replies.

Share This Page