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+ }
0 commit comments