Hey, i want to use citizens api on my plugin, its my code: Code:java import net.citizensnpcs.api.CitizensAPI;import net.citizensnpcs.api.npc.NPC;import net.citizensnpcs.api.npc.NPCRegistry;import net.citizensnpcs.api.trait.TraitInfo; import org.bukkit.Bukkit;import org.bukkit.Location;import org.bukkit.command.Command;import org.bukkit.command.CommandSender;import org.bukkit.entity.Entity;import org.bukkit.entity.EntityType;import org.bukkit.entity.Giant;import org.bukkit.entity.Player;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.event.player.PlayerJoinEvent;import org.bukkit.plugin.java.JavaPlugin; public class Main extends JavaPlugin implements Listener { public void onEnable() { Bukkit.getServer().getPluginManager().registerEvents(this, this); } @EventHandler public void onJoin(PlayerJoinEvent e) { Player p = e.getPlayer(); NPCRegistry registry = CitizensAPI.getNPCRegistry(); NPC npc = registry.createNPC(EntityType.PLAYER, "MyNPC"); npc.spawn(p.getLocation()); } } Plugin didnt output any errors, when i join npc doesnt exists at my location, its strange because i registered my npc, still citizens says: [Citizens] Loaded 0 NPCs. Is my code wrong? Why npc doesnt spawning?
maybe try a delayed task that spawns the npc 5 seconds after you join the game. Again this still may not fix it but it might be worth a try.
Thanks! It works ;-) Maybe you know why entity name returns null? Code:java @EventHandler public void onJoin(PlayerJoinEvent e) { final Player p = e.getPlayer(); new BukkitRunnable() { @Override public void run() { NPCRegistry registry = CitizensAPI.getNPCRegistry(); NPC npc = registry.createNPC(EntityType.PLAYER, "MyNPC"); npc.spawn(p.getLocation()); } }.runTaskLater(this, 90); } @EventHandler public void onClick(EntityDamageByEntityEvent e) { if(e.getEntity()instanceof Player) { Player p = (Player) e.getDamager(); if(e.getEntity().getType() == EntityType.PLAYER) { p.sendMessage("xxx + " + e.getEntityType().getName()); } } } I just want to do, somehing like when player hits npc named MyNPC. p.sendMessage("xxx + " + e.getEntityType().getName()); returns "xxx + null".
Code:java @EventHandler(priority = EventPriority.MONITOR)public void onPlayerHitEntity(EntityDamageByEntityEvent e) { Entity damager = e.getDamager();Entity damagee = e.getEntity(); if(damager instanceof Player && damagee instanceof Zombie) { //if the damager is a player and entity is a zombie for examplePlayer player = (Player) damager;Zombie zombie = (Zombie) damagee; player.sendMessage(zombie.getCustomName());} } this will work every time a player hits a zombie. You may want to check if the entity is an npc first before doing this as it will apply for every time you hit that mob type. It will return null if the entity does not have a custom name so you might want to check that.
Thanks, it was useful. Maybe you know how to remove an event? I seraching this all time, and still cant find. Its last needed thing ;p remove npc* soz EDIT by Moderator: merged posts, please use the edit button instead of double posting.