Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private boolean isWeapon(final Material material) {
- switch (material) {
- case WOOD_SWORD:
- case STONE_SWORD:
- case GOLD_SWORD:
- case IRON_SWORD:
- case DIAMOND_SWORD:
- case BOW:
- case ARROW:
- case FLINT_AND_STEEL:
- case FISHING_ROD:
- case WOOD_HOE:
- case STONE_HOE:
- case GOLD_HOE:
- case IRON_HOE:
- case DIAMOND_HOE:
- case WOOD_SPADE:
- case STONE_SPADE:
- case GOLD_SPADE:
- case IRON_SPADE:
- case DIAMOND_SPADE:
- case WOOD_PICKAXE:
- case STONE_PICKAXE:
- case GOLD_PICKAXE:
- case IRON_PICKAXE:
- case DIAMOND_PICKAXE:
- case WOOD_AXE:
- case STONE_AXE:
- case GOLD_AXE:
- case IRON_AXE:
- case DIAMOND_AXE:
- return true;
- default:
- return false;
- }
- }
- private int getArmorWorth(final ItemStack item) {
- final int[] armorWorth = {0};
- if (!this.isArmor(item.getType()))
- return 0;
- switch (item.getType()) {
- case DIAMOND_HELMET:
- armorWorth[0] += 363;
- armorWorth[0] -= item.getDurability();
- case DIAMOND_CHESTPLATE:
- armorWorth[0] += 528;
- armorWorth[0] -= item.getDurability();
- case DIAMOND_LEGGINGS:
- armorWorth[0] += 495;
- armorWorth[0] -= item.getDurability();
- case DIAMOND_BOOTS:
- armorWorth[0] += 429;
- armorWorth[0] -= item.getDurability();
- armorWorth[0] += 500;
- break;
- case IRON_HELMET:
- armorWorth[0] += 165;
- armorWorth[0] -= item.getDurability();
- case IRON_CHESTPLATE:
- armorWorth[0] += 240;
- armorWorth[0] -= item.getDurability();
- case IRON_LEGGINGS:
- armorWorth[0] += 225;
- armorWorth[0] -= item.getDurability();
- case IRON_BOOTS:
- armorWorth[0] += 195;
- armorWorth[0] -= item.getDurability();
- armorWorth[0] += 400;
- break;
- case CHAINMAIL_HELMET:
- armorWorth[0] += 165;
- armorWorth[0] -= item.getDurability();
- case CHAINMAIL_CHESTPLATE:
- armorWorth[0] += 240;
- armorWorth[0] -= item.getDurability();
- case CHAINMAIL_LEGGINGS:
- armorWorth[0] += 225;
- armorWorth[0] -= item.getDurability();
- case CHAINMAIL_BOOTS:
- armorWorth[0] += 195;
- armorWorth[0] -= item.getDurability();
- armorWorth[0] += 300;
- break;
- case GOLD_HELMET:
- armorWorth[0] += 77;
- armorWorth[0] -= item.getDurability();
- case GOLD_CHESTPLATE:
- armorWorth[0] += 112;
- armorWorth[0] -= item.getDurability();
- case GOLD_LEGGINGS:
- armorWorth[0] += 105;
- armorWorth[0] -= item.getDurability();
- case GOLD_BOOTS:
- armorWorth[0] += 91;
- armorWorth[0] -= item.getDurability();
- armorWorth[0] += 200;
- break;
- case LEATHER_HELMET:
- armorWorth[0] += 55;
- armorWorth[0] -= item.getDurability();
- case LEATHER_CHESTPLATE:
- armorWorth[0] += 80;
- armorWorth[0] -= item.getDurability();
- case LEATHER_LEGGINGS:
- armorWorth[0] += 75;
- armorWorth[0] -= item.getDurability();
- case LEATHER_BOOTS:
- armorWorth[0] += 65;
- armorWorth[0] -= item.getDurability();
- armorWorth[0] += 100;
- break;
- default:
- break;
- }
- final Map<Enchantment, Integer> enchantments = item.getItemMeta().getEnchants();
- final Set<Enchantment> enchantmentKeys = enchantments.keySet();
- enchantmentKeys.forEach(enchantment -> {
- if (enchantment.equals(Enchantment.DURABILITY)) {
- final int enchLevel = enchantments.get(Enchantment.DURABILITY);
- armorWorth[0] += enchLevel * 5;
- } else if (enchantment.equals(Enchantment.PROTECTION_ENVIRONMENTAL)) {
- final int enchLevel = enchantments.get(Enchantment.PROTECTION_ENVIRONMENTAL);
- armorWorth[0] += enchLevel * 5 * 5;
- } else if (enchantment.equals(Enchantment.PROTECTION_FIRE)) {
- final int enchLevel = enchantments.get(Enchantment.PROTECTION_FIRE);
- armorWorth[0] += enchLevel * 3 * 5;
- } else if (enchantment.equals(Enchantment.PROTECTION_PROJECTILE)) {
- final int enchLevel = enchantments.get(Enchantment.PROTECTION_PROJECTILE);
- armorWorth[0] += enchLevel * 4 * 5;
- } else if (enchantment.equals(Enchantment.PROTECTION_EXPLOSIONS)) {
- final int enchLevel = enchantments.get(Enchantment.PROTECTION_EXPLOSIONS);
- armorWorth[0] += enchLevel * 2 * 5;
- } else if (enchantment.equals(Enchantment.THORNS)) {
- final int enchLevel = enchantments.get(Enchantment.THORNS);
- armorWorth[0] += enchLevel * 7 * 5;
- } else if (enchantment.equals(Enchantment.OXYGEN)) {
- final int enchLevel = enchantments.get(Enchantment.OXYGEN);
- armorWorth[0] += enchLevel * 5;
- } else if (enchantment.equals(Enchantment.WATER_WORKER)) {
- final int enchLevel = enchantments.get(Enchantment.WATER_WORKER);
- armorWorth[0] += enchLevel * 5;
- } else if (enchantment.equals(Enchantment.PROTECTION_FALL)) {
- final int enchLevel = enchantments.get(Enchantment.PROTECTION_FALL);
- armorWorth[0] += enchLevel * 3 * 5;
- } else if (enchantment.equals(Enchantment.DEPTH_STRIDER)) {
- final int enchLevel = enchantments.get(Enchantment.DEPTH_STRIDER);
- armorWorth[0] += enchLevel * 2 * 5;
- }
- });
- return armorWorth[0];
- }
- public void autoEquip(final Player player) {
- final PlayerInventory playerInventory = player.getInventory();
- final ItemStack[] inventoryContents = playerInventory.getContents();
- for (int i = 0; i < inventoryContents.length; i++) {
- final ItemStack item = inventoryContents[i];
- if (item == null)
- continue;
- final ItemStack helmet = playerInventory.getHelmet(),
- chestplate = playerInventory.getChestplate(),
- leggings = playerInventory.getLeggings(),
- boots = playerInventory.getBoots();
- if (!this.isArmor(item.getType()))
- continue;
- switch (item.getType()) {
- case DIAMOND_HELMET:
- case IRON_HELMET:
- case CHAINMAIL_HELMET:
- case GOLD_HELMET:
- case LEATHER_HELMET:
- if (this.getArmorWorth(item) < (helmet == null ? 0 : this.getArmorWorth(helmet)))
- break;
- inventoryContents[i] = helmet;
- playerInventory.setHelmet(item);
- break;
- case DIAMOND_CHESTPLATE:
- case IRON_CHESTPLATE:
- case CHAINMAIL_CHESTPLATE:
- case GOLD_CHESTPLATE:
- case LEATHER_CHESTPLATE:
- if (this.getArmorWorth(item) < (chestplate == null ? 0 : this.getArmorWorth(chestplate)))
- break;
- inventoryContents[i] = chestplate;
- playerInventory.setChestplate(item);
- break;
- case DIAMOND_LEGGINGS:
- case IRON_LEGGINGS:
- case CHAINMAIL_LEGGINGS:
- case GOLD_LEGGINGS:
- case LEATHER_LEGGINGS:
- if (this.getArmorWorth(item) < (leggings == null ? 0 : this.getArmorWorth(leggings)))
- break;
- inventoryContents[i] = leggings;
- playerInventory.setLeggings(item);
- break;
- case DIAMOND_BOOTS:
- case IRON_BOOTS:
- case CHAINMAIL_BOOTS:
- case GOLD_BOOTS:
- case LEATHER_BOOTS:
- if (this.getArmorWorth(item) < (boots == null ? 0 : this.getArmorWorth(boots)))
- break;
- inventoryContents[i] = boots;
- playerInventory.setBoots(item);
- break;
- }
- }
- playerInventory.setContents(inventoryContents);
- player.updateInventory();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement