Solved Spawning and killing mobs with a custom name

Discussion in 'Plugin Development' started by ThatGuyWhoDied13, Nov 1, 2013.

Thread Status:
Not open for further replies.
  1. Hey guys, I was wondering how to spawn mobs with a custom name and then kill them and spawn it again but with a different name e.g. Spawning an Ender Dragon with the name ChatColor.AQUA + ChatColor.BOLD + "DRAGON NAME" and then kill it and spawn one with the name ChatColor.GREEN + ChatColor.BOLD + "DRAGON NAME" and then continue to spawn dragons and kill them going through the colours AQUA, GREEN, RED, GOLD and DARK_PURPLE. I've already got the scheduler ready but I don't know how to spawn mobs at a certain location
    Code:java
    1. int task = Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    2. public void run() {
    3.  
    4. }
    5. }, 5L, 5L);

    If you can help can you finish my code in the comments, thanks
     
  2. Offline

    JPG2000

    KevyPorter I don't get what the second part your asking about.


    Here is how to spawn with a custom name:
    Code:java
    1. LivingEntity entity = (LivingEntity) Bukkit.getWorld("world").spawnEntity(location, EntityType.SHEEP);
    2. entity.setCustomName("name");
    3.  
    4. //Rememebr, for custom things, like a she eps dye color, you can use the actual object of an animal
    5. //IE Sheep, etc
    6. Sheep sheep = (Sheep) Bukkit.getWorld("world").spawnEntity(location, EntityType.SHEEP);
    7. sheep.setCustomName("name");
    8. sheep.setDyeColor(DyeColor.BLACK);
    9.  
     
  3. JPG2000 Thanks. The second part is killing that mob and spawning a new one with a different name
     
  4. Offline

    JPG2000

    KevyPorter Use entity death event:
    Code:java
    1. @EventHandler
    2. public void onEntityDeath(EntityDeathEvent event) {
    3. Entity entity = event.getEntity();
    4. if (entity.getCustomName().equals("name") {
    5. entity.getWorld().spawnEntity(entity.getLocation, entity.getType());
    6. //... display name here
    7. }
    8. }
     
  5. JPG2000 Thanks :3

    JPG2000 but how do I put them in a scheduler would I remove the EventHandlet and just add them one after another

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  6. Offline

    JPG2000

    KevyPorter ?

    Never remove the @EventHandler or else the event won't fire. If you want to spawn one with a delay, add in the code when nessicary.
     
  7. Sorry, I've only been doing bukkit for a month and a half there's still some things it don't get. But anyways thankyou
     
    JPG2000 likes this.
  8. Offline

    JPG2000

    KevyPorter Its all cool. Feel free to message me and I'll add you on skype so I can help :p
     
  9. JPG2000 can I add you tomorrow :3 it's just I'm at my dad's house and he's internet isn't the best for Skype(I'm on my phone at the moment) and then I can share my screen with you and my headset is there as well so we can talk. But I can still give you my Skype
     
  10. Offline

    JPG2000

  11. JPG2000 Kevy.Porter
    Also how do I mark a thread as solved?
     
  12. Offline

    JPG2000

    KevyPorter Click "edit thread" at the very top of the OP, then tag solved. And added :)
     
  13. Marked as solved. I'll accept when I get home tomorrow :3 around 4ish
     
  14. Offline

    RainoBoy97

    Store the mobs UUID somewhere, get the mob by it's UUID and kill it!
     
Thread Status:
Not open for further replies.

Share This Page