|
| 1 | +/* |
| 2 | + * This file is part of ToolStats. |
| 3 | + * |
| 4 | + * ToolStats is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * ToolStats is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with ToolStats. If not, see <https://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | + |
| 18 | +package lol.hyper.toolstats.tools; |
| 19 | + |
| 20 | +import org.bukkit.Material; |
| 21 | + |
| 22 | +import java.util.Arrays; |
| 23 | +import java.util.Locale; |
| 24 | + |
| 25 | +public class ItemChecker { |
| 26 | + |
| 27 | + private static final String[] validItems = { "pickaxe", "sword", "shovel", "axe", "hoe", "bow", "helmet", "chestplate", "leggings", "boots", "fishing" }; |
| 28 | + private static final String[] validArmor = { "helmet", "chestplate", "leggings", "boots" }; |
| 29 | + private static final String[] validMelee = {"sword", "trident", "axe"}; |
| 30 | + private static final String[] validMine = { "pickaxe", "axe", "hoe", "shovel", "shear" }; |
| 31 | + |
| 32 | + /** |
| 33 | + * Check if item is an armor piece. |
| 34 | + * |
| 35 | + * @param itemType The item type, not name. |
| 36 | + * @return If the item is an armor piece. |
| 37 | + */ |
| 38 | + public static boolean isArmor(Material itemType) { |
| 39 | + return Arrays.stream(validArmor).anyMatch(type -> itemType.toString().toLowerCase(Locale.ROOT).contains(type)); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * Check if item is a tool or armor piece we want to track. |
| 44 | + * |
| 45 | + * @param itemType The item type, not name. |
| 46 | + * @return If the item something we want to track. |
| 47 | + */ |
| 48 | + public static boolean isValidItem(Material itemType) { |
| 49 | + return Arrays.stream(validItems).anyMatch(type -> itemType.toString().toLowerCase(Locale.ROOT).contains(type)); |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * Check if item is a melee weapon. |
| 54 | + * |
| 55 | + * @param itemType The item type, not name. |
| 56 | + * @return If the item is a melee weapon. |
| 57 | + */ |
| 58 | + public static boolean isMeleeWeapon(Material itemType) { |
| 59 | + return Arrays.stream(validMelee).anyMatch(type -> itemType.toString().toLowerCase(Locale.ROOT).contains(type)); |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * Check if item is a mining tool. |
| 64 | + * |
| 65 | + * @param itemType The item type, not name. |
| 66 | + * @return If the item is a mining tool. |
| 67 | + */ |
| 68 | + public static boolean isMineTool(Material itemType) { |
| 69 | + return Arrays.stream(validMine).anyMatch(type -> itemType.toString().toLowerCase(Locale.ROOT).contains(type)); |
| 70 | + } |
| 71 | +} |
0 commit comments