-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ec1eab
commit d301e14
Showing
17 changed files
with
123 additions
and
67 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
4 changes: 2 additions & 2 deletions
4
...kotlin/ru/astrainteractive/astralibs/command/api/argumenttype/PotionEffectTypeArgument.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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
package ru.astrainteractive.astralibs.command.api.argumenttype | ||
|
||
import org.bukkit.potion.PotionEffectType | ||
import ru.astrainteractive.astralibs.command.api.exception.BukkitCommandException | ||
import ru.astrainteractive.astralibs.command.api.exception.NoPotionEffectTypeException | ||
|
||
data object PotionEffectTypeArgument : ArgumentType<PotionEffectType> { | ||
override val key: String = "PotionEffectTypeArgument" | ||
override fun transform(value: String): PotionEffectType { | ||
return value.let(PotionEffectType::getByName) | ||
?: throw BukkitCommandException.NoPotionEffectTypeException(value) | ||
?: throw NoPotionEffectTypeException(value) | ||
} | ||
} |
7 changes: 4 additions & 3 deletions
7
.../main/kotlin/ru/astrainteractive/astralibs/command/api/context/BukkitCommandContextExt.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
11 changes: 0 additions & 11 deletions
11
...main/kotlin/ru/astrainteractive/astralibs/command/api/exception/BukkitCommandException.kt
This file was deleted.
Oops, something went wrong.
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
4 changes: 2 additions & 2 deletions
4
...nd/src/main/kotlin/ru/astrainteractive/astralibs/command/api/argumenttype/ArgumentType.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
31 changes: 31 additions & 0 deletions
31
...rc/main/kotlin/ru/astrainteractive/astralibs/command/api/argumenttype/EnumArgumentType.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,31 @@ | ||
package ru.astrainteractive.astralibs.command.api.argumenttype | ||
|
||
import ru.astrainteractive.astralibs.command.api.exception.ArgumentTypeException | ||
import kotlin.enums.EnumEntries | ||
|
||
/** | ||
* Enum argument is used to define enumeration of arguments | ||
* @see EnumArgumentType | ||
*/ | ||
interface EnumArgument { | ||
/** | ||
* This value will be checked for command argument | ||
*/ | ||
val value: String | ||
} | ||
|
||
/** | ||
* When your command is like /amarket <open|expired|players> - you can use enums | ||
*/ | ||
class EnumArgumentType<T>( | ||
private val entries: EnumEntries<T> | ||
) : PrimitiveArgumentType<Enum<T>> where T : Enum<T>, T : EnumArgument { | ||
override val key: String = "ENUM" | ||
|
||
override fun transform(value: String): Enum<T> { | ||
return entries.firstOrNull { entry -> entry.value.equals(value, ignoreCase = true) } | ||
?.ordinal | ||
?.let(entries::getOrNull) | ||
?: throw ArgumentTypeException(key, value) | ||
} | ||
} |
44 changes: 22 additions & 22 deletions
44
...in/kotlin/ru/astrainteractive/astralibs/command/api/argumenttype/PrimitiveArgumentType.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 |
---|---|---|
@@ -1,33 +1,33 @@ | ||
package ru.astrainteractive.astralibs.command.api.argumenttype | ||
|
||
import ru.astrainteractive.astralibs.command.api.exception.DefaultCommandException.ArgumentTypeException | ||
import ru.astrainteractive.astralibs.command.api.exception.ArgumentTypeException | ||
|
||
interface PrimitiveArgumentType<T : Any> : ArgumentType<T> { | ||
data object Int : PrimitiveArgumentType<kotlin.Int> { | ||
override val key: kotlin.String = "INT" | ||
override fun transform(value: kotlin.String): kotlin.Int { | ||
return value.toIntOrNull() ?: throw ArgumentTypeException(Double.key, value) | ||
} | ||
interface PrimitiveArgumentType<T : Any> : ArgumentType<T> | ||
|
||
data object IntArgumentType : PrimitiveArgumentType<Int> { | ||
override val key: String = "INT" | ||
override fun transform(value: String): Int { | ||
return value.toIntOrNull() ?: throw ArgumentTypeException(key, value) | ||
} | ||
} | ||
|
||
data object String : PrimitiveArgumentType<kotlin.String> { | ||
override val key: kotlin.String = "STRING" | ||
override fun transform(value: kotlin.String): kotlin.String { | ||
return value | ||
} | ||
data object StringArgumentType : PrimitiveArgumentType<String> { | ||
override val key: String = "STRING" | ||
override fun transform(value: String): String { | ||
return value | ||
} | ||
} | ||
|
||
data object Double : PrimitiveArgumentType<kotlin.Double> { | ||
override val key: kotlin.String = "DOUBLE" | ||
override fun transform(value: kotlin.String): kotlin.Double { | ||
return value.toDoubleOrNull() ?: throw ArgumentTypeException(key, value) | ||
} | ||
data object DoubleArgumentType : PrimitiveArgumentType<Double> { | ||
override val key: String = "DOUBLE" | ||
override fun transform(value: String): Double { | ||
return value.toDoubleOrNull() ?: throw ArgumentTypeException(key, value) | ||
} | ||
} | ||
|
||
data object Boolean : PrimitiveArgumentType<kotlin.Boolean> { | ||
override val key: kotlin.String = "BOOLEAN" | ||
override fun transform(value: kotlin.String): kotlin.Boolean { | ||
return value.toBooleanStrictOrNull() ?: throw ArgumentTypeException(Double.key, value) | ||
} | ||
data object BooleanArgumentType : PrimitiveArgumentType<Boolean> { | ||
override val key: String = "BOOLEAN" | ||
override fun transform(value: String): Boolean { | ||
return value.toBooleanStrictOrNull() ?: throw ArgumentTypeException(key, value) | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ makeevrserg.java.ktarget=21 | |
# Project | ||
makeevrserg.project.name=AstraLibs | ||
makeevrserg.project.group=ru.astrainteractive.astralibs | ||
makeevrserg.project.version.string=3.17.1 | ||
makeevrserg.project.version.string=3.18.0 | ||
makeevrserg.project.description=Core utilities for spigot development | ||
makeevrserg.project.developers=makeevrserg|Makeev Roman|[email protected] | ||
makeevrserg.project.url=https://empireprojekt.ru | ||
|
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
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