Custom Villager Names

Discussion in 'Plugin Development' started by Niknea, Dec 29, 2013.

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

    Niknea

    Hello everyone, I was wondering how I can spawn a villager with a custom name, thanks so much!
     
  2. Offline

    NoLiver92

    have you tried anything?
     
  3. Offline

    Ronbo

    Niknea
    setCustomName("name") & setCustomNameVisible(true)
     
  4. Offline

    Niknea

    Ronbo So how would I set it when I spawn a villager, as I want something like /v1 and it will spawn a villager with that name.

    Ronbo Ok I made a command that will spawn a villager, how/where will I add the method you suggested in my code? Here is my code so far.
    Code:java
    1. package me.niknea.Mobs;
    2.  
    3. import org.bukkit.command.Command;
    4. import org.bukkit.command.CommandExecutor;
    5. import org.bukkit.command.CommandSender;
    6. import org.bukkit.entity.CreatureType;
    7. import org.bukkit.entity.Player;
    8.  
    9.  
    10. @SuppressWarnings("deprecation")
    11. public class V1 implements CommandExecutor
    12. {
    13. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
    14. {
    15. Player player = (Player) sender;
    16. if(cmd.getName().equalsIgnoreCase("v1"))
    17. {
    18. player.getWorld().spawnCreature(player.getLocation(), CreatureType.VILLAGER);
    19. }
    20. return true;
    21. }
    22.  
    23. }
    24.  

    Thanks again!
     
  5. Offline

    et477

    there is actuall a very simple way. just take a spawn villager, than put it in the anvil, then click ont eh text that says spawn villager. chage it to whatever you want.
    asi was saying, put the spawn villager in anvil, then you need to click on the txt that says spawn villager. change it to whatever you want
     
  6. Offline

    BillyGalbreath

    Don't use deprecated methods.

    Code:java
    1.  
    2. Entity ent = player.getWorld().spawnEntity(player.getLocation(), EntityType.VILLAGER);
    3. ((Villager)ent).setCustomName("NewName");
    4. ((Villager)ent).setCustomNameVisible(true);
    5.  
     
    Niknea likes this.
  7. Offline

    et477

    no seriously it works i tried it too.
     
  8. Offline

    HungerCraftNL

    It donĀ“t works for me.
    Code:java
    1. LivingEntity ent = p.getWorld().spawnCreature(p.getLocation(), EntityType.VILLAGER);
    2. ent.setCustomName("");
    3. ent.setCustomNameVisible(true);

    A villager is a LivingEntity.
     
Thread Status:
Not open for further replies.

Share This Page