NpcSpawner lib - spawn basic NPCs

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

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

    kumpelblase2

    Because the code has been updated and the first post isn't up-to-date. Also, never just copy&paste.
     
  2. Offline

    Taces

    I just wanted to try, if it works and i tried about two hours to make it work.
    Do you have an up to date version?
     
  3. Offline

    kumpelblase2

    The code on github is up-to-date, just the example isn't. To get to know how to use it, you can just search through the last pages and the code itself which explains a lot.
     
  4. Offline

    PatrickWTB

    Nice work. ;-)

    Sorry, i really tried it,
    but i'm not able to find the Download-Link.

    Someone help plz...

    Greetz
    Patrick
     
  5. Offline

    Chipmunk9998

    Doesn't work for moveTo either... :l
     
  6. Offline

    fullwall

    Cue - Bukkit doesn't have an API for the new separation between head yaw and entity yaw. Citizens fixes this by modifying the EntityLiving.X field which controls head yaw along with the actual yaw.
     
  7. Offline

    Numenorean95

    Source code?
     
    Wundark likes this.
  8. Offline

    McLuke500

    It's on the first thread it's to use yourself
     
  9. Offline

    Numenorean95

    Yea, just saw, sorry
     
  10. Offline

    bubbleguj

    Where's the download? Can't find it :D
     
  11. Offline

    Kekec852

  12. Offline

    bubbleguj

    Works but:

    Code:
    15:56:03 [SCHWERWIEGEND] Could not load 'plugins\LeaveKill.jar' in folder 'plugi
    ns'
    org.bukkit.plugin.InvalidPluginException: java.lang.IllegalArgumentException: Pl
    ugin cannot be null
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:149)
            at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.
    java:305)
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager
    .java:230)
            at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:213)
            at org.bukkit.craftbukkit.CraftServer.reload(CraftServer.java:550)
            at org.bukkit.Bukkit.reload(Bukkit.java:182)
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:
    22)
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:16
    6)
            at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:4
    79)
            at org.bukkit.craftbukkit.CraftServer.dispatchServerCommand(CraftServer.
    java:475)
            at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:612)
            at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:581)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:459)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.IllegalArgumentException: Plugin cannot be null
            at org.bukkit.craftbukkit.scheduler.CraftScheduler.scheduleSyncRepeating
    Task(CraftScheduler.java:189)
            at com.topcat.npclib.NPCManager.<init>(NPCManager.java:52)
            at me.bubbleguj.leavekill.LeaveKill.<init>(LeaveKill.java:16)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
     
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
     
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
    rce)
            at java.lang.reflect.Constructor.newInstance(Unknown Source)
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:145)
            ... 13 more
    With this class:

    PHP:
    package me.bubbleguj.leavekill;
     
    import org.bukkit.Location;
    import org.bukkit.entity.HumanEntity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
     
    public class 
    LeaveKillPlayerListener implements Listener{
       
        public 
    LeaveKillPlayerListener(LeaveKill plugin){
            
    this.plugin plugin;
            
    plugin.getServer().getPluginManager().registerEvents(thisplugin);
        }
       
       
    //Quit Event
       
        
    @EventHandler
        
    public void onPlayerLeave(PlayerQuitEvent event){
           
        
    //General
            
    final Player p event.getPlayer();
            
    Location ploc p.getLocation();
            final 
    String name p.getName();
        
    //Npc Spawnen
            
    plugin.m.spawnHumanNPC(nameploc);
        
    //Npc  löschen
            
    plugin.getServer().getScheduler().scheduleAsyncDelayedTask(plugin, new Runnable(){
     
                @
    Override
                
    public void run() {
                    
    plugin.m.despawnHumanByName(name);
                }
            }, 
    600);
        }
       
    //Player Damage Event
       
        
    @EventHandler
        
    public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
     
        
    //Event
            
    if(event.getEntity() instanceof HumanEntity) {
            }
            else {
                return;
            }
        }
       
    //Join Event
       
        
    @EventHandler
        
    public void onPlayerJoin(PlayerJoinEvent event){
           
        
    //General
            
    final Player p event.getPlayer();
            
    String name p.getName();
     
        
    //Event
            
    if(plugin.m.getHumanNPCByName(name) != null) {
                
    p.getInventory().clear();
            }
            else {
                return;
            }
        }
        private 
    LeaveKill plugin;
    }
     
  13. Offline

    Kekec852

    Where in main plugin class do you init the NPCManager?

    You are doing it constructor right?
    Code:
            at com.topcat.npclib.NPCManager.<init>(NPCManager.java:52)
            at me.bubbleguj.leavekill.LeaveKill.<init>(LeaveKill.java:16)
    
    Try moving it to onEnable method.
     
  14. Offline

    bubbleguj

    This is my Main:
    PHP:
    package me.bubbleguj.leavekill;
     
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    import com.topcat.npclib.NPCManager;
     
    public class 
    LeaveKill extends JavaPlugin{
     
        private 
    PluginDescriptionFile pdf;
        public 
    LeaveKill plugin;
        
    NPCManager m = new NPCManager(plugin);
       
        @
    Override
        
    public void onEnable() {
            
    pdf getDescription();
            
    System.out.println("[LeaveKill] Plugin v" pdf.getVersion() + " activated!");
            
    System.out.println("[LeaveKill] Plugin by bubbleguj");
            
    registerEvent();
        }
     
        @
    Override
        
    public void onDisable() {
            
    System.out.println("[LeaveKill] Plugin disabled!");
        }
       
        private 
    void registerEvent() {
            new 
    LeaveKillPlayerListener(this);
        }
    }
     
  15. Offline

    Kekec852

    Object NPCManager can be created only inside onEnable function or it will fail to work.
     
  16. Offline

    r0306

    I'm trying to fire an arrow from the npc by getting the bukkit npc and they calling launch arrow. The first issue with this is that the arrow hits the npc entity hitbox, causing it to damage itself. When I spawn it outside the hitbox and set the arrow's velocity, it off in the wrong direction (most likely because the server's location is different from bukkit's location). Is there anyway to fix this?
     
  17. Offline

    devilquak


    I get this same error, from

    Code:
    Caused by: java.lang.IllegalArgumentException: Plugin cannot be null
            at org.bukkit.craftbukkit.scheduler.CraftScheduler.scheduleSyncRepeating
    Task(CraftScheduler.java:189)
            at com.topcat.npclib.NPCManager.<init>(NPCManager.java:52)
    I can find the exact place it's talking about but I can't find anything wrong with it and I don't know how to fix it. Any help? Pretty please?
     
  18. Offline

    Neodork

    Without code there is little to see. Did you read the comment of Kekec852? I recommend you to read the comment and look to the code example above it.
     
  19. Offline

    devilquak

    Actually, I just got it working last night, ignore that post if you would :D

    But I have one more problem that I need to ask about. I can spawn an NPC perfectly well with .spawnHumanNPC, but nothing will delete it besides restarting the server since I haven't tried to save them. Neither .despawnById, .despawnHumanByName, nor .despawnAll will work do take anything away. All the correct strings and arguments are in place for each command, just nothing happens. The message "You have erased all the NPCs!" appears when I run the command, but there are no errors or anything, it just doesn't delete anything. Here's my main class right now:

    PHP:
    package com.github.devilquak;
     
    import java.util.logging.Level;
     
    import npclib.NPCManager;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class 
    NPCTest extends JavaPlugin
    {
     
        public 
    NPCTest plugin;
     
        @
    Override
        
    public void onEnable()
        {
            
    this.getLogger().log(Level.INFO,"NPCTest");
            
    plugin this;
        }
     
        public 
    void onDisable()
        {
     
        }
     
        public 
    boolean onCommand(CommandSender senderCommand cmdString labelString[] args)
        {
            
    NPCManager npcManager = new NPCManager(plugin);
            
    Player player = (Playersender;
            
    Location playerLoc player.getLocation();
            if(
    cmd.getName().equalsIgnoreCase("npccreate"))
            {
                
    npcManager.spawnHumanNPC(args[0], playerLoc);
                
    sender.sendMessage(ChatColor.GOLD "You have created an NPC!");
                return 
    true;
            }
            if(
    cmd.getName().equalsIgnoreCase("npcremove"))
            {
                
    npcManager.despawnAll();
                
    sender.sendMessage(ChatColor.GOLD "You have erased all the NPCs!");
                return 
    true;
            }
            return 
    false;   
        }
    }
     
  20. Offline

    Neodork

    Sorry for the late response, vacation. Did you figure this out already ?
     
  21. Offline

    devilquak

    No, I haven't :(

    I'd really appreciate it if I could get a little help with it, I've been stuck on it for a while.
     
  22. Offline

    Neodork

    I haven't tested this but I think this should work fine:
    Code:java
    1. List<NPC> npclist = plugin.m.getNPCs();
    2. for(int i=0;i<npclist.size();i++){
    3. npclist.get(i).removeFromWorld();
    4. }
    5.  
    6. //Edit: This doesn't removes the npc from the npcs list.
    7.  


    Edit: despawnAll() still is the way to go (Works perfect for me)
     
  23. Offline

    devilquak

    I get errors on List<NPC> that I can't get rid of, "NPC cannot be resolved to a type" and "The type List is not generic; it cannot be parameterized with arguments <NPC>" . And what exactly goes in the "m" spot? It's telling me "m cannot be resolved or is not a field".
     
  24. Offline

    Neodork


    import java.util.List;
    import com.topcat.npclib.entity.NPC;
    replace m with npcManager
     
  25. Offline

    bubbleguj

    How to check if the damaged npc is an npc? This doesn't work for me:
    PHP:
        @Override
        
    public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
     
            if (
    event.getEntity() instanceof HumanEntity) {
                
    BasicHumanNpc npc parent.HumanNPCList.getBasicHumanNpc(event.getEntity());
     
                if (
    npc != null && event.getDamager() instanceof Player) {
     
                    
    Player p = (Playerevent.getDamager();
                    
    p.sendMessage("<" npc.getName() + "> Don't hit me so much :P");
     
                    
    NpcSpawner.RemoveBasicHumanNpc(npc);
                    
    parent.HumanNPCList.remove(npc.getUniqueId());
     
                    
    event.setCancelled(true);
     
                }
     
            }
        }
     
  26. Offline

    IDragonfire

    Try to debug it:
    PHP:
        @Override
        
    public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
            
    Bukkit.broadcastMessage("event called");
            if (
    event.getEntity() instanceof HumanEntity) {
                
    BasicHumanNpc npc parent.HumanNPCList.getBasicHumanNpc(event.getEntity());
                
    Bukkit.broadcastMessage("is Human");
                if (
    npc != null && event.getDamager() instanceof Player) {
                     
    Bukkit.broadcastMessage("...");
                    
    Player p = (Playerevent.getDamager();
                    
    p.sendMessage("<" npc.getName() + "> Don't hit me so much :P");
     
                    
    NpcSpawner.RemoveBasicHumanNpc(npc);
                    
    parent.HumanNPCList.remove(npc.getUniqueId());
     
                    
    event.setCancelled(true);
     
                }
     
            }
        }
     
  27. Offline

    Zimbaway

    Is it me or is their no download link?
     
  28. Offline

    IDragonfire

    forums.bukkit.org/threads/npcspawner-lib-spawn-basic-npcs.3298/page-16#post-1343988
     
  29. Offline

    bubbleguj

    ok, all fixed, thx
     
  30. Offline

    Elbcore3

    Hey, i'm pretty new to the Plugin writing and i got a question:

    here is my code:
    Code:
    import org.bukkit.Location;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import com.topcat.npclib.NPCManager;
    import com.topcat.npclib.entity.NPC;
     
    public class Listen extends JavaPlugin
    implements Listener{
        public void onPlayerLogin(PlayerLoginEvent e) {
            Location loc =e.getPlayer().getLocation();
            String name = "LOGIN";
            NPCManager m = new NPCManager(this);
            NPC npc = m.spawnHumanNPC(name,loc);
        }
    }
    
    but somehow i can't do the setIteminHand();
    could someone tell me what i did wrong?
     
Thread Status:
Not open for further replies.

Share This Page