***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 }
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
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.
Your change is wrong, just change server = BServer.getInstance((Server) plugin); -> server = BServer.getInstance(); My mistake, but your fix is unnecessary
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)
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 (I'm not fluent in english as I'd like)
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.
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.
Nope But it just randomely started working again, I didn't change anything... odd... Thanks again for the lib, top_cat :3
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)
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?
That's why you have so many errors, that was last updated Feb 2011. Try reading at least one page before posting on a thread. Also I HATE DOUBLE POSTERS. Now I have that out of my system here's the link to the latest version, https://github.com/Top-Cat/NPCLib