Added isUnarmed Method

Checks if the player is not holding a tool, as opposed to checking if
the player is holding air. This means that attacking with something such
as a dirt block would count as unarmed.
This commit is contained in:
mjkaufer 2014-12-29 00:12:46 -05:00
parent af7ff3df58
commit e19a898aa6
3 changed files with 14 additions and 2 deletions

View File

@ -19,6 +19,7 @@ import com.gmail.nossr50.datatypes.skills.ToolType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.ItemUtils;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.player.UserManager;
@ -48,7 +49,7 @@ public class UnarmedManager extends SkillManager {
public boolean canDeflect() {
Player player = getPlayer();
return player.getItemInHand().getType() == Material.AIR && Permissions.secondaryAbilityEnabled(getPlayer(), SecondaryAbility.DEFLECT);
return ItemUtils.isUnarmed(player.getItemInHand()) && Permissions.secondaryAbilityEnabled(getPlayer(), SecondaryAbility.DEFLECT);
}
public boolean canUseBlockCracker() {

View File

@ -146,6 +146,16 @@ public final class ItemUtils {
}
}
/**
* Checks if the item counts as unarmed.
*
* @param item Item to check
* @return true if the item counts as unarmed, false otherwise
*/
public static boolean isUnarmed(ItemStack item) {
return !isMinecraftTool(item);
}
/**
* Checks if the item is a helmet.
*

View File

@ -41,6 +41,7 @@ import com.gmail.nossr50.skills.axes.AxesManager;
import com.gmail.nossr50.skills.swords.Swords;
import com.gmail.nossr50.skills.swords.SwordsManager;
import com.gmail.nossr50.skills.taming.TamingManager;
import com.gmail.nossr50.skills.unarmed.Unarmed;
import com.gmail.nossr50.skills.unarmed.UnarmedManager;
import com.gmail.nossr50.util.EventUtils;
import com.gmail.nossr50.util.ItemUtils;
@ -251,7 +252,7 @@ public final class CombatUtils {
processAxeCombat(target, player, event);
}
}
else if (heldItem.getType() == Material.AIR) {
else if (ItemUtils.isUnarmed(heldItem)) {
if (!SkillType.UNARMED.shouldProcess(target)) {
return;
}