Working with custom mob names

Discussion in 'Plugin Development' started by Stackore, Apr 16, 2014.

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

    Stackore

    Okey so i working with this code
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    2. Player p = (Player) sender;
    3. if(label.equalsIgnoreCase("sm"));
    4. NPC n = (NPC) p.getWorld().spawnEntity(p.getLocation(), EntityType.VILLAGER);
    5. n.setCustomName(ChatColor.GREEN + "Ranker");
    6. n.setCustomNameVisible(true);
    7. return false;


    And i want so when i do /sm i can change custom name
    example: /sm Stackore
    And the custom name would change to Stackore
    I think.. well i AM pretty sure it had something with args to do :p

    Right now when i do /sm it spawn a villager with name "Ranker"

    Hope u guys can help :)
     
  2. Offline

    MrInspector

    I'd suggest you look at this tutorial - http://forums.bukkit.org/threads/tutorial-command-arguments.186497/

    if you look down, I fix a couple of errors, good luck! ;)
     
  3. Offline

    Stackore

  4. Offline

    MrInspector

    It'd be a little bit more harder, but I'm currently busy trying to get something resolved here, I'll see if I can help you later. :(
     
  5. Offline

    Stackore

    Do you think it can be something like this? :)
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    2. Player p = (Player) sender;
    3. if(label.equalsIgnoreCase("sc"));
    4. if (args.length == 0) {
    5. p.sendMessage(ChatColor.RED + "" + ChatColor.ITALIC + "/sm <Mob> <Name>");
    6.  
    7. } else {
    8.  
    9. if (args.length == 1) {
    10. p.sendMessage(ChatColor.RED + "" + ChatColor.ITALIC + "/sm <Mob> <Name>");
    11.  
    12. } else {
    13.  
    14. }
    15. }
    16. Entity ent = (Entity) p.getWorld().spawnEntity(p.getLocation(), EntityType.fromName(args[0]));
    17. ((LivingEntity) ent).setCustomName(ChatColor.translateAlternateColorCodes('&', args[1]));
    18. ((LivingEntity) ent).setCustomNameVisible(true);
    19.  
    20. return false;
    21. }
    22. }
     
  6. Offline

    MrInspector

    Probably. :p

    I'm pretty tired at the moment, I'll help you once i'm well rested, sorry for the delay, someone else may help you though while i'm taking a nap.

    Good luck though. :)
     
Thread Status:
Not open for further replies.

Share This Page