FireworkCalculate - 2022 .ver
This commit is contained in:
parent
0719ae092f
commit
e0a9853e9c
|
|
@ -1,5 +1,6 @@
|
||||||
package cc.maxmc.fwc
|
package cc.maxmc.fwc
|
||||||
|
|
||||||
|
import cc.maxmc.fwc.command.Commands
|
||||||
import cc.maxmc.fwc.database.connect
|
import cc.maxmc.fwc.database.connect
|
||||||
import kotlinx.coroutines.CoroutineExceptionHandler
|
import kotlinx.coroutines.CoroutineExceptionHandler
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
|
@ -23,19 +24,12 @@ import java.util.concurrent.Executor
|
||||||
object FireworkCounter: Plugin() {
|
object FireworkCounter: Plugin() {
|
||||||
|
|
||||||
override fun onEnable() {
|
override fun onEnable() {
|
||||||
|
Commands
|
||||||
connect()
|
connect()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val PluginScope = CoroutineScope(SupervisorJob() + CoroutineExceptionHandler { _, except ->
|
|
||||||
console().sendMessage("§e执行异步操作时出现异常 ${except.message}")
|
|
||||||
console().sendMessage("§c栈追踪: ")
|
|
||||||
except.stackTrace.forEach {
|
|
||||||
console().sendMessage("§c位于 $it")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
val bukkitSyncContext = Executor {
|
val bukkitSyncContext = Executor {
|
||||||
Bukkit.getScheduler().runTask(BukkitPlugin.getInstance(), it)
|
Bukkit.getScheduler().runTask(BukkitPlugin.getInstance(), it)
|
||||||
}.asCoroutineDispatcher()
|
}.asCoroutineDispatcher()
|
||||||
|
|
@ -43,3 +37,11 @@ val bukkitSyncContext = Executor {
|
||||||
val bukkitAsyncContext = Executor {
|
val bukkitAsyncContext = Executor {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(BukkitPlugin.getInstance(), it)
|
Bukkit.getScheduler().runTaskAsynchronously(BukkitPlugin.getInstance(), it)
|
||||||
}.asCoroutineDispatcher()
|
}.asCoroutineDispatcher()
|
||||||
|
|
||||||
|
val PluginScope = CoroutineScope(bukkitAsyncContext + SupervisorJob() + CoroutineExceptionHandler { _, except ->
|
||||||
|
console().sendMessage("§e执行异步操作时出现异常 ${except.message}")
|
||||||
|
console().sendMessage("§c栈追踪: ")
|
||||||
|
except.stackTrace.forEach {
|
||||||
|
console().sendMessage("§c位于 $it")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,134 @@
|
||||||
|
package cc.maxmc.fwc.command
|
||||||
|
|
||||||
|
import cc.maxmc.fwc.PluginScope
|
||||||
|
import cc.maxmc.fwc.database.FireworkTable
|
||||||
|
import cc.maxmc.fwc.database.PlayerFireworkScore
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import org.bukkit.Bukkit
|
||||||
|
import org.bukkit.entity.Player
|
||||||
|
import org.jetbrains.exposed.sql.exposedLogger
|
||||||
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
|
import taboolib.common.platform.command.CommandBuilder
|
||||||
|
import taboolib.common.platform.command.command
|
||||||
|
|
||||||
|
object Commands {
|
||||||
|
init {
|
||||||
|
register()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun register() = command("firework", description = "花火活动相关命令") {
|
||||||
|
topCommand()
|
||||||
|
addCommand()
|
||||||
|
setCommand()
|
||||||
|
showCommand()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun CommandBuilder.CommandComponent.topCommand() = literal("top") {
|
||||||
|
execute<Player> { sender, _, _ ->
|
||||||
|
PluginScope.launch {
|
||||||
|
sender.sendMessage("§6| §7花火点排行:")
|
||||||
|
transaction {
|
||||||
|
val scores = PlayerFireworkScore.all().sortedByDescending { it.score }
|
||||||
|
scores.forEachIndexed { rank, score ->
|
||||||
|
sender.sendMessage("§e| §7${rank + 1}.${score.name} - §e${score.score} 花火点")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TODO
|
||||||
|
dynamic {
|
||||||
|
restrict<Player> { _, _, argument ->
|
||||||
|
return@restrict argument.toIntOrNull() != null
|
||||||
|
}
|
||||||
|
|
||||||
|
execute<Player> { sender, _, argument ->
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun CommandBuilder.CommandComponent.addCommand() = literal("add", permission = "fireworks.add") {
|
||||||
|
dynamic {
|
||||||
|
suggestion<Player> { _, _ ->
|
||||||
|
Bukkit.getOnlinePlayers().map { it.name }
|
||||||
|
}
|
||||||
|
restrict<Player> { _, _, argument ->
|
||||||
|
return@restrict Bukkit.getPlayerExact(argument) != null
|
||||||
|
}
|
||||||
|
dynamic {
|
||||||
|
restrict<Player> { _, _, argument ->
|
||||||
|
argument.toIntOrNull() != null
|
||||||
|
}
|
||||||
|
execute<Player> { sender, context, argument ->
|
||||||
|
val target = Bukkit.getPlayerExact(context.argument(-1))!!
|
||||||
|
val scoreAdded = argument.toInt()
|
||||||
|
PluginScope.launch {
|
||||||
|
transaction {
|
||||||
|
val scoreObj = PlayerFireworkScore.findById(target.uniqueId) ?: PlayerFireworkScore.new(target.uniqueId) {
|
||||||
|
name = target.name
|
||||||
|
score = 0
|
||||||
|
}
|
||||||
|
scoreObj.score += scoreAdded
|
||||||
|
sender.sendMessage("§6| §7成功给予玩家 §a${target.name} §6$argument 花火点")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun CommandBuilder.CommandComponent.setCommand() = literal("set", permission = "fireworks.set") {
|
||||||
|
dynamic {
|
||||||
|
suggestion<Player> { _, _ ->
|
||||||
|
Bukkit.getOnlinePlayers().map { it.name }
|
||||||
|
}
|
||||||
|
restrict<Player> { _, _, argument ->
|
||||||
|
return@restrict Bukkit.getPlayerExact(argument) != null
|
||||||
|
}
|
||||||
|
dynamic {
|
||||||
|
restrict<Player> { _, _, argument ->
|
||||||
|
argument.toIntOrNull() != null
|
||||||
|
}
|
||||||
|
execute<Player> { sender, context, argument ->
|
||||||
|
val target = Bukkit.getPlayerExact(context.argument(-1))!!
|
||||||
|
val scoreAdded = argument.toInt()
|
||||||
|
PluginScope.launch {
|
||||||
|
transaction {
|
||||||
|
val scoreObj = PlayerFireworkScore.findById(target.uniqueId) ?: PlayerFireworkScore.new(target.uniqueId) {
|
||||||
|
name = target.name
|
||||||
|
score = 0
|
||||||
|
}
|
||||||
|
scoreObj.score = scoreAdded
|
||||||
|
sender.sendMessage("§6| §7成功将玩家 §a${target.name} §7的花火点设置为 §6$argument.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun CommandBuilder.CommandComponent.showCommand() = literal("show", permission = "fireworks.show") {
|
||||||
|
dynamic {
|
||||||
|
suggestion<Player> { _, _ ->
|
||||||
|
Bukkit.getOnlinePlayers().map { it.name }
|
||||||
|
}
|
||||||
|
restrict<Player> { _, _, argument ->
|
||||||
|
return@restrict Bukkit.getPlayerExact(argument) != null
|
||||||
|
}
|
||||||
|
execute<Player> { sender, _, argument ->
|
||||||
|
val target = Bukkit.getPlayerExact(argument)!!
|
||||||
|
PluginScope.launch {
|
||||||
|
transaction {
|
||||||
|
val scoreObj = PlayerFireworkScore.findById(target.uniqueId) ?: PlayerFireworkScore.new(target.uniqueId) {
|
||||||
|
name = target.name
|
||||||
|
score = 0
|
||||||
|
}
|
||||||
|
sender.sendMessage("§6| §7玩家 §a${target.name} §7的花火点为 §6${scoreObj.score}.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package cc.maxmc.fwc.listener
|
package cc.maxmc.fwc.listener
|
||||||
|
|
||||||
import cc.maxmc.fwc.database.PlayerFireworkScore
|
import cc.maxmc.fwc.database.PlayerFireworkScore
|
||||||
import cc.maxmc.fwc.utils.Calculator
|
import cc.maxmc.fwc.misc.Calculator
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
import org.bukkit.event.entity.FireworkExplodeEvent
|
import org.bukkit.event.entity.FireworkExplodeEvent
|
||||||
import org.jetbrains.exposed.sql.transactions.transaction
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
|
|
@ -12,13 +12,13 @@ object FireworkListener {
|
||||||
fun onFirework(e: FireworkExplodeEvent) {
|
fun onFirework(e: FireworkExplodeEvent) {
|
||||||
val shooter = e.entity.shooter
|
val shooter = e.entity.shooter
|
||||||
if (shooter !is Player) return
|
if (shooter !is Player) return
|
||||||
var score = Calculator.calculateScore(e.entity.fireworkMeta)
|
val score = Calculator.calculateScore(e.entity.fireworkMeta)
|
||||||
shooter.sendMessage("§6| §7恭喜您获得 §6$score 花火点")
|
shooter.sendMessage("§6| §7恭喜您获得 §6$score 花火点")
|
||||||
transaction {
|
transaction {
|
||||||
val current: PlayerFireworkScore =
|
val current: PlayerFireworkScore =
|
||||||
PlayerFireworkScore.findById(shooter.uniqueId) ?: PlayerFireworkScore.new(shooter.uniqueId) {
|
PlayerFireworkScore.findById(shooter.uniqueId) ?: PlayerFireworkScore.new(shooter.uniqueId) {
|
||||||
name = shooter.name
|
name = shooter.name
|
||||||
score = 0
|
this.score = 0
|
||||||
}
|
}
|
||||||
current.score = current.score + score
|
current.score = current.score + score
|
||||||
shooter.sendMessage("§6| §7您目前的花火点为: §6${PlayerFireworkScore[shooter.uniqueId].score}")
|
shooter.sendMessage("§6| §7您目前的花火点为: §6${PlayerFireworkScore[shooter.uniqueId].score}")
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package cc.maxmc.fwc.utils
|
package cc.maxmc.fwc.misc
|
||||||
|
|
||||||
import org.bukkit.FireworkEffect
|
import org.bukkit.FireworkEffect
|
||||||
import org.bukkit.FireworkEffect.Type.*
|
import org.bukkit.FireworkEffect.Type.*
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package cc.maxmc.fwc.utils
|
package cc.maxmc.fwc.misc
|
||||||
|
|
||||||
import cc.maxmc.fwc.database.PlayerFireworkScore
|
import cc.maxmc.fwc.database.PlayerFireworkScore
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
Loading…
Reference in New Issue