diff --git a/src/main/java/codes/biscuit/skyblockaddons/features/cooldowns/CooldownManager.java b/src/main/java/codes/biscuit/skyblockaddons/features/cooldowns/CooldownManager.java index cd40a643d2..76ccc7a9dd 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/features/cooldowns/CooldownManager.java +++ b/src/main/java/codes/biscuit/skyblockaddons/features/cooldowns/CooldownManager.java @@ -46,6 +46,24 @@ public static void put(ItemStack item) { } } + /** + * Put an item on cooldown by getting the index of which cooldown value from its lore. + * + * @param item Item to put on cooldown + * @param index Index of the cooldown + */ + public static void put(ItemStack item, int index) { + if(item == null || !item.hasDisplayName()) { + return; + } + + int cooldown = getLoreCooldown(item, index); + if(cooldown > 0) { + // cooldown is returned in seconds and required in milliseconds + put(item.getDisplayName(), cooldown * 1000); + } + } + /** * Put an item on cooldown with provided cooldown, for items that do not show their cooldown @@ -151,22 +169,49 @@ public static double getRemainingCooldownPercent(String itemName) { * @see #ALTERNATE_COOLDOWN_PATTERN */ private static int getLoreCooldown(ItemStack item) { + return getLoreCooldown(item, 0); + } + + /** + * Read multiple cooldown values of an item from it's lore. + * And, gets the selected value. + * This requires that the lore shows the cooldown either like {@code X Second Cooldown} or + * {@code Cooldown: Xs}. Cooldown is returned in seconds. + * + * @param item Item to read cooldown from + * @param index The index of the cooldown + * @return Read cooldown in seconds or {@code -1} if no cooldown was found + * @see #ITEM_COOLDOWN_PATTERN + * @see #ALTERNATE_COOLDOWN_PATTERN + */ + private static int getLoreCooldown(ItemStack item, int index) { + int result = -1; for (String loreLine : item.getTooltip(Minecraft.getMinecraft().thePlayer, false)) { Matcher matcher = ITEM_COOLDOWN_PATTERN.matcher(loreLine); if (matcher.matches()) { try { - return Integer.parseInt(matcher.group(1)); + result = Integer.parseInt(matcher.group(1)); + + if (index == 0) + break; + else + index--; } catch (NumberFormatException ignored) { } } else { matcher = ALTERNATE_COOLDOWN_PATTERN.matcher(loreLine); if (matcher.matches()) { try { - return Integer.parseInt(matcher.group(1)); + result = Integer.parseInt(matcher.group(1)); + + if (index == 0) + break; + else + index--; } catch (NumberFormatException ignored) { } } } } - return -1; + return result; } } diff --git a/src/main/java/codes/biscuit/skyblockaddons/listeners/PlayerListener.java b/src/main/java/codes/biscuit/skyblockaddons/listeners/PlayerListener.java index 4c0a6b9faf..0b58641ae0 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/listeners/PlayerListener.java +++ b/src/main/java/codes/biscuit/skyblockaddons/listeners/PlayerListener.java @@ -352,6 +352,14 @@ public void onInteract(PlayerInteractEvent e) { ItemStack heldItem = e.entityPlayer.getHeldItem(); if (main.getUtils().isOnSkyblock() && heldItem != null) { + // Show cooldown on dungeon orb when the player uses it in dungeons + if (main.getConfigValues().isEnabled(Feature.SHOW_ITEM_COOLDOWNS) + && main.getUtils().isInDungeon() + && (e.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK || e.action == PlayerInteractEvent.Action.RIGHT_CLICK_AIR) + && heldItem.getItem().equals(Items.skull)) { + main.getDungeonUtils().useOrb(heldItem); + } + // Change the GUI background color when a backpack is opened to match the backpack's color. if (heldItem.getItem() == Items.skull) { Backpack backpack = BackpackManager.getFromItem(heldItem); diff --git a/src/main/java/codes/biscuit/skyblockaddons/utils/DungeonUtils.java b/src/main/java/codes/biscuit/skyblockaddons/utils/DungeonUtils.java index bf41764481..074cbec100 100644 --- a/src/main/java/codes/biscuit/skyblockaddons/utils/DungeonUtils.java +++ b/src/main/java/codes/biscuit/skyblockaddons/utils/DungeonUtils.java @@ -4,8 +4,11 @@ import codes.biscuit.skyblockaddons.core.DungeonMilestone; import codes.biscuit.skyblockaddons.core.DungeonPlayer; import codes.biscuit.skyblockaddons.core.EssenceType; +import codes.biscuit.skyblockaddons.features.cooldowns.CooldownManager; import lombok.Getter; import lombok.Setter; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import java.util.EnumMap; import java.util.HashMap; @@ -113,4 +116,23 @@ public void parseBonusEssence(String message) { collectedEssences.put(essenceType, collectedEssences.getOrDefault(essenceType, 0) + 1); } } + + /** + * Check if the given item is a dungeon orb. And, notifies the player that it got used. + * It applies the cooldown of the second ability. Since the main ability is showed in the experience bar. + * + * @param orb The dungeon orb item + */ + public void useOrb(ItemStack orb) { + NBTTagCompound extraAttributes = orb.getTagCompound().getCompoundTag("ExtraAttributes"); + if (extraAttributes == null) + return; + String id = extraAttributes.getString("id"); + if (id == null) + return; + if (!id.equals("DUNGEON_STONE")) + return; + + CooldownManager.put(orb, 1); + } }