-
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.
Refactor and some more MVVM and observer
- Loading branch information
1 parent
ca98212
commit daf00a0
Showing
30 changed files
with
606 additions
and
701 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
kotlin.code.style=official |
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
35 changes: 0 additions & 35 deletions
35
src/main/kotlin/com/astrainteractive/astratemplate/api/Api.kt
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
src/main/kotlin/com/astrainteractive/astratemplate/api/TemplateApi.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,21 @@ | ||
package com.astrainteractive.astratemplate.api | ||
|
||
import org.bukkit.Material | ||
import org.bukkit.inventory.ItemStack | ||
import kotlin.random.Random | ||
|
||
object TemplateApi { | ||
fun randomItemStack(): ItemStack { | ||
val values = Material.values() | ||
val size = values.size | ||
val i = Random.nextInt(size) | ||
return ItemStack(values[i]) | ||
} | ||
fun randomItemStackList(size: Int = 70) = IntRange(0, size).map { randomItemStack() } | ||
|
||
fun onEnable() { | ||
} | ||
|
||
fun onDisable() { | ||
} | ||
} |
118 changes: 59 additions & 59 deletions
118
src/main/kotlin/com/astrainteractive/astratemplate/commands/AddCommand.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,77 +1,77 @@ | ||
package com.astrainteractive.astratemplate.commands | ||
|
||
import CommandManager | ||
import com.astrainteractive.astralibs.commands.AstraDSLCommand | ||
import com.astrainteractive.astralibs.withEntry | ||
import org.bukkit.Bukkit | ||
import org.bukkit.Material | ||
import org.bukkit.entity.Player | ||
import org.bukkit.inventory.ItemStack | ||
|
||
|
||
class AddCommand { | ||
val newTabCompleter = AstraDSLCommand.onTabComplete("add") { | ||
onType(0) { | ||
return@onTabComplete Bukkit.getOnlinePlayers().map { it.name }.withEntry(it) | ||
fun CommandManager.addCommandCompleter() = AstraDSLCommand.onTabComplete("add") { | ||
onType(0) { | ||
return@onTabComplete Bukkit.getOnlinePlayers().map { it.name }.withEntry(it) | ||
} | ||
onType(1) { | ||
return@onTabComplete Material.values().map { it.name }.withEntry(it) | ||
} | ||
onType(2) { | ||
return@onTabComplete IntRange(1, 64).map { it.toString() }.withEntry(it) | ||
} | ||
return@onTabComplete listOf() | ||
} | ||
|
||
/** | ||
* Add {PLAYER} {ITEM} [AMOUNT] | ||
*/ | ||
fun CommandManager.addCommand() = AstraDSLCommand.command("add") { | ||
if (!sentByPlayer) { | ||
sender.sendMessage("Sender should be player") | ||
return@command | ||
} | ||
val player = player() { | ||
onEmptyArgument { | ||
println("onEmptyArgument") | ||
} | ||
onType(1) { | ||
return@onTabComplete Material.values().map { it.name }.withEntry(it) | ||
onWrongArgument { | ||
println("onWrongArgument") | ||
} | ||
onType(2) { | ||
return@onTabComplete IntRange(1, 64).map { it.toString() }.withEntry(it) | ||
onResultNotFound { | ||
println("onResultNotFound") | ||
} | ||
return@onTabComplete listOf() | ||
} | ||
|
||
/** | ||
* Add {PLAYER} {ITEM} [AMOUNT] | ||
*/ | ||
val addCommand = AstraDSLCommand.command("add") { | ||
if (!sentByPlayer) { | ||
sender.sendMessage("Sender should be player") | ||
return@command | ||
onFailure { | ||
println("onFailure") | ||
} | ||
val player = player() { | ||
onEmptyArgument { | ||
println("onEmptyArgument") | ||
} | ||
onWrongArgument { | ||
println("onWrongArgument") | ||
} | ||
onResultNotFound { | ||
println("onResultNotFound") | ||
} | ||
onFailure { | ||
println("onFailure") | ||
} | ||
} ?: return@command | ||
val item = item() { | ||
sender.sendMessage("Item not found") | ||
} ?: return@command | ||
val amount = getArgumentOrNull(2)?.toIntOrNull() ?: 1 | ||
player.inventory.addItem(item.apply | ||
{ setAmount(amount) }) | ||
} | ||
} ?: return@command | ||
val item = item() { | ||
sender.sendMessage("Item not found") | ||
} ?: return@command | ||
val amount = getArgumentOrNull(2)?.toIntOrNull() ?: 1 | ||
player.inventory.addItem(item.apply | ||
{ setAmount(amount) }) | ||
} | ||
|
||
|
||
fun AstraDSLCommand.DSLCommandBuilder.player(block: AstraDSLCommand.ArgumentResult.() -> Unit): Player? { | ||
val argument = this.getArgumentOrNull(0) ?: run { | ||
block(AstraDSLCommand.ArgumentResult(AstraDSLCommand.ArgumentStatus.Empty)) | ||
return null | ||
} | ||
return Bukkit.getPlayer(argument) ?: run { | ||
block(AstraDSLCommand.ArgumentResult(AstraDSLCommand.ArgumentStatus.ResultNotFound)) | ||
null | ||
} | ||
private fun AstraDSLCommand.DSLCommandBuilder.player(block: AstraDSLCommand.ArgumentResult.() -> Unit): Player? { | ||
val argument = this.getArgumentOrNull(0) ?: run { | ||
block(AstraDSLCommand.ArgumentResult(AstraDSLCommand.ArgumentStatus.Empty)) | ||
return null | ||
} | ||
return Bukkit.getPlayer(argument) ?: run { | ||
block(AstraDSLCommand.ArgumentResult(AstraDSLCommand.ArgumentStatus.ResultNotFound)) | ||
null | ||
} | ||
} | ||
|
||
private fun AstraDSLCommand.DSLCommandBuilder.item(onNotFound: () -> Unit): ItemStack? { | ||
val argument = getArgumentOrNull(1) ?: run { | ||
onNotFound() | ||
return null | ||
} | ||
val material = Material.matchMaterial(argument) ?: run { | ||
onNotFound() | ||
return null | ||
} | ||
return ItemStack(material) | ||
private fun AstraDSLCommand.DSLCommandBuilder.item(onNotFound: () -> Unit): ItemStack? { | ||
val argument = getArgumentOrNull(1) ?: run { | ||
onNotFound() | ||
return null | ||
} | ||
val material = Material.matchMaterial(argument) ?: run { | ||
onNotFound() | ||
return null | ||
} | ||
} | ||
return ItemStack(material) | ||
} |
Oops, something went wrong.