-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added HasChanceCommand. - Deprecated the CommandUtilsService for adding commands to the 'whenOnline' module, use the '/cu execute whenOnline' command instead.
- Loading branch information
1 parent
4a37e45
commit f5447e1
Showing
4 changed files
with
31 additions
and
3 deletions.
There are no files selected for viewing
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
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
20 changes: 20 additions & 0 deletions
20
src/main/kotlin/de/randombyte/commandutils/conditions/HasChanceCommand.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,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() | ||
} | ||
} |
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