Skip to content

Commit

Permalink
Draft Official Extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
gmitch215 committed Dec 2, 2023
1 parent 23a36fd commit eaa8be6
Show file tree
Hide file tree
Showing 3 changed files with 177 additions and 0 deletions.
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 api/src/main/java/us/teaminceptus/novaconomy/api/util/extensions.kt
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)
14 changes: 14 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
kotlin("jvm") version "1.9.21"
id("org.sonarqube") version "4.0.0.2929"
id("com.github.johnrengelman.shadow") version "8.1.1" apply false

Expand Down Expand Up @@ -96,8 +97,10 @@ subprojects {
apply<JacocoPlugin>()
apply(plugin = "org.sonarqube")
apply(plugin = "com.github.johnrengelman.shadow")
apply(plugin = "org.jetbrains.kotlin.jvm")

dependencies {
compileOnly(kotlin("stdlib"))
compileOnly("org.jetbrains:annotations:24.1.0")

testImplementation("org.spigotmc:spigot-api:1.8-R0.1-SNAPSHOT")
Expand All @@ -112,12 +115,23 @@ subprojects {
}

tasks {
assemble {
dependsOn(compileKotlin)
}

compileJava {
options.encoding = "UTF-8"
options.isWarnings = false
options.compilerArgs.addAll(listOf("-Xlint:all", "-Xlint:-processing"))
}

compileKotlin {
kotlinOptions {
jvmTarget = jvmVersion.toString()
freeCompilerArgs = listOf("-Xjvm-default=all")
}
}

jacocoTestReport {
dependsOn(test)

Expand Down

0 comments on commit eaa8be6

Please sign in to comment.