Added price system
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
package com.willfp.eco.internal.price
|
||||
|
||||
import com.willfp.eco.core.price.Price
|
||||
import com.willfp.eco.core.price.PriceFactory
|
||||
import com.willfp.eco.core.price.impl.PriceEconomy
|
||||
|
||||
object PriceFactoryEconomy : PriceFactory {
|
||||
override fun getNames() = listOf(
|
||||
"coins",
|
||||
"$"
|
||||
)
|
||||
|
||||
override fun create(value: Double): Price = PriceEconomy(value)
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.willfp.eco.internal.price
|
||||
|
||||
import com.willfp.eco.core.price.Price
|
||||
import com.willfp.eco.core.price.PriceFactory
|
||||
import org.bukkit.entity.Player
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
object PriceFactoryXP : PriceFactory {
|
||||
override fun getNames() = listOf(
|
||||
"xp",
|
||||
"exp",
|
||||
"experience"
|
||||
)
|
||||
|
||||
override fun create(value: Double): Price = PriceXP(value.roundToInt())
|
||||
|
||||
private class PriceXP(
|
||||
private val xp: Int
|
||||
) : Price {
|
||||
override fun canAfford(player: Player) = player.totalExperience >= xp
|
||||
|
||||
override fun pay(player: Player) {
|
||||
player.totalExperience -= xp
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.willfp.eco.internal.price
|
||||
|
||||
import com.willfp.eco.core.price.Price
|
||||
import com.willfp.eco.core.price.PriceFactory
|
||||
import org.bukkit.entity.Player
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
object PriceFactoryXPLevels : PriceFactory {
|
||||
override fun getNames() = listOf(
|
||||
"levels",
|
||||
"xp levels",
|
||||
"exp levels",
|
||||
"l",
|
||||
"xpl",
|
||||
"expl"
|
||||
)
|
||||
|
||||
override fun create(value: Double): Price = PriceXPLevel(value.roundToInt())
|
||||
|
||||
private class PriceXPLevel(
|
||||
private val levels: Int
|
||||
) : Price {
|
||||
override fun canAfford(player: Player) = player.level >= levels
|
||||
|
||||
override fun pay(player: Player) {
|
||||
player.level -= levels
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import com.willfp.eco.core.integrations.mcmmo.McmmoManager
|
||||
import com.willfp.eco.core.integrations.placeholder.PlaceholderManager
|
||||
import com.willfp.eco.core.integrations.shop.ShopManager
|
||||
import com.willfp.eco.core.items.Items
|
||||
import com.willfp.eco.core.price.Prices
|
||||
import com.willfp.eco.internal.entities.EntityArgParserAdult
|
||||
import com.willfp.eco.internal.entities.EntityArgParserAttackDamage
|
||||
import com.willfp.eco.internal.entities.EntityArgParserAttackSpeed
|
||||
@@ -45,11 +46,14 @@ import com.willfp.eco.internal.items.ArgParserTexture
|
||||
import com.willfp.eco.internal.items.ArgParserUnbreakable
|
||||
import com.willfp.eco.internal.lookup.SegmentParserGroup
|
||||
import com.willfp.eco.internal.lookup.SegmentParserUseIfPresent
|
||||
import com.willfp.eco.internal.price.PriceFactoryEconomy
|
||||
import com.willfp.eco.internal.price.PriceFactoryXP
|
||||
import com.willfp.eco.internal.price.PriceFactoryXPLevels
|
||||
import com.willfp.eco.internal.spigot.arrows.ArrowDataListener
|
||||
import com.willfp.eco.internal.spigot.data.DataListener
|
||||
import com.willfp.eco.internal.spigot.data.DataYml
|
||||
import com.willfp.eco.internal.spigot.data.ProfileHandler
|
||||
import com.willfp.eco.internal.spigot.data.PlayerBlockListener
|
||||
import com.willfp.eco.internal.spigot.data.ProfileHandler
|
||||
import com.willfp.eco.internal.spigot.data.storage.ProfileSaver
|
||||
import com.willfp.eco.internal.spigot.display.PacketAutoRecipe
|
||||
import com.willfp.eco.internal.spigot.display.PacketChat
|
||||
@@ -161,6 +165,10 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
|
||||
Entities.registerArgParser(EntityArgParserSilent)
|
||||
Entities.registerArgParser(EntityArgParserEquipment)
|
||||
|
||||
Prices.registerPriceFactory(PriceFactoryEconomy)
|
||||
Prices.registerPriceFactory(PriceFactoryXPLevels)
|
||||
Prices.registerPriceFactory(PriceFactoryXP)
|
||||
|
||||
CraftingRecipeListener.registerListener(ComplexInComplex)
|
||||
CraftingRecipeListener.registerListener(ComplexInVanilla)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user