Skip to content

Commit

Permalink
v2.3.0
Browse files Browse the repository at this point in the history
- Added HasChanceCommand.
- Deprecated the CommandUtilsService for adding commands to the 'whenOnline' module, use the '/cu execute whenOnline' command instead.
  • Loading branch information
randombyte-developer committed Dec 25, 2018
1 parent 4a37e45 commit f5447e1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if (!isJitpack) {
}

group "de.randombyte"
version "2.2.4"
version "2.3.0"

repositories {
jcenter()
Expand Down Expand Up @@ -50,7 +50,6 @@ shadowJar {

relocate "kotlin", "de.randombyte.commandutils.shaded.kotlin"
relocate "de.randombyte.kosp", "de.randombyte.commandutils.shaded.kosp"
relocate "org.bstats", "de.randombyte.commandutils.shaded.bstats"

classifier = null // Remove '-all' suffix from output file name
}
Expand Down
10 changes: 9 additions & 1 deletion src/main/kotlin/de/randombyte/commandutils/CommandUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class CommandUtils @Inject constructor(
companion object {
const val ID = "command-utils"
const val NAME = "CommandUtils"
const val VERSION = "2.2.4"
const val VERSION = "2.3.0"
const val AUTHOR = "RandomByte"

const val PLACEHOLDER_API_ID = "placeholderapi"
Expand All @@ -67,6 +67,7 @@ class CommandUtils @Inject constructor(
const val QUANTITY_ARG = "quantity"
const val PERMISSION_ARG = "permission"
const val ITEM_ARG = "item"
const val CHANCE_ARG = "chance"
const val CONDITION_COMMAND_ARG = "condition_command"

private val LAZY_INSTANCE = lazy { Sponge.getPluginManager().getPlugin(ID).get().instance.get() as CommandUtils }
Expand Down Expand Up @@ -154,6 +155,12 @@ class CommandUtils @Inject constructor(
.executor(HasPermissionCommand())
.build()

val hasChanceCommandSpec = CommandSpec.builder()
.permission("$ROOT_PERMISSION.chance")
.arguments(doubleNum(CHANCE_ARG.toText()))
.executor(HasChanceCommand())
.build()

val hasInHandCommandSpec = CommandSpec.builder()
.permission("$ROOT_PERMISSION.in-hand")
.arguments(
Expand Down Expand Up @@ -203,6 +210,7 @@ class CommandUtils @Inject constructor(
.child(hasMoneyCommandSpec, "money")
.child(hasPayedCommandSpec, "payed")
.child(hasPermissionCommandSpec, "permission")
.child(hasChanceCommandSpec, "chance")
.child(CommandSpec.builder()
.child(hasInHandCommandSpec, "hand")
.build(), "in")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package de.randombyte.commandutils.conditions

import de.randombyte.commandutils.CommandUtils
import de.randombyte.kosp.extensions.toText
import org.spongepowered.api.command.CommandException
import org.spongepowered.api.command.CommandResult
import org.spongepowered.api.command.CommandSource
import org.spongepowered.api.command.args.CommandContext
import org.spongepowered.api.command.spec.CommandExecutor
import kotlin.random.Random

class HasChanceCommand : CommandExecutor {
override fun execute(src: CommandSource, args: CommandContext): CommandResult {
val chance = args.getOne<Double>(CommandUtils.CHANCE_ARG).get()
if (chance < 0.0 || chance > 1.0) throw CommandException("'chance' must be between 0.0 and 1.0!".toText())

val random = Random.nextDouble(from = 0.0, until = 1.0)
return (random < chance).toCommandResult()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package de.randombyte.commandutils.service

import java.util.*

@Deprecated("This will be removed at some point in the future. Use the '/cu execute whenOnline' command instead.")
interface CommandUtilsService {

fun executeWhenOnline(playerUuid: UUID, newCommand: String)
Expand Down

0 comments on commit f5447e1

Please sign in to comment.