Set a Displayname for a mob

Discussion in 'Plugin Development' started by CorePvP, Nov 27, 2013.

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

    CorePvP

    Hey how can i set the Displayname of a mob which i choose in a command

    final Player p = (Player) cs;
    if(label.equalsIgnoreCase("mob")) {
    if(args.length != 2) {
    p.sendMessage("§cusage: /mob <mob> <name>");
    }
    if(args.length == 2) {
    Location loc = p.getLocation();
    Entity ent = p.getWorld().spawnEntity(loc, EntityType.valueOf(args[0])) {

    }
    }
    }

    thats my code but i don't know how i can use my args in the CreatureSpawnEvent
     
  2. Wait, are you having trouble by setting the mobs name, or with the commands stuff?
     
  3. Offline

    CorePvP

    Setting the Mobs name :)
     
  4. Offline

    pope_on_dope

    mob.setDisplayName("")
     
  5. Offline

    JPG2000

    CorePvP Um:
    Code:java
    1. Sheep s = (Sheep) Bukkit.getWorld("world").spawnEntity(player.getLocation(), EntityType.SHEEP);
    2.  
    3. s.setDisplayName("CUSTOM NAME");


    Just change 'Sheep' and the casting when ever you want a different mob.
     
  6. Offline

    iCopyright

    JPG2000 CorePvP

    you must define that the custom name should be visible to players.
    Code:java
    1. public void spawnGolem(Player player) {
    2. CraftGolem golem = (CraftGolem) player.getLocation().getWorld()
    3. .spawn(player.getLocation(), Golem.class);
    4.  
    5. golem.setCustomName(ChatColor.GREEN + "Iron Golem");
    6. golem.setCustomNameVisible(true);


    that is an easy way to do it.

    to spawn the mob:
    Code:java
    1. public boolean onCommand17(CommandSender sender, Command cmd, String label,
    2. String[] a) {
    3. if (cmd.getName().equalsIgnoreCase("golem")) {
    4. Player player = (Player) sender;
    5. spawnGolem(player);
    6. }
    7. return false;


    if you want me to, i can paste all of my code from the beginning.
     
  7. Offline

    JPG2000

    HyVe No you don't. If you don't make it visible, you can see if if hover over the entity. (By hover I mean mouse over it)
     
  8. Offline

    iCopyright

    the code i provided lets the mob have a nametag just like a player all the time.

    if that was your question.

    JPG2000
     
  9. Offline

    JPG2000

    HyVe No. You said:
    Which is incorrect. What that says is the custom name tag won't be visible to players unless you do the code your way, which is wrong. I know what you men't, but they way you wrote it...
     
  10. Offline

    iCopyright

    JPG2000 well than i am very sry. hope you forgive:p

    but anyways, i am going to leave this thread alone now, have a good day and i hope that i have been to help.

    Regards
    -HyVe
     
    JPG2000 likes this.
  11. Offline

    JPG2000

    HyVe I wasn't angry, I just thought you gave the wrong information :p
     
Thread Status:
Not open for further replies.

Share This Page