Modifying Iron Swords Damage?

Discussion in 'Plugin Development' started by camakeson, Apr 6, 2013.

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

    camakeson

    Hi!
    I know I have been asking a lot of questions but could you help me with this? So I am simply trying to make a 1 hit kill iron sword. So I tried and failed miserably (Like all the other times....)
    I used the damage event but it didn't work. Could someone show me what I need to do? Thanks!
     
  2. Offline

    CubixCoders

    EntityDamageByEntityEvent if event.getDamager instanceof Player && ((Player)event.getDamager()).getItemInHand().getType() == Material.IRON_SWORD
    event.setDamage(20);

    So its the EntityDamageByEntityEvent, it checks if the damager is a player, and the held item is an iron sword, then sets the damage to 20
     
    camakeson and justcool393 like this.
  3. Offline

    camakeson

    CubixCoders Thanks for the help! I know this sounds REALLY pathetic but could you put it in the code box the format is messed up. Sorry!
     
  4. Offline

    justcool393

    Code:java
    1.  
    2. @EventHandler
    3. public void onDamageByEntity(EntityDamageByEntityEvent) {
    4. if (event.getDamager() instanceof Player && ((Player)event.getDamager()).getItemInHand().getType() == Material.IRON_SWORD) {
    5. event.setDamage(20);
    6. }
    7.  

    Fixed up the syntax a bit :)
     
    camakeson likes this.
  5. Offline

    camakeson

    justcool393 Hey... um the code is coming out with warnings... Heh heh. *facepalm* Could you tell me how to fix it please. Thank you!
     
  6. Offline

    justcool393

    What warnings are you getting?
     
  7. Offline

    camakeson

    Justcool 393 uh on the public class line it says "Syntax error, insert "}" to complete ClassBody (I dont get that...)
    Code:
    public class Knife extends JavaPlugin{
    and
    "Syntax error on token "EntityDamageByEntityEvent", VariableDeclaratorld expected after this token.
    Code:
    public void onDamageByEntity(EntityDamageByEntityEvent) {
    Thank you for being patient with me. I think I should do some more tutorials before attempting plugins...
     
  8. Offline

    ZeusAllMighty11

    You will get an NPE if the player is using their fist. Check if their item in hand isn't null

    Also, do 'EntityDamageByEntityEvent e'
     
    camakeson and justcool393 like this.
  9. Offline

    justcool393

    Try changing
    Code:java
    1. public void onDamageByEntity(EntityDamageByEntityEvent) {
    to
    Code:java
    1. public void onDamageByEntity(EntityDamageByEntityEvent event) {
     
    camakeson likes this.
  10. Offline

    camakeson

    justcool393 Wow it worked! Thank you for being patient with me. I appreciate it!
     
  11. Offline

    justcool393

    Glad to see it worked. :D
     
  12. Offline

    CubixCoders

    Sorry, i wasn't writing in code form to help you learn
     
Thread Status:
Not open for further replies.

Share This Page