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

    Necrodoom

    tommyhoogstra bukkit API is Java. You can't learn bukkit API but not know Java. Its like saying you know how to write in English, but not understand any word in English.
     
  2. Offline

    tommyhoogstra

    And you can't make bukkit plugins without knowing the bukkit API, I know enough Java to make plugins, and me throwing lines of code at him is a win for me, as I'm learning more about the API at the same time. Any who, we can stop arguing now, its not helping anyone.


    Edit: Thread solved.
     
    123ang likes this.
  3. Offline

    Necrodoom

    tommyhoogstra maybe a win for you, but an issue for him, as you practically just confused him.
    If you wish to learn Java and bukkit API, dont do so by harming others.
     
  4. Offline

    123ang

    tommyhoogstra I'm not getting the message that I put before the if statement.

    Updated 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.playSound(loc, Sound.HORSE_SADDLE, 1, 0);
    11. player.sendMessage(ChatColor.BLUE + "Mounts>" + ChatColor.GRAY + " Despawning Your Mount Donkey...");
    12. for (LivingEntity ent : e.getPlayer().getWorld().getLivingEntities()) {
    13. player.sendMessage("Testing...");
    14. if(!(ent instanceof Horse)) return;
    15. if(ent.getCustomName().contains(player.getName() + "'s" + " Mount Donkey")) {
    16. ent.setHealth(0D);
    17. }
    18. }
    19.  
    20. }
    21. }
    22. }


    Necrodoom Please don't start an argument on my thread!
     
  5. Offline

    DevRosemberg

    123ang
    1) You are storing Action & Material, why?
    2) You are never checking if the entity does not have a name which will end up giving you an NPE.
    3) ent.setHealth(0);? Why not just ent.remove();
     
  6. Offline

    123ang

    DevRosemberg ent.remove(); doesn't work either. I am also storing action & material because I want it to delete the donkey by right clicking the saddle
     
  7. Offline

    tommyhoogstra

    No need to check if it has a custom name, just check if the owner of the tamed animal is the player
     
    123ang likes this.
  8. Offline

    123ang

    tommyhoogstra Helped me solve this :)!

    Here is the code he told me:

    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.playSound(loc, Sound.HORSE_SADDLE, 1, 0);
    11. player.sendMessage(ChatColor.BLUE + "Mounts>" + ChatColor.GRAY + " Despawning Your Mount");
    12.  
    13. for (LivingEntity ent : e.getPlayer().getWorld().getLivingEntities()) {
    14. if(ent instanceof Tameable){ // Checks if its a tameable entity, in this case it is.
    15. if(((Tameable) ent).isTamed()){ // Checks if the animal has been tamed, otherwise itl skip the rest of the code.
    16.  
    17.  
    18. if(((Tameable) ent).getOwner().equals(player)){ // Checks if the owner of the animal is the person right clicking with the saddle
    19.  
    20. ent.remove();
    21. }
    22. }
    23. }
    24. }
    25. }
    26. }
    27. }
     
  9. Offline

    Necrodoom

    tommyhoogstra you are still feeding him code though PM, aren't you?
     
  10. Offline

    tommyhoogstra

    I sent him 3 commented lines of code.
    Get over it.
     
  11. Offline

    Necrodoom

    tommyhoogstra you just cant let him actually learn Java first, don't you? You have to act selfish and give him junk code just so you somehow understand bukkit API better even though you help no one like this.
     
  12. Offline

    tommyhoogstra

    If you're so good yourself Necrodoom why don't you teach him.
    So far, you haven't even made an effort in this thread, shows me your all talk and nothing but an attention seeker.

    He provided code, he wanted to know how to fix it, so I did.
     
  13. Offline

    Necrodoom

    tommyhoogstra you haven't gave anyone a chance because you kept feeding him code.
    You didn't tell him how to fix it, you told him "here is the fix, copy-paste it". There's a vast amount of difference, being that it doesn't help anyone.

    The plugin development forums are here to help you LEARN how to code plugins, not for coding plugins for you. Please read http://www.javaprogrammingforums.com/content/45-problem-spoon-feeding.html for why spoon feeding is bad.

    In conclusion, stop thinking you know how to help if you don't actually know the subject. All you are doing is telling people that copy-pasting someone else's code is the solution, when it isn't.

    In this current point, your spoonfed code may appear to do what you thought it should do, but fact is, it doesn't. It takes every single tameable mob, including wolves and cats, and removes them too, even if they don't have a custom name. You just made this thread into a scrapyard of confusion and showed everyone why exactly spoonfeeding is so bad.
     
  14. Offline

    teej107

    Whether the spoonfed guy wants to hurt himself by accepting spoonfed code without trying to understand it is up to him. Anybody can spoonfeed code even if it works and is relevant or not. Try figuring this code out: http://pastebin.com/V2YUYbZD.
    What if I told you that the code shown was needed to take control and change a players location? A guy who actually looked up on how the code worked would eventually find out that the posted code has nothing to do with Bukkit. xD. In fact, if I ever spoonfeed code to anybody, I might just hide
    Code:java
    1. Bukkit.shutdown();
    in it. Just to make a point that spoonfeeding isn't worth taking in.
     
    tommyhoogstra likes this.
  15. Offline

    tommyhoogstra


    You're quoting things I haven't even said, and besides, if you actually read the front page you would understand 90% of it is his own code. He hasn't asked me to write his entire plugin, because he wants to do it himself, even by putting the pieces together helps to develop his logic. I practically transitioned straight from C to bukkit, because java is C based.

    I am proud of what I've done here, because if you haven't noticed, the plugin request section only produces plugins for about 10% of the plugins requested. So at the same time as me "spoon feeding" him 3 explained lines of code, which can be adjusted using an instanceof snippet i previously provided, potentially creates another developer, which is something we should all want in the bukkit community.

    You say
    , but what is this supported by, who HAS learnt java? It is an evolving language with thousands of new possibilities.
     
  16. Offline

    Necrodoom

    tommyhoogstra except, he just copy-pastes your code, he hasn't learnt anything, and he couldn't learn anything from copying lines that don't actually do what he wants, because he doesn't understand variable types.

    You haven't creates another developer, you created a person who expects the solution to problems always comes from spoon feeding, which means, he won't actually be able to solve the problem himself and adjust it, if he doesn't actually learn Java.

    And you perfectly know that when I say learn Java, I mean learn its syntax and how to work with Java logic. You, for some reason, thing that this is unneeded, and think all that is needed is knowing an API that uses Java is all that is needed. This is false, and simply teaches people to copy-paste code. Ive seen this a lot, and you aren't helping anyone. You are just creating problems for the future.
     
  17. Offline

    tommyhoogstra

    Necrodoom I never said all you need to know is the API, of course you need to understand basic syntax and logic in order to apply it. I said I was helping him, as I was interested in how to work with Tameable mobs as well.

    Lets just stop the arguing here, if you want to be crowned victor, fine.
    If he wants to be spoon fed, its his mistake for taking it in.
     
  18. Offline

    Necrodoom

    Oh god no.
    So now you blame the user for your unhelping?
     
  19. Offline

    tommyhoogstra

    Necrodoom No, I'm saying we can stop arguing now because this issue has been resolved.
    Ok yes, I spoon fed him code, welcome to the bukkit development section. Now people in the future who
    google how to kill all of a players tamed mobs will have a result lying at there feet.
     
  20. Offline

    tommyhoogstra

    The amount of times ive googled things to solve a problem, 98% of the time there is a result there for me to look at, as a large snippet as well :)
     
  21. Offline

    Necrodoom

    tommyhoogstra and learn nothing in the process, i presume.
    What happened to actually learning logic of programming languages?
     
  22. Offline

    tommyhoogstra

    I've learnt plenty, who are you to judge?
     
  23. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    Locked. This is the plugin development subforum not the plugin copy/paste forum or the drama forum.
     
    tommyhoogstra likes this.
Thread Status:
Not open for further replies.

Share This Page