diff --git a/build.gradle b/build.gradle index 32562b4..e0c34a2 100644 --- a/build.gradle +++ b/build.gradle @@ -22,7 +22,7 @@ if (!isJitpack) { } group "de.randombyte" -version "2.2.4" +version "2.3.0" repositories { jcenter() @@ -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 } diff --git a/src/main/kotlin/de/randombyte/commandutils/CommandUtils.kt b/src/main/kotlin/de/randombyte/commandutils/CommandUtils.kt index d28ea47..68930c4 100644 --- a/src/main/kotlin/de/randombyte/commandutils/CommandUtils.kt +++ b/src/main/kotlin/de/randombyte/commandutils/CommandUtils.kt @@ -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" @@ -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 } @@ -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( @@ -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") diff --git a/src/main/kotlin/de/randombyte/commandutils/conditions/HasChanceCommand.kt b/src/main/kotlin/de/randombyte/commandutils/conditions/HasChanceCommand.kt new file mode 100644 index 0000000..d4a6fe3 --- /dev/null +++ b/src/main/kotlin/de/randombyte/commandutils/conditions/HasChanceCommand.kt @@ -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(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() + } +} \ No newline at end of file diff --git a/src/main/kotlin/de/randombyte/commandutils/service/CommandUtilsService.kt b/src/main/kotlin/de/randombyte/commandutils/service/CommandUtilsService.kt index 9ed5e39..b19d782 100644 --- a/src/main/kotlin/de/randombyte/commandutils/service/CommandUtilsService.kt +++ b/src/main/kotlin/de/randombyte/commandutils/service/CommandUtilsService.kt @@ -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)