Cancel knockback

Discussion in 'Plugin Development' started by JellyYods, May 20, 2014.

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

    JellyYods

    Hello everyone I'm making a kit called anchor and I already have it to where the player deals no knockback, but now I need it to where you the player wont take knockback I tried to setVelocity on hit. That didn't work it would let me move in-game.
     
  2. JellyYods
    You can cancel the event and just damage the player being damaged.
     
  3. Offline

    JellyYods

    Can you please write the code
    I don't understand what you mean.
     
  4. JellyYods
    I can give you a basic concept. You can listen to EntityDamageByEntityEvent, check if the Entity & Damager are players and Damager is of anchor class. Cancel the event and just damage the player the amount of damage the event received.
     
  5. Offline

    JellyYods

    Okay I dont understand much about craftbukkit im starting off to learn and making something simple Like taking no knockback I dont know how to cancel an event
     
  6. Offline

    JellyYods

  7. Gater12 Gave you the correct answer. There is no reason to bump. You also cannot bump until 24 hours has elapsed. If you can't transfer what he said in plain language into code then you probably don't have the right skill-setto be making plugins.
     
  8. Offline

    JellyYods

    Its a good thing im learning how to do it
    stupid
     
  9. Offline

    GeorgeeeHD

    he pretty much gave it to you... if he fully gave it to you, you would just copy and paste it and probably not learn from this at all. but he gave you one of the like 3 lines of code needed to do this.
     
  10. Offline

    JellyYods

    Well im fricin new and I dont know what he means by entity a player would it look like this Entity player = e.getPlayer();
     
  11. Listen, this isn't a "Give others Code" community, this is a "We'll explain how to do it, but you must execute our instructions so you may learn". There's a Bukkit Plugin tutorial here. I suggest using it. As to answer your question, it's simple. Listen for the EntityDamageByEntityEvent, then if both the damager and the damaged are instances of Players and the damager has the anchor class, cancel the event and set the health to their current health - the damage desired.

    No, players are their own entity type. So Player player = e.getPlayer();

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

    JellyYods

    Well I have learned to make an ItemStack and someone is doing it they way they are doing it now. Someone came along and they gave me a code and said what each little line does. No I know that when you do

    ItemStack sword = new ItemStack(Material.DIAMOND_SWORD);

    They just kinda told me how to do which I don understand I know basic Java, but I dont understand craftbukkit that well

    I like it where someone gives me the code and tells me what is doing so I can remember for future references.

    And would this be a EntityDamageByEntity would look like

    Code:java
    1. @EventHandler
    2. public void AnchorListener(EntityDamageByEntityEvent e) {
    3. if(e.getEntity() instanceof Player && e.getDamager() instanceof Player) {
    4. Player victim = (Player)e.getEntity();
    5. Player damager = (Player)e.getDamager();
    6.  


    is that would it should look like

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

    Plo124

    JellyYods
    Yes, but you also need to check if the 'victim' is the Anchor class.

    Also, please dont use flaming, or excessive language,
     
  14. Offline

    JellyYods

    Sorry about my language now to cancel the knockback I just write public knockback return false;

    Code:java
    1. @EventHandler
    2. public void ReaperListener(EntityDamageByEntityEvent e) {
    3. if(e.getEntity() instanceof Player && e.getDamager() instanceof Player) {
    4. Player victim = (Player)e.equals(Anchor);
    5. Player damager = (Player)e.getDamager();
    6. victim.set
    7.  
    8. }
    9. }



    I get an arror on e.equals...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  15. Code:
    Player victim = (Player)e.equals(Anchor);
    w...

    Do you have any sort of system to select kits?
    Do you understand how variables work in Java (or really in general)?
    Do you understand Java?
     
    alzdoesmc and Wingzzz like this.
  16. To cancel the knockback you cancel the event and gives
    the victim the damage.
     
  17. Offline

    JellyYods

    Little about array lists loops and strings

    Would you like me to post the whole class

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  18. I don't think that would help. I do think that you should get a better understanding of Java before trying to work with the Bukkit API or you're not going to have a very good time.
     
  19. Offline

    JellyYods

    What should I learn then to get this code
     
  20. JellyYods Learn basic java. I'd suggest watching through thenewbostons tutorials on the matter.
     
  21. No offence, but you don't know enough Java in order to judge what qualifies as basic Java. :) I recommend reading ass opposed to video tutorials as has been suggested above - preferably a good Java book (there are plenty about) or, failing that, an online text-based tutorial (again, there are plenty)
     
  22. Code:java
    1. public void getHit(EntityDamageByEntityEvent e){
    2. if(!(e.getEntity() instanceof Player) return;
    3. if(!(e.getDamager() instanceof Player) return;
    4. //do an if check to see if theyre the anchor kit
    5. Player p = e.getEntity() // may have to cast, I'm just writing this here.
    6. e.setCancelled(true);
    7. p.damage(amount of damage);
    8. }
    9.  


    I probably shouldnt have told you this straight up, but we all need a starting point.
     
  23. Problem with us feeding you code is that even if we explain what the code does- you won't understand what it does in terms of the Java programming language. So say what tommyhoogstra did where he sent code and even made a few comments, all you'll understand is that it will do some magic and get it working. None of us here are trying to discourage you from learning this and we all want to help you. Although as it stands the majority of us have come to the conclusion that you're lacking in basic Java knowledge.

    I recommend you focus on learning a bit more Java and then revisiting the problem, and once you do- post another thread with your new found knowledge and any issues you might have. I say this because I'd like you to be able to understand the code and have fun making plugins. In order for us to help you, we would like a little work on your Java understandings (so that we don't have to explain Java in tandem with the use of Bukkit API). This will keep us from having to say "check it's instance with instanceof- which will check if the object on the left side of the statement is an instance of the class on the right side of the statment" and now that we've explained (poorly but this is an example) that, we would proceed to explain the Bukkit aspect. This is basically us teaching you Java at the same time as teaching you/helping you learn the Bukkit API. This isn't a problem for some of us, but it will impede your ability to understand what we're teaching you.

    Learn some Java and apply it to your plugins. If you need something in your plugin you don't understand, learn it and then revisit your plugin and apply it. Plugins are great for leaning Java- it's how I learnt. It provides an easy environment to see your code come alive and actually do something rather than just printing "Hello World!" in 18 different ways (exaggeration). That being said, don't get ahead of yourself and take things slow. When posting threads please ensure that you understand what you use in it. If you're curious about code other people use or about practical uses of things in a Bukkit plugin (like say you looked into what maps are and were wondering about some implementations of it inside of a plugin) then people would definitely help provide examples.

    Good luck, and happy programming- and err- coffee downing..
     
    Garris0n and tommyhoogstra like this.
  24. Offline

    JellyYods

    Thank you all for the help and the Boston is helping
     
    Wingzzz likes this.
Thread Status:
Not open for further replies.

Share This Page