Cooldown references for rpg pots

This commit is contained in:
Indyuce 2022-07-07 15:29:35 +02:00
parent 393821234e
commit 9b40f9e4b7
3 changed files with 27 additions and 8 deletions

View File

@ -131,6 +131,7 @@ public class ItemStats {
SOULBOUND_LEVEL = new SoulboundLevel(), SOULBOUND_LEVEL = new SoulboundLevel(),
// AUTO_SOULBIND = new BooleanStat("AUTO_SOULBIND", VersionMaterial.ENDER_EYE.toMaterial(), "Auto-Soulbind", new String[]{"Automatically soulbinds this item to", "a player when he acquires it."}, new String[]{"!consumable", "all"}), // AUTO_SOULBIND = new BooleanStat("AUTO_SOULBIND", VersionMaterial.ENDER_EYE.toMaterial(), "Auto-Soulbind", new String[]{"Automatically soulbinds this item to", "a player when he acquires it."}, new String[]{"!consumable", "all"}),
ITEM_COOLDOWN = new DoubleStat("ITEM_COOLDOWN", Material.COOKED_CHICKEN, "Item Cooldown", new String[]{"This cooldown applies for consumables", "as well as for item commands."}, new String[]{"!armor", "!gem_stone", "!block", "all"}), ITEM_COOLDOWN = new DoubleStat("ITEM_COOLDOWN", Material.COOKED_CHICKEN, "Item Cooldown", new String[]{"This cooldown applies for consumables", "as well as for item commands."}, new String[]{"!armor", "!gem_stone", "!block", "all"}),
COOLDOWN_REFERENCE = new StringStat("COOLDOWN_REFERENCE", Material.CHICKEN, "Cooldown Reference", new String[]{"Two items with the same cooldown reference", "will share their cooldowns. This is useful", "for health or mana pots for example."}, new String[]{"!armor", "!gem_stone", "!block", "all"}),
VANILLA_EATING_ANIMATION = new VanillaEatingAnimation(), VANILLA_EATING_ANIMATION = new VanillaEatingAnimation(),
GEM_COLOR = new GemColor(), GEM_COLOR = new GemColor(),
GEM_UPGRADE_SCALING = new GemUpgradeScaling(), GEM_UPGRADE_SCALING = new GemUpgradeScaling(),

View File

@ -366,14 +366,26 @@ public class PlayerData {
mmoData.getCooldownMap().applyCooldown(type.name(), value); mmoData.getCooldownMap().applyCooldown(type.name(), value);
} }
/**
* @deprecated Deprecated due to cooldown references
*/
@Deprecated
public boolean isOnCooldown(ItemReference ref) { public boolean isOnCooldown(ItemReference ref) {
return mmoData.getCooldownMap().isOnCooldown(ref); return mmoData.getCooldownMap().isOnCooldown(ref);
} }
/**
* @deprecated Deprecated due to cooldown references
*/
@Deprecated
public void applyItemCooldown(ItemReference ref, double value) { public void applyItemCooldown(ItemReference ref, double value) {
mmoData.getCooldownMap().applyCooldown(ref, value); mmoData.getCooldownMap().applyCooldown(ref, value);
} }
/**
* @deprecated Deprecated due to cooldown references
*/
@Deprecated
public double getItemCooldown(ItemReference ref) { public double getItemCooldown(ItemReference ref) {
return mmoData.getCooldownMap().getInfo(ref).getRemaining() / 1000d; return mmoData.getCooldownMap().getInfo(ref).getRemaining() / 1000d;
} }

View File

