[Lib] [1.7.10] NPCFactory v1.4 - Create walking npcs with custom names and skins!

Discussion in 'Resources' started by lenis0012, May 26, 2014.

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

    Goblom

    I wrote a little piece of code, that calls the NPCInteractEvent.
    Code:java
    1. @EventHandler
    2. public void onInteract(PlayerInteractEntityEvent event) {
    3. if (plugin.getNPCFactory().isNPC(event.getRightClicked())) {
    4. NPC npc = plugin.getNPCFactory().getNPC(event.getRightClicked());
    5.  
    6. NPCInteractEvent nie = new NPCInteractEvent(npc, event.getPlayer());
    7.  
    8. Bukkit.getPluginManager().callEvent(nie);
    9.  
    10. event.setCancelled(nie.isCancelled());
    11. }
    12. }
     
    lenis0012 likes this.
  2. Offline

    shohouku


    I tried cloning it and the API still doesn't exist.

    I used sourcetree to clone the API and I also tried cloning it manually on Eclipse.

    I'm using the API for this:

    Code:java
    1. package plugin;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.Location;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.plugin.PluginDescriptionFile;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. import com.lenis0012.bukkit.npc.NPC;
    14. import com.lenis0012.bukkit.npc.NPCFactory;
    15. import com.lenis0012.bukkit.npc.NPCProfile;
    16.  
    17. public class Main extends JavaPlugin implements Listener {
    18.  
    19. public final Logger logger = Logger.getLogger("Minecraft");
    20. @Override
    21. public void onEnable() {
    22. getServer().getPluginManager().registerEvents(this, this);
    23. PluginDescriptionFile pdfFile = this.getDescription();
    24.  
    25.  
    26. this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " has been Enabled!");
    27.  
    28.  
    29.  
    30. }
    31.  
    32.  
    33. @Override
    34. public void onDisable() {
    35. PluginDescriptionFile pdfFile = this.getDescription();
    36. this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " has been Disabled!");
    37. }
    38. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    39.  
    40. if(label.equalsIgnoreCase("spawnnpc")){
    41. final NPCFactory factory = new NPCFactory(this);
    42. final Location location = new Location(Bukkit.getWorld("world"), 222, 69, -643);
    43. NPC npc = factory.spawnHumanNPC(location, new NPCProfile("lenis0012"));
    44. npc.setYaw(location.getYaw());
    45.  
    46.  
    47. }
    48. return false;
    49. }
    50. }
    51.  
     
  3. Offline

    TeamJesus

    install git and then git clone then point your IDE to the dir of the clone and bam!
     
  4. Offline

    shohouku


    It's the same as SourceTree and Eclipse, :\
     
  5. Offline

    lenis0012

    shohouku You have to clone it into your src directory and then reload your project.
     
    Europia79 likes this.
  6. Offline

    shohouku

    npc.lookAt, the npc doesn't look up or down.

    And both the events are kinda buggy :p
     
  7. Offline

    lenis0012

    lookAt only changes yaw that is correct.
    I can add pitch support if you want.

    The events are called from actualy code inside the enttiy.
    However its better if you use bukkit events and check factory.isNPC(event.getEntity()) until i solved it
     
    shohouku likes this.
  8. Offline

    shohouku

  9. Offline

    lenis0012


    use args[0] and args[1] for the first 2 args
    Anf you may not want to check if if has a argument and 2 arguments.
    Because thats impossible

    Remove "if(args.length() == 1)"
     
    shohouku likes this.
  10. So normal player/animal behavior won't exist I'm guessing? ;( I really would like NPCs to randomly move like an animal, I have no idea how to do this myself without making it look really glitchy, like they're teleport/speed hacking.
     
  11. Offline

    shohouku

    How would I get a certain NPC from my world, without creating a new profile?

    I tried this, didn't work out:

    Code:java
    1. for(Entity entity : world.getEntities()){
    2. NPC npc = factory.getNPC(entity);
    3. }
     
  12. Offline

    Goblom

    shohouku Add this to your NPC class.
    Code:java
    1. public String getName();


    That way you can get an npc by its name.
     
  13. Offline

    shohouku


    Looks like it aint getting the NPC name, because I'm getting a null exception.

    Code:java
    1. if(label.equalsIgnoreCase("removenpc")) {
    2. World world = Bukkit.getWorld("world");
    3. final String name = args[0];
    4. for(Entity entity : world.getEntities()){
    5. NPC npc = factory.getNPC(entity);
    6. String test = npc.getName();
    7. System.out.println(test);
    8. if(test == null) {
    9. p.sendMessage(name + " does not exist!");
    10. } else {
    11. if(test.equalsIgnoreCase(name)) {
    12. npc.getBukkitEntity().remove();
    13. }
    14. }
    15. }
    16. }
    17. }
    18.  


    Code:java
    1. public String getName();
    2. /**
    3. * Get the entity the npc name
    4. *
    5. * @return Entity npc name (null if not found)
    6. */
     
  14. Offline

    Goblom

    shohouku You have an error with your getNPC(entity) because it has to do with casting if you get an entity that was not created with the spawnHumanNPC your code will stop running...

    I suggest using isNPC(entity) before using getNPC(entity)
     
  15. Offline

    shohouku


    I get an error using this:

    Code:java
    1. if(factory.isNPC(entity)) {


    and I'm still getting a null when I try and get the name.

    Code:java
    1. System.out.println(test);
     
  16. Offline

    xTigerRebornx

    shohouku You preform no check to see if the Entity you are calling getNPC() on is actually an NPC. You are calling getNPC() on all entities regardless of whether or not they are actually an NPC,
     
    shohouku likes this.
  17. Offline

    IDragonfire

  18. Offline

    shohouku

    Is it possible to save the NPCs so they don't get removed after a reload?
     
  19. Offline

    Goblom

    shohouku Its removed on reload because the entity loses its "npc-ness" when that happens, just have the entity re-spawn onEnable() or something
     
  20. Offline

    lenis0012

  21. Offline

    IDragonfire

    Why?
    Why you then not call the baseTick method manually?
     
  22. Offline

    lenis0012

    Thats what i am doing
     
  23. Offline

    IDragonfire

  24. Offline

    lenis0012

  25. Offline

    PandazNWafflez

    So, can the NPCs punch out blocks and stuff? As in, will calling the SWING_ARM animation actually make them hit something or just show the animation?
     
    Europia79 likes this.
  26. Offline

    TeamJesus


    just show animations....
     
  27. Offline

    MiniDigger

    I am getting an error if I try to spawn an npc and send something with protocollib
    Code:
    [16:18:11] [Server thread/INFO]: MiniDigger issued server command: /npc spawn
    [16:18:12] [Server thread/INFO]: MiniDigger lost connection: Internal Exception: net.minecraft.util.io.netty.handler.codec.EncoderException: java.lang.RuntimeException: An internal error occured.
    [16:18:12] [Server thread/INFO]: MiniDigger left the game.
    [16:18:13] [pool-3-thread-2/WARN]: java.lang.IllegalArgumentException: Unable to find a field null with the type net.minecraft.util.io.netty.channel.Channel in com.lenis0012.bukkit.npc.NPCNetworkManager
    [16:18:13] [pool-3-thread-2/WARN]:    at com.comphenix.protocol.reflect.FuzzyReflection.getFieldByType(FuzzyReflection.java:367)
    [16:18:13] [pool-3-thread-2/WARN]:    at com.comphenix.protocol.reflect.accessors.Accessors.getFieldAccessor(Accessors.java:56)
    [16:18:13] [pool-3-thread-2/WARN]:    at com.comphenix.protocol.reflect.FuzzyReflection.getFieldValue(FuzzyReflection.java:104)
    [16:18:13] [pool-3-thread-2/WARN]:    at com.comphenix.protocol.injector.netty.InjectionFactory.fromPlayer(InjectionFactory.java:72)
    [16:18:13] [pool-3-thread-2/WARN]:    at com.comphenix.protocol.injector.netty.NettyProtocolInjector$4.sendServerPacket(NettyProtocolInjector.java:341)
    [16:18:13] [pool-3-thread-2/WARN]:    at com.comphenix.protocol.injector.PacketFilterManager.sendServerPacket(PacketFilterManager.java:791)
    [16:18:13] [pool-3-thread-2/WARN]:    at com.comphenix.protocol.injector.PacketFilterManager.sendServerPacket(PacketFilterManager.java:765)
    [16:18:13] [pool-3-thread-2/WARN]:    at me.MiniDigger.Core.ProtocolAPI.SignChangers.sendSignChange(SignChangers.java:391)
    [16:18:13] [pool-3-thread-2/WARN]:    at me.MiniDigger.Core.ProtocolAPI.SignChangers.update(SignChangers.java:46)
    [16:18:13] [pool-3-thread-2/WARN]:    at me.MiniDigger.Core.ProtocolAPI.ProtocolManager$2.run(ProtocolManager.java:55)
    [16:18:13] [pool-3-thread-2/WARN]:    at org.bukkit.craftbukkit.v1_7_R3.scheduler.CraftTask.run(CraftTask.java:53)
    [16:18:13] [pool-3-thread-2/WARN]:    at org.bukkit.craftbukkit.v1_7_R3.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:53)
    [16:18:13] [pool-3-thread-2/WARN]:    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    [16:18:13] [pool-3-thread-2/WARN]:    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    [16:18:13] [pool-3-thread-2/WARN]:    at java.lang.Thread.run(Thread.java:745)
    SignCHangers.sendSignChange just creates an packet and sends it...
     
  28. Offline

    lenis0012

    You are trying to send a packet to an npc
     
  29. Offline

    MiniDigger

    lenis0012 Ah, thank you, Sir.
    EDIT: This did not solve everything. I still get disconnected when I create the NPC.
    Code:
    [22:58:05 INFO]: MiniDigger issued server command: /npc spawn
    [22:58:05 INFO]: MiniDigger lost connection: Internal Exception: net.minecraft.util.io.netty.handler.codec.EncoderException: java.lang.RuntimeException: An internal error occured.
    [22:58:06 INFO]: MiniDigger left the game.
    [22:58:23 INFO]: MiniDigger[/127.0.0.1:56230] logged in with entity id 20198 at ([Spawn] 969.0, 108.0, 85.0)
    [22:58:23 INFO]: MiniDigger lost connection: Internal Exception: net.minecraft.util.io.netty.handler.codec.EncoderException: java.lang.RuntimeException: An internal error occured.
    [22:58:23 INFO]: MiniDigger left the game.
    Here is my spawn code http://pastebin.com/RNV49t9z
     
  30. Offline

    Goblom

    MiniDigger What server version are you running? 1.7.10 currently breaks NPCs and causes an error like that.
     
Thread Status:
Not open for further replies.

Share This Page