Getting how much damage item in hand will do

Discussion in 'Plugin Development' started by kameronn, Oct 2, 2016.

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

    kameronn

    I'm trying to look for an efficient way to do this. I dont want to check for all items that dont do half a heart and do it like that, is there any easy way to check?
     
  2. Offline

    Zombie_Striker

    @kameronn
    Create a Map of Materials and Integers. The materials will be the materials that deal extra damage (e.g. Wooden swords, Iron Axes, Pickaxes), and the Integer is the amount of damage for that item.Since all items besides tools only do half a heart of damage, all you need to do is check if the item is not in the map.

    By doing this, you can use the following method to get the amount of damage an item does:
    Code:
    public int getDamage(Material m){
     return HASHMAP#contains(m) ? HASHMAP#get(m) : 1;
    }
     
Thread Status:
Not open for further replies.

Share This Page