1.12.2 Trying to get npc from another class

Discussion in 'Spigot Plugin Development' started by Carster, Feb 19, 2020.

  1. Hey so i trying to create this npc i spawned in this class:
    Code (Text):
    package customEntities;

    import net.citizensnpcs.api.CitizensAPI;
    import net.citizensnpcs.api.npc.NPC;
    import net.citizensnpcs.nms.v1_12_R1.entity.nonliving.ArmorStandController;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.entity.ArmorStand;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.AsyncPlayerChatEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerMoveEvent;
    public class CustomZombie implements Listener {
        @EventHandler (priority = EventPriority.HIGHEST)
        void JoinEvent(PlayerJoinEvent event){

            Player player = event.getPlayer();
            Object playerLoc = player.getLocation();
            NPC npc = CitizensAPI.getNPCRegistry().createNPC(EntityType.PLAYER, player.getPlayerListName() + "'s" + "pet");

            npc.spawn(player.getLocation());
            npc.setBukkitEntityType(EntityType.ARMOR_STAND);



        }



    }
     
    But i dont know how i can get it in this class :/

    Code (Text):

    package customEntities;
    import net.citizensnpcs.api.CitizensAPI;
    import net.citizensnpcs.api.npc.NPC;
    import net.citizensnpcs.api.npc.NPCRegistry;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerMoveEvent;

    public class MoveTPEvent implements Listener {
        @EventHandler(priority = EventPriority.HIGHEST)
        void MoveEvent(PlayerMoveEvent event){

            Player player = event.getPlayer();

            //I trying to get the NPC with the name i created in the last class
            npc.getNavigator().setTarget(player, true);



        }



    }
     
     
    #1 Carster, Feb 19, 2020
    Last edited: Feb 19, 2020
  2. Couple of nitpicks, why are you storing playerLoc as an Object instead of a Location, and then just using player.getLocation() again anyway? Second of all, do you really need to re-set the target to every player every time they move?
     
  3. I dont know i just want to make the armorstand follwo the player
     
  4. You need to store the NPC instance somewhere in order to access is from another class. Based on your code you could probably just move both handlers in one class which makes it even easier (just declare a map for it in that class). I also don't understand why you even have a class called CustomZombie that is a listener and spawns in a player type NPC on player join just to change the entity type to a armor stand after that? Really confusing, don't just copy and paste stuff together.
     
  5. I do not copy paste but in the start i would make a zombie not a armorstand