forked from Team-Inceptus/Novaconomy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
177 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
api/src/main/java/us/teaminceptus/novaconomy/api/economy/market/extensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package us.teaminceptus.novaconomy.api.economy.market | ||
|
||
import org.bukkit.Material | ||
import us.teaminceptus.novaconomy.api.economy.Economy | ||
|
||
// NovaMarket | ||
|
||
/** | ||
* Gets the price of an item. | ||
* @param item The item to get the price of. | ||
* @return The price of the item. | ||
*/ | ||
operator fun NovaMarket.get(item: Material): Double = getPrice(item) | ||
|
||
/** | ||
* Gets the price of an item. | ||
* @param item The item to get the price of. | ||
* @param economy The economy to get the price in. | ||
* @return The price of the item. | ||
*/ | ||
operator fun NovaMarket.get(item: Material, economy: Economy?): Double = getPrice(item, economy) | ||
|
||
/** | ||
* Gets the price of an item. | ||
* @param item The item to get the price of. | ||
* @param scale The conversion scale to get the price in. | ||
* @return The price of the item. | ||
*/ | ||
operator fun NovaMarket.get(item: Material, scale: Double): Double = getPrice(item, scale) | ||
|
||
/** | ||
* Sets the override price of an item. | ||
* @param item The item to get the price of. | ||
* @param price The price to set the item to. | ||
*/ | ||
operator fun NovaMarket.set(item: Material, price: Double) = setPriceOverrides(item, price) |
127 changes: 127 additions & 0 deletions
127
api/src/main/java/us/teaminceptus/novaconomy/api/util/extensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package us.teaminceptus.novaconomy.api.util | ||
|
||
// Price | ||
|
||
/** | ||
* Adds two prices together. | ||
* @param price The price to add. | ||
* @return The sum of the original price and the given price. | ||
*/ | ||
operator fun Price.plus(price: Price): Price = Price(this.amount + price.amount) | ||
|
||
/** | ||
* Adds two prices together. | ||
* @param price The price to add. | ||
* @return The sum of the original price and the given price. | ||
*/ | ||
operator fun Price.plus(price: Double): Price = Price(this.amount + price) | ||
|
||
/** | ||
* Adds two prices together. | ||
* @param price The price to add. | ||
* @return The sum of the original price and the given price. | ||
*/ | ||
operator fun Price.plusAssign(price: Price) { add(price) } | ||
|
||
/** | ||
* Adds two prices together. | ||
* @param price The price to add. | ||
* @return The sum of the original price and the given price. | ||
*/ | ||
operator fun Price.plusAssign(price: Double) { add(price) } | ||
|
||
/** | ||
* Increments the price's amount by 1. | ||
* @return The price with the amount incremented by 1. | ||
*/ | ||
operator fun Price.inc() = add(1.0) | ||
|
||
/** | ||
* Subtracts two prices. | ||
* @param price The price to subtract. | ||
* @return The difference between the original price and the given price. | ||
*/ | ||
operator fun Price.minus(price: Price): Price = Price(this.amount - price.amount) | ||
|
||
/** | ||
* Subtracts two prices. | ||
* @param price The price to subtract. | ||
* @return The difference between the original price and the given price. | ||
*/ | ||
operator fun Price.minus(price: Double): Price = Price(this.amount - price) | ||
|
||
/** | ||
* Subtracts two prices. | ||
* @param price The price to subtract. | ||
* @return The difference between the original price and the given price. | ||
*/ | ||
operator fun Price.minusAssign(price: Price) { remove(price) } | ||
|
||
/** | ||
* Subtracts two prices. | ||
* @param price The price to subtract. | ||
* @return The difference between the original price and the given price. | ||
*/ | ||
operator fun Price.minusAssign(price: Double) { remove(price) } | ||
|
||
/** | ||
* Decrements the price's amount by 1. | ||
* @return The price with the amount decremented by 1. | ||
*/ | ||
operator fun Price.dec() = remove(1.0) | ||
|
||
/** | ||
* Multiplies two prices. | ||
* @param price The price to multiply. | ||
* @return The product of the original price and the given price. | ||
*/ | ||
operator fun Price.times(price: Price): Price = Price(this.amount * price.amount) | ||
|
||
/** | ||
* Multiplies two prices. | ||
* @param price The price to multiply. | ||
* @return The product of the original price and the given price. | ||
*/ | ||
operator fun Price.times(price: Double): Price = Price(this.amount * price) | ||
|
||
/** | ||
* Multiplies two prices. | ||
* @param price The price to multiply. | ||
* @return The product of the original price and the given price. | ||
*/ | ||
operator fun Price.timesAssign(price: Price) { times(price) } | ||
|
||
/** | ||
* Multiplies two prices. | ||
* @param price The price to multiply. | ||
* @return The product of the original price and the given price. | ||
*/ | ||
operator fun Price.timesAssign(price: Double) { times(price) } | ||
|
||
/** | ||
* Divides two prices. | ||
* @param price The price to divide. | ||
* @return The quotient of the original price and the given price. | ||
*/ | ||
operator fun Price.div(price: Price): Price = Price(this.amount / price.amount) | ||
|
||
/** | ||
* Divides two prices. | ||
* @param price The price to divide. | ||
*/ | ||
operator fun Price.div(price: Double): Price = Price(this.amount / price) | ||
|
||
/** | ||
* Divides two prices. | ||
* @param price The price to divide. | ||
*/ | ||
operator fun Price.divAssign(price: Price) { div(price) } | ||
|
||
/** | ||
* Divides two prices. | ||
* @param price The price to divide. | ||
*/ | ||
operator fun Price.divAssign(price: Double) { div(price) } | ||
|
||
operator fun Price.unaryMinus() = Price(-this.amount) | ||
operator fun Price.unaryPlus() = Price(+this.amount) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters