Skip to content

Commit 06eeaa7

Browse files
committed
feat: add Expensive Trades module to increase villager trade costs
1 parent be053da commit 06eeaa7

3 files changed

Lines changed: 63 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ The following modules are currently available:
3030
inventory management more challenging.
3131
- **Bad Air Caves**: Sometimes, poisonous gas will fill caves, causing damage to players.
3232
- **Baby Creatures**: Any LivingEntity can spawn as a baby, babies are faster and smaller than their adult counterparts.
33+
- **Expensive Trades**: Villager trades are more expensive, making it harder to obtain valuable items.
3334
- **More to come**: This plugin is a work in progress, with more modules planned for future releases.
3435

3536
## Configuration
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.sybsuper.sybsafetyfirst.modules
2+
3+
import kotlinx.serialization.Serializable
4+
import org.bukkit.event.EventHandler
5+
import org.bukkit.event.entity.VillagerAcquireTradeEvent
6+
import org.bukkit.event.entity.VillagerReplenishTradeEvent
7+
8+
class ExpensiveTrades : Module {
9+
override val description: String = "Trades will become expensive very quickly."
10+
override var options: ModuleOptions = ExpensiveTradesOptions()
11+
val typeSafeOptions
12+
get() = (options as? ExpensiveTradesOptions)
13+
?: error("Options are not of type ExpensiveTradesOptions")
14+
15+
@Serializable
16+
data class ExpensiveTradesOptions(
17+
override var enabled: Boolean = true,
18+
/**
19+
* Multiplier for the price of trades.
20+
* Higher values make the price changer more quickly.
21+
* Note this price change on itself goes both ways, meaning non-frequent trades (low demand) would be very cheap.
22+
* Use the [startingDemand] and [restockMinimumDemand] options to control the demand for trades. Where high demand means high prices.
23+
*/
24+
var priceMultiplierMultiplier: Float = 3f,
25+
/**
26+
* High demand for trades means higher prices.
27+
* This only affects the initial demand for trades.
28+
* To keep high prices, the demand has to stay high by trading frequently.
29+
* @see restockMinimumDemand
30+
*/
31+
var startingDemand: Int = 5,
32+
/**
33+
* The minimum demand for trades to be restocked.
34+
* If the demand is below this value, the recipe will not be restocked.
35+
* This is to prevent trades from becoming too cheap.
36+
*/
37+
var restockMinimumDemand: Int = 5,
38+
/**
39+
* If true, the recipe will ignore discounts from villagers.
40+
* This should be set to true to ensure that trades remain expensive.
41+
* This ignores discounts from the hero of the village effect, and curing a zombie villager.
42+
*/
43+
var ignoreDiscounts: Boolean = true,
44+
45+
) : ModuleOptions
46+
47+
@EventHandler(ignoreCancelled = true)
48+
fun on(e: VillagerAcquireTradeEvent) {
49+
e.recipe.priceMultiplier *= typeSafeOptions.priceMultiplierMultiplier
50+
e.recipe.demand += typeSafeOptions.startingDemand
51+
if (typeSafeOptions.ignoreDiscounts)
52+
e.recipe.setIgnoreDiscounts(true)
53+
}
54+
55+
@EventHandler(ignoreCancelled = true)
56+
fun on(e: VillagerReplenishTradeEvent) {
57+
if (e.recipe.demand < typeSafeOptions.restockMinimumDemand)
58+
e.recipe.demand = typeSafeOptions.restockMinimumDemand
59+
}
60+
}

src/main/kotlin/com/sybsuper/sybsafetyfirst/modules/ModuleManager.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ object ModuleManager {
3333
NetherPortalsDestabilize(),
3434
SkillBasedInventory(),
3535
BadAirCaves(),
36-
BabyCreatures()
36+
BabyCreatures(),
37+
ExpensiveTrades()
3738
)
3839
private val currentModuleInstances = modules.associateBy { it.id }.toMutableMap()
3940
private val nameMap = modules.associateBy { it.name }

0 commit comments

Comments
 (0)