Solved Double Damage? NEW PROBLEM

Discussion in 'Plugin Development' started by Bobfan, Nov 23, 2012.

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

    Bobfan

    I am having trouble to see if this event is working.
    Code:
    Player pR = (Player) event.getEntity();
            Player pA = (Player) ((EntityDamageByEntityEvent) event.getEntity()).getDamager();
           
            ItemStack iH = pA.getItemInHand();
    Code:
    if((pA instanceof Player) &&
                ((iH.getType() == Material.WOOD_SWORD) ||
                (iH.getType() == Material.STONE_SWORD) ||
                (iH.getType() == Material.IRON_SWORD) ||
                (iH.getType() == Material.GOLD_SWORD) ||
                (iH.getType() == Material.DIAMOND_SWORD)) &&
                (c.getStringList("Races.Human").contains(pA.getName()))) {//Human Attack
                    int random = new Random().nextInt(2) + 1;
                   
                    if(random == 2) {
                        pR.setHealth(pR.getHealth() - (event.getDamage() * 2);
                }//damage * 2
            }//attack
    What I'm trying to accomplish is if pA is a player, and the item in hand is a sword, than generate a number between 1-2. If the number is 2, than set the entity being attacked's health will take double damage. I don't think this is the best method, is there a better way of doing this?
     
  2. Offline

    Jogy34

    Why don't you just use an EntityDamageByEntityEvent and see if the damager is a player then if it is set the damage to double with event.setDamage(event.getDamage() * 2);
     
  3. Offline

    raGan.

    Sure is. There is no reaso to add 1 and decide between 1-2 while you can just decide between 0-1. Everything else seems fine to me. One more thing may be to have random generator as field in your listener class and don't create new one every time method is called.
     
  4. Offline

    Bobfan

    OOPS, FORGOT TO REGISTER EVENT!!!

    Well now everything has just flat out stopped working. I don't know why?

    edit edit edit edit edit: NO REALLY, I CAN'T FIGURE OUT WHY!
     
  5. Offline

    Skatedog27

    I have no idea. Is your plugin.yml valid? Maybe remove the Randoms? Check if the target player is instanceof Player?
     
Thread Status:
Not open for further replies.

Share This Page