Skip to content

Commit f5447e1

Browse files
v2.3.0
- Added HasChanceCommand. - Deprecated the CommandUtilsService for adding commands to the 'whenOnline' module, use the '/cu execute whenOnline' command instead.
1 parent 4a37e45 commit f5447e1

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ if (!isJitpack) {
2222
}
2323

2424
group "de.randombyte"
25-
version "2.2.4"
25+
version "2.3.0"
2626

2727
repositories {
2828
jcenter()
@@ -50,7 +50,6 @@ shadowJar {
5050

5151
relocate "kotlin", "de.randombyte.commandutils.shaded.kotlin"
5252
relocate "de.randombyte.kosp", "de.randombyte.commandutils.shaded.kosp"
53-
relocate "org.bstats", "de.randombyte.commandutils.shaded.bstats"
5453

5554
classifier = null // Remove '-all' suffix from output file name
5655
}

src/main/kotlin/de/randombyte/commandutils/CommandUtils.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class CommandUtils @Inject constructor(
4848
companion object {
4949
const val ID = "command-utils"
5050
const val NAME = "CommandUtils"
51-
const val VERSION = "2.2.4"
51+
const val VERSION = "2.3.0"
5252
const val AUTHOR = "RandomByte"
5353

5454
const val PLACEHOLDER_API_ID = "placeholderapi"
@@ -67,6 +67,7 @@ class CommandUtils @Inject constructor(
6767
const val QUANTITY_ARG = "quantity"
6868
const val PERMISSION_ARG = "permission"
6969
const val ITEM_ARG = "item"
70+
const val CHANCE_ARG = "chance"
7071
const val CONDITION_COMMAND_ARG = "condition_command"
7172

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

158+
val hasChanceCommandSpec = CommandSpec.builder()
159+
.permission("$ROOT_PERMISSION.chance")
160+
.arguments(doubleNum(CHANCE_ARG.toText()))
161+
.executor(HasChanceCommand())
162+
.build()
163+
157164
val hasInHandCommandSpec = CommandSpec.builder()
158165
.permission("$ROOT_PERMISSION.in-hand")
159166
.arguments(
@@ -203,6 +210,7 @@ class CommandUtils @Inject constructor(
203210
.child(hasMoneyCommandSpec, "money")
204211
.child(hasPayedCommandSpec, "payed")
205212
.child(hasPermissionCommandSpec, "permission")
213+
.child(hasChanceCommandSpec, "chance")
206214
.child(CommandSpec.builder()
207215
.child(hasInHandCommandSpec, "hand")
208216
.build(), "in")
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package de.randombyte.commandutils.conditions
2+
3+
import de.randombyte.commandutils.CommandUtils
4+
import de.randombyte.kosp.extensions.toText
5+
import org.spongepowered.api.command.CommandException
6+
import org.spongepowered.api.command.CommandResult
7+
import org.spongepowered.api.command.CommandSource
8+
import org.spongepowered.api.command.args.CommandContext
9+
import org.spongepowered.api.command.spec.CommandExecutor
10+
import kotlin.random.Random
11+
12+
class HasChanceCommand : CommandExecutor {
13+
override fun execute(src: CommandSource, args: CommandContext): CommandResult {
14+
val chance = args.getOne<Double>(CommandUtils.CHANCE_ARG).get()
15+
if (chance < 0.0 || chance > 1.0) throw CommandException("'chance' must be between 0.0 and 1.0!".toText())
16+
17+
val random = Random.nextDouble(from = 0.0, until = 1.0)
18+
return (random < chance).toCommandResult()
19+
}
20+
}

src/main/kotlin/de/randombyte/commandutils/service/CommandUtilsService.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package de.randombyte.commandutils.service
22

33
import java.util.*
44

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

78
fun executeWhenOnline(playerUuid: UUID, newCommand: String)

0 commit comments

Comments
 (0)