NpcSpawner lib - spawn basic NPCs

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

  1. Offline

    Trc202

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    It's already there.

    This post has been edited 1 time. It was last edited by Trc202 Dec 4, 2011.
  2. Offline

    Abrupt

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    no it isn't. that's for regular Entities. NPCEntities can not be cast to regular Entities.
  3. Offline

    Top_Cat

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Yes, yes you can...
    Code:
    getNPCIdFromEntity(npcEntity.getBukkitEntity());

    This post has been edited 1 time. It was last edited by Top_Cat Dec 4, 2011.
  4. Offline

    Abrupt

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    oh, duh. I have no idea how I didn't think about that, I even used it in my function. my bad.
  5. Offline

    Top_Cat

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    ***Notice***
    Spout update! Woot!
    With the latest source, available at https://github.com/Top-Cat/NPCLib you can get the spout player for an npc with which you can set the skin and cape. The method itself is safe on non-spout servers, however it will cause an error when you try and use the return. Therefore I recommend you check if spout is on the server and possibly create a soft dependency. You can check for spout reliably (as long as you have a soft depend) like this:

    Code:
    try {
        Class.forName("org.getspout.spout.Spout");
        //Spout on server
    } catch (ClassNotFoundException e) {
        //Spout not on server
    }

    This post has been edited 1 time. It was last edited by Top_Cat Dec 7, 2011.
  6. Offline

    rings_akira

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    First of all, thanks for the lib ;)
    I have some questions.

    1.- Top_cat, I've recently downloaded the last source and the cosntructor of NPCManager says that plugin must be cast to the type Server. Is this an error?
    Code:
    public NPCManager(JavaPlugin plugin) {
            server = BServer.getInstance((Server) plugin);
    .
    .
    .
    Also, does this new version require that I add the spoutapi to my project in Eclipse AND the one from spout?

    Until now, I've only needed the spoutapi one, and I've used snippets like
    Code:
    NPCEntity npc = plugin.nm.spawnNPC("MyName", location);
    SpoutPlayer splayer = SpoutManager.getPlayer(playerWhoTriggersEvent);
    splayer.setEntitySkin((LivingEntity) npc.getBukkitEntity(), "URL", EntitySkinType.DEFAULT);
    to set skins. What advantage does this last source provide?

    2.- I'vefound myself in need of a function to set the item in hand of my NPC's but suppotring wool color (damage/durability of the item). Adding this to NPCEntity.java

    Code:
    public void setItemInHand(Material m,short damage) {
            ((HumanEntity) getBukkitEntity()).setItemInHand(new ItemStack(m, 1,damage));
        }
    did "the trick" for me.

    Thanks

    This post has been edited 1 time. It was last edited by rings_akira Dec 8, 2011.
  7. Offline

    rings_akira

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    For the first part of my previous point, I had to leave NPManager as in the source (without the cast) and add this to Bserver.java:
    Code:
    public static BServer getInstance(JavaPlugin pl) {
            if (ins == null) {
                ins = new BServer(pl);
            }
            return ins;
        }
        private BServer(JavaPlugin plugin) {
            //Getting neede structures
            server = plugin.getServer();
            try {
                cServer = (CraftServer) server;
                mcServer = cServer.getServer();
            } catch (Exception ex) {
                Logger.getLogger("Minecraft").log(Level.SEVERE, null, ex);
            }
            //end
        }
    that were on the previous version.
  8. Offline

    Top_Cat

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Your change is wrong, just change
    server = BServer.getInstance((Server) plugin); -> server = BServer.getInstance();

    My mistake, but your fix is unnecessary

    This post has been edited 3 times. It was last edited by Top_Cat Dec 9, 2011.
  9. Offline

    Top_Cat

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Didn't think about that, but yes you need to import spout api (http://spout.in/pluginapidev) for this to compile. Although as mentioned spout is not needed on the server unless you're using these features.

    This code allows you to set the skin and clock of the npc not the player.

    As for 2, I've added that method (implemented slightly better) :)
  10. Offline

    rings_akira

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Thank you Top_Cat for all the help :)
    I downloaded again your new source but since I've also upgraded my bukkit jar I feel there's been some changes on the bukkit code that are causing me some problems, I'll deal with that later.

    Refering to one of my previous issues, I did indeed add the spout api jar but, in your imports you do have:
    Code:
    import org.getspout.spout.player.SpoutCraftPlayer;
    import org.getspout.spoutapi.player.SpoutPlayer;
    and while the 2nd one resolves correctly, the first does not. So I have to add spoutapi AND spout jars and I'm wondering if that's correct.

    P.D.: Sorry about the "fix thing" in my first comment, I hope I didn't sound like a smart ass or something, or that I was implying a bad source code from your part :p (I'm not fluent in english as I'd like)
  11. Offline

    orange451

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Can you try to fix the damaging of NPC's?
    Since 1.0.0 bukkit, they no longer work :/
  12. Offline

    Top_Cat

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I just fixed and tested killing an NPC. Since my spout update they were in creative mode.
  13. Offline

    orange451

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    You sir, have made my day.
    [EDIT]
    I downloaded the NPClib that you update 8 hours ago
    I still cannot amage my NPC's... I had to take out the SpoutPlayer stuff however, because I don't want to use spout in my plugin.

    This post has been edited 2 times. It was last edited by orange451 Dec 12, 2011.
  14. Offline

    Top_Cat

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    You can leave the code, it won't cause any errors if spout isn't on the server...
    If damaging doesn't work then another plugin is interfering or pvp is turned off. It works, so it's you not me.

    This post has been edited 1 time. It was last edited by Top_Cat Dec 12, 2011.
    r3Fuze likes this.
  15. Offline

    orange451

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    It's the only plugin I have in my server...
    Which worked fine before 1.0.0

    This post has been edited 1 time. It was last edited by orange451 Dec 14, 2011.
  16. Offline

    Trc202

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Are you spawning the npc in spawn (pvp protected area)?
  17. Offline

    orange451

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Nope
    But it just randomely started working again, I didn't change anything...
    odd...
    Thanks again for the lib, top_cat :3
  18. Offline

    GarretSidzaka

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    orange that error you and me talked about is still there and its crashing the shit out of my server.
  19. Offline

    Top_Cat

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Care to elaborate?
  20. Offline

    GarretSidzaka

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    ill let orange explain it he much much smarter than me at code.
  21. Offline

    orange451

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I have, last time I asked you to fix it, remember? You told me to send my source code to you, and you never responded back...
    Code:
    2011-12-14 18:08:14 [SEVERE] java.lang.NullPointerException
    2011-12-14 18:08:14 [SEVERE]  at net.minecraft.server.World.getEntities(World.java:990)
    2011-12-14 18:08:14 [SEVERE]  at net.minecraft.server.Entity.move(Entity.java:417)
    2011-12-14 18:08:14 [SEVERE]  at net.minecraft.server.EntityItem.w_(EntityItem.java:64)
    2011-12-14 18:08:14 [SEVERE]  at net.minecraft.server.World.entityJoinedWorld(World.java:1253)
    2011-12-14 18:08:14 [SEVERE]  at net.minecraft.server.WorldServer.entityJoinedWorld(WorldServer.java:107)
    2011-12-14 18:08:14 [SEVERE]  at net.minecraft.server.World.playerJoinedWorld(World.java:1235)
    2011-12-14 18:08:14 [SEVERE]  at net.minecraft.server.World.tickEntities(World.java:1142)
    2011-12-14 18:08:14 [SEVERE]  at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:518)
    2011-12-14 18:08:14 [SEVERE]  at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:425)
    2011-12-14 18:08:14 [SEVERE]  at net.minecraft.server.ThreadServerApplication.run(SourceFile:457)
    2011-12-14 18:08:14 [SEVERE] Unexpected exception
    java.lang.NullPointerException
     at net.minecraft.server.World.getEntities(World.java:990)
     at net.minecraft.server.Entity.move(Entity.java:417)
     at net.minecraft.server.EntityItem.w_(EntityItem.java:64)
     at net.minecraft.server.World.entityJoinedWorld(World.java:1253)
     at net.minecraft.server.WorldServer.entityJoinedWorld(WorldServer.java:107)
     at net.minecraft.server.World.playerJoinedWorld(World.java:1235)
     at net.minecraft.server.World.tickEntities(World.java:1142)
     at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:518)
     at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:425)
     at net.minecraft.server.ThreadServerApplication.run(SourceFile:457)

    This post has been edited 3 times. It was last edited by orange451 Dec 17, 2011.
  22. Offline

    KaiBB

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I got confused and uploaded the example project into Eclipse to look at. It's full of errors I don't know how to fix, so I'm stuck. Can somebody help? :(

    This post has been edited 1 time. It was last edited by KaiBB Dec 20, 2011.
  23. Offline

    Top_Cat

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Example project?
  24. Offline

    KaiBB

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    There's a downloadable "example plugin"...
  25. Offline

    Top_Cat

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    No there really isn't... link?
  26. Offline

    KaiBB

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    It's on the bottom of the post.
  27. Offline

    KaiBB

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
  28. Offline

    Top_Cat

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)

    This post has been edited 1 time. It was last edited by Top_Cat Dec 21, 2011.
  29. Offline

    KaiBB

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Thank you so much! That was driving me insane, because I had no idea what was wrong with everything :eek:
  30. Offline

    orange451

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Make and progress on the server error, @Top_Cat ?

    This post has been edited 1 time. It was last edited by orange451 Dec 22, 2011.

Share This Page