9
0
mirror of https://github.com/Auxilor/EcoSkills.git synced 2026-01-02 22:02:19 +00:00

Began adding modifiers

This commit is contained in:
Auxilor
2021-08-21 09:52:55 +01:00
parent 27d6ae8c9a
commit b0bfd8b2d3
3 changed files with 135 additions and 7 deletions

View File

@@ -0,0 +1,98 @@
package com.willfp.ecoskills.api;
import com.willfp.eco.util.NamespacedKeyUtils;
import com.willfp.ecoskills.stats.Stat;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.EquipmentSlot;
import org.jetbrains.annotations.NotNull;
public class StatModifier {
/**
* The key.
*/
private final NamespacedKey key;
/**
* The key.
*/
private final NamespacedKey slotKey;
/**
* The stat.
*/
private final Stat stat;
/**
* The amount.
*/
private final int amount;
/**
* The slots.
*/
private final EquipmentSlot[] slots;
/**
* Create a stat modifier.
*
* @param key The key.
* @param stat The stat.
* @param amount The amount.
* @param slot The slots. (Empty is the same as all).
*/
public StatModifier(@NotNull final NamespacedKey key,
@NotNull final Stat stat,
final int amount,
@NotNull final EquipmentSlot... slot) {
this.key = key;
this.slotKey = NamespacedKeyUtils.create(key.getNamespace(), key.getKey() + "_slot");
this.stat = stat;
this.amount = amount;
this.slots = slot;
}
/**
* Get the key.
*
* @return The key.
*/
public NamespacedKey getKey() {
return key;
}
/**
* Get the slot key.
*
* @return The key.
*/
public NamespacedKey getSlotKey() {
return slotKey;
}
/**
* Get the stat.
*
* @return The stat.
*/
public Stat getStat() {
return stat;
}
/**
* Get the amount.
*
* @return The amount.
*/
public int getAmount() {
return amount;
}
/**
* Get the slots.
*
* @return The slots.
*/
public EquipmentSlot[] getSlots() {
return slots;
}
}

View File

@@ -0,0 +1,32 @@
package com.willfp.ecoskills
import com.willfp.eco.util.NamespacedKeyUtils
import com.willfp.ecoskills.api.StatModifier
import com.willfp.ecoskills.effects.Effect
import com.willfp.ecoskills.skills.Skill
import com.willfp.ecoskills.stats.Stat
import org.bukkit.NamespacedKey
import org.bukkit.entity.Player
import org.bukkit.inventory.EquipmentSlot
import org.bukkit.inventory.ItemStack
import org.bukkit.persistence.PersistentDataAdapterContext
import org.bukkit.persistence.PersistentDataContainer
import org.bukkit.persistence.PersistentDataHolder
import org.bukkit.persistence.PersistentDataType
private val modifierKey: NamespacedKey = NamespacedKeyUtils.create("ecoskills", "modifiers")
fun ItemStack.addStatModifier(modifier: StatModifier) {
val meta = this.itemMeta ?: return
val container = meta.persistentDataContainer
val context = container.adapterContext
val modifiers = container.getOrDefault(modifierKey, PersistentDataType.TAG_CONTAINER, context.newPersistentDataContainer())
modifiers.remove(modifier.key)
modifiers.remove(modifier.slotKey)
modifiers.set(modifier.key, PersistentDataType.INTEGER, modifier.amount)
modifiers.set(modifier.slotKey, PersistentDataType.STRING, modifier.slots.map { slot -> slot.name }.toTypedArray().joinToString { "," })
}

View File

@@ -35,13 +35,11 @@ class SkillFarming : Skill(
val type = event.block.type
val player = event.player
if (event.block.blockData !is Ageable) {
return
}
val data = event.block.blockData as Ageable
if (data.age < data.maximumAge) {
return
if (event.block.blockData is Ageable) {
val data = event.block.blockData as Ageable
if (data.age < data.maximumAge) {
return
}
}
val toGive = rewards[type] ?: return