Solved Killing mobs with a custom name (help)

Discussion in 'Plugin Development' started by 123ang, Jul 5, 2014.

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

    123ang

    Trying to kill every mob in the world with the name: player.getName + "'s" + " Mount Donkey" by right clicking a saddle.

    All I can work out is right clicking the saddle, but not being able to kill the mobs with the certain name.

    Here is my code so far:

    Code:java
    1. @EventHandler
    2. public void onDespawnDonkey(PlayerInteractEvent e) {
    3. Player player = e.getPlayer();
    4. Action a = e.getAction();
    5. if (a.equals(Action.RIGHT_CLICK_AIR)){
    6.  
    7. Material m = player.getItemInHand().getType();
    8. if (m == Material.SADDLE) {
    9.  
    10. }
    11. }
    12. }


    Please help me!
     
  2. Offline

    hintss

    Try PlayerInteractEntityEvent.

    edit: oh, and,

    Code:java
    1. for (Entity e : event.getPlayer().getWorld().getEntities()) {
    2. if (e instanceof LivingEntity && !(e instanceof Player)) {
    3. e.remove();
    4. }
    5. }
     
  3. Offline

    123ang

    hintss no that doesn't work because I need to kill all of the mobs in that world with the specific display name by right clicking the saddle.
     
  4. Offline

    hintss

    uh...
     
  5. Offline

    123ang

  6. Offline

    hintss

    did you read my edit?
     
  7. Offline

    123ang

    hintss Oh Okay; thanks! But is there a way to only kill mobs with the certain display name?
     
  8. Offline

    teej107

    123ang The code that hintss works. It is the equivalent of killing a LivingEntity, which mobs are.

    EDIT:
    check to see if the mob's display name is .......
     
  9. Offline

    hintss

    add another if checking the name?
     
  10. Offline

    123ang

    hintss EDIT: In-game when I right clicked the saddle it did nothing.

    Here is the code that I used:

    Code:java
    1. @EventHandler
    2. public void onDespawnDonkey(PlayerInteractEvent e) {
    3. Player player = e.getPlayer();
    4. Action a = e.getAction();
    5. if (a.equals(Action.RIGHT_CLICK_AIR)){
    6.  
    7. Location loc = player.getLocation();
    8. Material m = player.getItemInHand().getType();
    9. if (m == Material.SADDLE) {
    10. for (Entity event : e.getPlayer().getWorld().getEntities()) {
    11. if (e instanceof LivingEntity && !(e instanceof Player)) {
    12. event.remove();
    13. }
    14. }
    15. player.sendMessage(ChatColor.BLUE + "Mounts>" + ChatColor.GRAY + " Despawning Your Mount Donkey...");
    16. }
    17. }
    18. }


    All my events are registered, because it's sending me the message perfectly fine.

    teej107 ?

    teej107 Yes it does.

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

    teej107

    123ang Because you are checking to see if an event is an instance of a LivingEntity.

    EDIT: And a player too.
     
  12. Offline

    123ang

    teej107 I'm just following hintss' code. Do you have an alternative for killing every entity in the world with a specific display name by right clicking a saddle? (Not Sarcasm, lol).
     
  13. Offline

    teej107

    123ang It's not working because:
    Your if statement will always be false because events are never LivingEntities.
     
  14. Offline

    Kassestral

  15. Offline

    123ang

  16. Offline

    teej107

    123ang I post hints with your code. Lets see if you get them.
     
  17. Offline

    123ang

    teej107 I'm so confused right now...

    teej107 I changed LivingEntity to Entity, but it did no difference.
    EDIT: It is now
    Code:java
    1. if (e instanceof Entity) {


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

    teej107

    123ang Pay attention to what you have named your event and what you are checking in your if statement with your code that I posted.
     
  19. Offline

    123ang

    teej107 Just Tell Me What I'm Doing Wrong!!
     
  20. Offline

    teej107

    123ang
     
  21. Offline

    123ang

    teej107 It's 8PM where I am, please just tell me what I'm doing wrong; I can't work things out right now.
     
  22. Offline

    teej107

    123ang I'll tell you whats wrong.
    In this if statement:
     
  23. Offline

    123ang

    teej107 I know & I changed it to:

    Code:java
    1. if (e instanceof Entity) {


    But, it made no difference.
     
  24. Offline

    teej107

    123ang That won't work either since LivingEntity is an Entity also. In fact with that code, you will remove all entities. Item frames, items on ground, etc.
     
  25. Offline

    123ang

    teej107 I'm getting really annoyed here; just tell me what to change it to :( :( :(.
     
  26. Offline

    teej107

    123ang Have you noticed all of my quoted posts? I am telling you your problem.
     
  27. Offline

    xTigerRebornx

    123ang teej107 is giving you the exact problem, 'e' is your event, not an Entity, not a LivingEntity, it is your event (aka a PlayerInteractEvent), what is there not to understand?
     
  28. Offline

    123ang

    teej107 yes I know I can see them! But they don't make sense to me! Just tell me the code, please I don't want to fall asleep tonight with this stuck in my head!

    xTigerRebornx I can see that & I've changed 'e' to 'event'. Does that help?

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

    xTigerRebornx

    123ang I'd have to see your current code.
     
  30. Offline

    123ang

    xTigerRebornx Here is my current code:

    Code:java
    1. @EventHandler
    2. public void onDespawnDonkey(PlayerInteractEvent e) {
    3. Player player = e.getPlayer();
    4. Action a = e.getAction();
    5. if (a.equals(Action.RIGHT_CLICK_AIR)){
    6.  
    7. Location loc = player.getLocation();
    8. Material m = player.getItemInHand().getType();
    9. if (m == Material.SADDLE) {
    10. player.sendMessage(ChatColor.BLUE + "Mounts>" + ChatColor.GRAY + " Despawning Your Mount Donkey...");
    11. for (Entity event : e.getPlayer().getWorld().getEntities()) {
    12. if (event instanceof LivingEntity && !(e instanceof Player)) {
    13. event.remove();
    14. }
    15. }
    16.  
    17. }
    18. }
    19. }
     
Thread Status:
Not open for further replies.

Share This Page