@ -8,7 +8,6 @@ import io.lumine.mythic.lib.api.player.EquipmentSlot;
import io.lumine.mythic.lib.comp.target.InteractionType; import io.lumine.mythic.lib.comp.target.InteractionType;
import io.lumine.mythic.lib.damage.MeleeAttackMetadata; import io.lumine.mythic.lib.damage.MeleeAttackMetadata;
import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.MMOUtils;
import net.Indyuce.mmoitems.api.ItemAttackMetadata; import net.Indyuce.mmoitems.api.ItemAttackMetadata;
import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.Type;
import net.Indyuce.mmoitems.api.TypeSet; import net.Indyuce.mmoitems.api.TypeSet;
@ -18,7 +17,7 @@ import net.Indyuce.mmoitems.api.interaction.weapon.Gauntlet;
import net.Indyuce.mmoitems.api.interaction.weapon.Weapon; import net.Indyuce.mmoitems.api.interaction.weapon.Weapon;
import net.Indyuce.mmoitems.api.interaction.weapon.untargeted.Staff; import net.Indyuce.mmoitems.api.interaction.weapon.untargeted.Staff;
import net.Indyuce.mmoitems.api.interaction.weapon.untargeted.UntargetedWeapon; import net.Indyuce.mmoitems.api.interaction.weapon.untargeted.UntargetedWeapon;
import net.Indyuce.mmoitems.api.interaction.weapon.untargeted.UntargetedWeaponType; import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem;
import net.Indyuce.mmoitems.api.player.PlayerData; import net.Indyuce.mmoitems.api.player.PlayerData;
import net.Indyuce.mmoitems.api.util.message.Message; import net.Indyuce.mmoitems.api.util.message.Message;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -74,9 +73,10 @@ public class ItemUse implements Listener {
// Commands & consummables // Commands & consummables
if (event.getAction().name().contains("RIGHT_CLICK")) { if (event.getAction().name().contains("RIGHT_CLICK")) {
if (useItem.getPlayerData().isOnCooldown(useItem.getMMOItem())) { final String cooldownReference = getCooldownReference(useItem.getMMOItem());
if (useItem.getPlayerData().getMMOPlayerData().getCooldownMap().isOnCooldown(cooldownReference)) {
Message.ITEM_ON_COOLDOWN Message.ITEM_ON_COOLDOWN
.format(ChatColor.RED, "#left#", DIGIT.format(useItem.getPlayerData().getItemCooldown(useItem.getMMOItem()))) .format(ChatColor.RED, "#left#", DIGIT.format(useItem.getPlayerData().getMMOPlayerData().getCooldownMap().getCooldown(cooldownReference)))
.send(player); .send(player);
event.setUseItemInHand(Event.Result.DENY); event.setUseItemInHand(Event.Result.DENY);
return; return;
@ -92,7 +92,7 @@ public class ItemUse implements Listener {
event.getItem().setAmount(event.getItem().getAmount() - 1); event.getItem().setAmount(event.getItem().getAmount() - 1);
} }
useItem.getPlayerData().applyItemCooldown(useItem.getMMOItem(), useItem.getNBTItem().getStat("ITEM_COOLDOWN")); useItem.getPlayerData().getMMOPlayerData().getCooldownMap().applyCooldown(cooldownReference, useItem.getNBTItem().getStat("ITEM_COOLDOWN"));
useItem.executeCommands(); useItem.executeCommands();
} }
@ -104,6 +104,11 @@ public class ItemUse implements Listener {
} }
} }
private String getCooldownReference(VolatileMMOItem mmoitem) {
final String ref = mmoitem.getNBT().getString("MMOITEMS_COOLDOWN_REFERENCE");
return ref != null && !ref.isEmpty() ? ref : mmoitem.getCooldownPath();
}
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void meleeAttacks(PlayerAttackEvent event) { public void meleeAttacks(PlayerAttackEvent event) {
@ -322,9 +327,10 @@ public class ItemUse implements Listener {
if (useItem instanceof Consumable) { if (useItem instanceof Consumable) {
if (useItem.getPlayerData().isOnCooldown(useItem.getMMOItem())) { final String cooldownReference = getCooldownReference(useItem.getMMOItem());
if (useItem.getPlayerData().getMMOPlayerData().getCooldownMap().isOnCooldown(cooldownReference)) {
Message.ITEM_ON_COOLDOWN Message.ITEM_ON_COOLDOWN
.format(ChatColor.RED, "#left#", DIGIT.format(useItem.getPlayerData().getItemCooldown(useItem.getMMOItem()))) .format(ChatColor.RED, "#left#", DIGIT.format(useItem.getPlayerData().getMMOPlayerData().getCooldownMap().getCooldown(cooldownReference)))
.send(player); .send(player);
event.setCancelled(true); event.setCancelled(true);
return; return;
@ -342,7 +348,7 @@ public class ItemUse implements Listener {
if (result == Consumable.ConsumableConsumeResult.NOT_CONSUME) if (result == Consumable.ConsumableConsumeResult.NOT_CONSUME)
event.setCancelled(true); event.setCancelled(true);
useItem.getPlayerData().applyItemCooldown(useItem.getMMOItem(), useItem.getNBTItem().getStat("ITEM_COOLDOWN")); useItem.getPlayerData().getMMOPlayerData().getCooldownMap().applyCooldown(cooldownReference, useItem.getNBTItem().getStat("ITEM_COOLDOWN"));
useItem.executeCommands(); useItem.executeCommands();
} }
} }