diff --git a/pom.xml b/pom.xml
index 4143d84..f73c911 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,7 +7,7 @@
top.wetabq.easyapi
EasyAPI
- 1.1.3
+ 1.1.5
diff --git a/src/main/java/top/wetabq/easyapi/api/defaults/AsyncListenerAPI.kt b/src/main/java/top/wetabq/easyapi/api/defaults/AsyncListenerAPI.kt
new file mode 100644
index 0000000..30857aa
--- /dev/null
+++ b/src/main/java/top/wetabq/easyapi/api/defaults/AsyncListenerAPI.kt
@@ -0,0 +1,251 @@
+package top.wetabq.easyapi.api.defaults
+
+
+import cn.nukkit.event.EventHandler
+import cn.nukkit.event.Listener
+import cn.nukkit.event.block.BlockBreakEvent
+import cn.nukkit.event.block.BlockPlaceEvent
+import cn.nukkit.event.entity.EntityArmorChangeEvent
+import cn.nukkit.event.entity.EntityDamageByEntityEvent
+import cn.nukkit.event.entity.EntityDamageEvent
+import cn.nukkit.event.entity.EntityDeathEvent
+import cn.nukkit.event.inventory.CraftItemEvent
+import cn.nukkit.event.inventory.InventoryPickupItemEvent
+import cn.nukkit.event.inventory.InventoryTransactionEvent
+import cn.nukkit.event.level.WeatherChangeEvent
+import cn.nukkit.event.player.*
+import top.wetabq.easyapi.EasyAPI
+import top.wetabq.easyapi.api.SimpleIntegrateAPI
+import top.wetabq.easyapi.listener.AsyncListener
+import top.wetabq.easyapi.module.defaults.asyncTaskCallEvent
+
+object AsyncListenerAPI : SimpleIntegrateAPI, Listener, AsyncListener {
+
+ private val asyncListenerList = arrayListOf()
+
+ init {
+ EasyAPI.server.pluginManager.registerEvents(this, EasyAPI.INSTANCE)
+ }
+
+ fun add(t: AsyncListener): AsyncListenerAPI {
+ asyncListenerList.add(t)
+ return this
+ }
+
+ fun remove(t: AsyncListener): AsyncListenerAPI {
+ asyncListenerList.remove(t)
+ return this
+ }
+
+ @EventHandler
+ override fun onPlayerChatEvent(event: PlayerChatEvent) {
+ asyncTaskCallEvent(event, EasyAPI.INSTANCE) {
+ asyncListenerList.forEach { it.onPlayerChatEvent(event) }
+ }
+ }
+
+ @EventHandler
+ override fun onPlayerCommandPreprocessEvent(event: PlayerCommandPreprocessEvent) {
+ asyncTaskCallEvent(event, EasyAPI.INSTANCE) {
+ asyncListenerList.forEach { it.onPlayerCommandPreprocessEvent(event) }
+ }
+ }
+
+ @EventHandler
+ override fun onPlayerDeathEvent(event: PlayerDeathEvent) {
+ asyncTaskCallEvent(event, EasyAPI.INSTANCE) {
+ asyncListenerList.forEach { it.onPlayerDeathEvent(event) }
+ }
+ }
+
+ @EventHandler
+ override fun onPlayerBucketEmptyEvent(event: PlayerBucketEmptyEvent) {
+ asyncTaskCallEvent(event, EasyAPI.INSTANCE) {
+ asyncListenerList.forEach { it.onPlayerBucketEmptyEvent(event) }
+ }
+ }
+
+ @EventHandler
+ override fun onPlayerBucketFillEvent(event: PlayerBucketFillEvent) {
+ asyncTaskCallEvent(event, EasyAPI.INSTANCE) {
+ asyncListenerList.forEach { it.onPlayerBucketFillEvent(event) }
+ }
+ }
+
+ @EventHandler
+ override fun onPlayerDropItemEvent(event: PlayerDropItemEvent) {
+ asyncTaskCallEvent(event, EasyAPI.INSTANCE) {
+ asyncListenerList.forEach { it.onPlayerDropItemEvent(event) }
+ }
+ }
+
+ @EventHandler
+ override fun onPlayerEatFoodEvent(event: PlayerEatFoodEvent) {
+ asyncTaskCallEvent(event, EasyAPI.INSTANCE) {
+ asyncListenerList.forEach { it.onPlayerEatFoodEvent(event) }
+ }
+ }
+
+ @EventHandler
+ override fun onPlayerFoodLevelChangeEvent(event: PlayerFoodLevelChangeEvent) {
+ asyncTaskCallEvent(event, EasyAPI.INSTANCE) {
+ asyncListenerList.forEach { it.onPlayerFoodLevelChangeEvent(event) }
+ }
+ }
+
+ @EventHandler
+ override fun onPlayerFormRespondedEvent(event: PlayerFormRespondedEvent) {
+ asyncTaskCallEvent(event, EasyAPI.INSTANCE) {
+ asyncListenerList.forEach { it.onPlayerFormRespondedEvent(event) }
+ }
+ }
+
+ @EventHandler
+ override fun onPlayerGameModeChangeEvent(event: PlayerGameModeChangeEvent) {
+ asyncTaskCallEvent(event, EasyAPI.INSTANCE) {
+ asyncListenerList.forEach { it.onPlayerGameModeChangeEvent(event) }
+ }
+ }
+
+ @EventHandler
+ override fun onPlayerInteractEntityEvent(event: PlayerInteractEntityEvent) {
+ asyncTaskCallEvent(event, EasyAPI.INSTANCE) {
+ asyncListenerList.forEach { it.onPlayerInteractEntityEvent(event) }
+ }
+ }
+
+ @EventHandler
+ override fun onPlayerInteractEvent(event: PlayerInteractEvent) {
+ asyncTaskCallEvent(event, EasyAPI.INSTANCE) {
+ asyncListenerList.forEach { it.onPlayerInteractEvent(event) }
+ }
+ }
+
+ @EventHandler
+ override fun onPlayerItemHeldEvent(event: PlayerItemHeldEvent) {
+ asyncTaskCallEvent(event, EasyAPI.INSTANCE) {
+ asyncListenerList.forEach { it.onPlayerItemHeldEvent(event) }
+ }
+ }
+
+ @EventHandler
+ override fun onPlayerJoinEvent(event: PlayerJoinEvent) {
+ asyncTaskCallEvent(event, EasyAPI.INSTANCE) {
+ asyncListenerList.forEach { it.onPlayerJoinEvent(event) }
+ }
+ }
+
+ @EventHandler
+ override fun onPlayerLoginEvent(event: PlayerLoginEvent) {
+ asyncTaskCallEvent(event, EasyAPI.INSTANCE) {
+ asyncListenerList.forEach { it.onPlayerLoginEvent(event) }
+ }
+ }
+
+ @EventHandler
+ override fun onPlayerMoveEvent(event: PlayerMoveEvent) {
+ asyncTaskCallEvent(event, EasyAPI.INSTANCE) {
+ asyncListenerList.forEach { it.onPlayerMoveEvent(event) }
+ }
+ }
+
+ @EventHandler
+ override fun onPlayerPreLoginEvent(event: PlayerPreLoginEvent) {
+ asyncTaskCallEvent(event, EasyAPI.INSTANCE) {
+ asyncListenerList.forEach { it.onPlayerPreLoginEvent(event) }
+ }
+ }
+
+ @EventHandler
+ override fun onPlayerQuitEvent(event: PlayerQuitEvent) {
+ asyncTaskCallEvent(event, EasyAPI.INSTANCE) {
+ asyncListenerList.forEach { it.onPlayerQuitEvent(event) }
+ }
+ }
+
+ @EventHandler
+ override fun onPlayerRespawnEvent(event: PlayerRespawnEvent) {
+ asyncTaskCallEvent(event, EasyAPI.INSTANCE) {
+ asyncListenerList.forEach { it.onPlayerRespawnEvent(event) }
+ }
+ }
+
+ @EventHandler
+ override fun onPlayerTeleportEvent(event: PlayerTeleportEvent) {
+ asyncTaskCallEvent(event, EasyAPI.INSTANCE) {
+ asyncListenerList.forEach { it.onPlayerTeleportEvent(event) }
+ }
+ }
+
+ @EventHandler
+ override fun onBlockBreakEvent(event: BlockBreakEvent) {
+ asyncTaskCallEvent(event, EasyAPI.INSTANCE) {
+ asyncListenerList.forEach { it.onBlockBreakEvent(event) }
+ }
+ }
+
+ @EventHandler
+ override fun onBlockPlaceEvent(event: BlockPlaceEvent) {
+ asyncTaskCallEvent(event, EasyAPI.INSTANCE) {
+ asyncListenerList.forEach { it.onBlockPlaceEvent(event) }
+ }
+ }
+
+ @EventHandler
+ override fun onEntityArmorChangeEvent(event: EntityArmorChangeEvent) {
+ asyncTaskCallEvent(event, EasyAPI.INSTANCE) {
+ asyncListenerList.forEach { it.onEntityArmorChangeEvent(event) }
+ }
+ }
+
+ @EventHandler
+ override fun onEntityDamageByEntityEvent(event: EntityDamageByEntityEvent) {
+ asyncTaskCallEvent(event, EasyAPI.INSTANCE) {
+ asyncListenerList.forEach { it.onEntityDamageByEntityEvent(event) }
+ }
+ }
+
+ @EventHandler
+ override fun onEntityDamageEvent(event: EntityDamageEvent) {
+ asyncTaskCallEvent(event, EasyAPI.INSTANCE) {
+ asyncListenerList.forEach { it.onEntityDamageEvent(event) }
+ }
+ }
+
+ @EventHandler
+ override fun onEntityDeathEvent(event: EntityDeathEvent) {
+ asyncTaskCallEvent(event, EasyAPI.INSTANCE) {
+ asyncListenerList.forEach { it.onEntityDeathEvent(event) }
+ }
+ }
+
+ @EventHandler
+ override fun onCraftItemEvent(event: CraftItemEvent) {
+ asyncTaskCallEvent(event, EasyAPI.INSTANCE) {
+ asyncListenerList.forEach { it.onCraftItemEvent(event) }
+ }
+ }
+
+ @EventHandler
+ override fun onInventoryPickupItemEvent(event: InventoryPickupItemEvent) {
+ asyncTaskCallEvent(event, EasyAPI.INSTANCE) {
+ asyncListenerList.forEach { it.onInventoryPickupItemEvent(event) }
+ }
+ }
+
+ @EventHandler
+ override fun onInventoryTransactionEvent(event: InventoryTransactionEvent) {
+ asyncTaskCallEvent(event, EasyAPI.INSTANCE) {
+ asyncListenerList.forEach { it.onInventoryTransactionEvent(event) }
+ }
+ }
+
+ @EventHandler
+ override fun onWeatherChangeEvent(event: WeatherChangeEvent) {
+ asyncTaskCallEvent(event, EasyAPI.INSTANCE) {
+ asyncListenerList.forEach { it.onWeatherChangeEvent(event) }
+ }
+ }
+
+
+}
\ No newline at end of file
diff --git a/src/main/java/top/wetabq/easyapi/api/defaults/SimpleAsyncTaskAPI.kt b/src/main/java/top/wetabq/easyapi/api/defaults/SimpleAsyncTaskAPI.kt
new file mode 100644
index 0000000..58f014a
--- /dev/null
+++ b/src/main/java/top/wetabq/easyapi/api/defaults/SimpleAsyncTaskAPI.kt
@@ -0,0 +1,21 @@
+package top.wetabq.easyapi.api.defaults
+
+import cn.nukkit.scheduler.AsyncTask
+import top.wetabq.easyapi.EasyAPI
+import top.wetabq.easyapi.api.SimpleIntegrateAPI
+
+object SimpleAsyncTaskAPI : SimpleIntegrateAPI {
+
+ fun add(action: () -> Unit): AsyncTask {
+ val task =
+ object: AsyncTask() {
+ override fun onRun() {
+ action()
+ }
+ }
+ EasyAPI.server.scheduler.scheduleAsyncTask(EasyAPI.INSTANCE, task)
+ return task
+ }
+
+
+}
\ No newline at end of file
diff --git a/src/main/java/top/wetabq/easyapi/api/defaults/SimplePluginTaskAPI.kt b/src/main/java/top/wetabq/easyapi/api/defaults/SimplePluginTaskAPI.kt
new file mode 100644
index 0000000..707afa6
--- /dev/null
+++ b/src/main/java/top/wetabq/easyapi/api/defaults/SimplePluginTaskAPI.kt
@@ -0,0 +1,46 @@
+package top.wetabq.easyapi.api.defaults
+
+import cn.nukkit.scheduler.PluginTask
+import top.wetabq.easyapi.EasyAPI
+import top.wetabq.easyapi.api.SimpleIntegrateAPI
+
+object SimplePluginTaskAPI : SimpleIntegrateAPI {
+
+ fun delay(delay: Int, action: (Int) -> Unit): PluginTask {
+ val task =
+ object: PluginTask(EasyAPI.INSTANCE) {
+
+ override fun onRun(currentTick: Int) {
+ action(currentTick)
+ }
+ }
+ EasyAPI.server.scheduler.scheduleDelayedTask(task, delay)
+ return task
+ }
+
+ fun repeating(period: Int, action: (Int) -> Unit): PluginTask {
+ val task =
+ object: PluginTask(EasyAPI.INSTANCE) {
+
+ override fun onRun(currentTick: Int) {
+ action(currentTick)
+ }
+ }
+ EasyAPI.server.scheduler.scheduleRepeatingTask(task, period)
+ return task
+ }
+
+ fun delayRepeating(delay: Int, period: Int, action: (Int) -> Unit): PluginTask {
+ val task =
+ object: PluginTask(EasyAPI.INSTANCE) {
+
+ override fun onRun(currentTick: Int) {
+ action(currentTick)
+ }
+ }
+ EasyAPI.server.scheduler.scheduleDelayedRepeatingTask(task, delay, period)
+ return task
+ }
+
+
+}
\ No newline at end of file
diff --git a/src/main/java/top/wetabq/easyapi/config/encoder/advance/AdvanceCodecEasyConfig.kt b/src/main/java/top/wetabq/easyapi/config/encoder/advance/AdvanceCodecEasyConfig.kt
index 070449f..be69913 100644
--- a/src/main/java/top/wetabq/easyapi/config/encoder/advance/AdvanceCodecEasyConfig.kt
+++ b/src/main/java/top/wetabq/easyapi/config/encoder/advance/AdvanceCodecEasyConfig.kt
@@ -6,7 +6,8 @@ import top.wetabq.easyapi.config.encoder.CodecEasyConfig
abstract class AdvanceCodecEasyConfig(
configName:String,
- plugin: Plugin
+ plugin: Plugin,
+ private val defaultValue: T
) : CodecEasyConfig(configName, plugin),
AdvanceConfigCodec {
@@ -29,4 +30,9 @@ abstract class AdvanceCodecEasyConfig(
configSection.putAll(encodeMap)
}
+ fun safeGetData(key: String): T {
+ if (!simpleConfig.containsKey(key)) simpleConfig[key] = defaultValue
+ return simpleConfig[key]?:defaultValue
+ }
+
}
\ No newline at end of file
diff --git a/src/main/java/top/wetabq/easyapi/config/encoder/advance/SimpleCodecEasyConfig.kt b/src/main/java/top/wetabq/easyapi/config/encoder/advance/SimpleCodecEasyConfig.kt
index 14ab53c..322f19d 100644
--- a/src/main/java/top/wetabq/easyapi/config/encoder/advance/SimpleCodecEasyConfig.kt
+++ b/src/main/java/top/wetabq/easyapi/config/encoder/advance/SimpleCodecEasyConfig.kt
@@ -6,10 +6,11 @@ abstract class SimpleCodecEasyConfig(
configName:String,
val plugin: Plugin,
val clazzT: Class,
+ defaultValue: T,
private val codec: AdvanceConfigCodec = ReflectionConfigCodec(
clazzT
)
-) : AdvanceCodecEasyConfig(configName, plugin) {
+) : AdvanceCodecEasyConfig(configName, plugin, defaultValue) {
override fun encode(obj: T): LinkedHashMap = codec.encode(obj)
diff --git a/src/main/java/top/wetabq/easyapi/listener/AsyncListener.kt b/src/main/java/top/wetabq/easyapi/listener/AsyncListener.kt
index 1269f06..425435a 100644
--- a/src/main/java/top/wetabq/easyapi/listener/AsyncListener.kt
+++ b/src/main/java/top/wetabq/easyapi/listener/AsyncListener.kt
@@ -6,60 +6,72 @@ import cn.nukkit.event.entity.EntityArmorChangeEvent
import cn.nukkit.event.entity.EntityDamageByEntityEvent
import cn.nukkit.event.entity.EntityDamageEvent
import cn.nukkit.event.entity.EntityDeathEvent
+import cn.nukkit.event.inventory.CraftItemEvent
+import cn.nukkit.event.inventory.InventoryPickupItemEvent
+import cn.nukkit.event.inventory.InventoryTransactionEvent
+import cn.nukkit.event.level.WeatherChangeEvent
import cn.nukkit.event.player.*
interface AsyncListener {
- fun onPlayerChatEvent(event: PlayerChatEvent)
+ fun onPlayerChatEvent(event: PlayerChatEvent) {}
- fun onPlayerCommandPreprocessEvent(event: PlayerCommandPreprocessEvent)
+ fun onPlayerCommandPreprocessEvent(event: PlayerCommandPreprocessEvent) {}
- fun onPlayerDeathEvent(event: PlayerDeathEvent)
+ fun onPlayerDeathEvent(event: PlayerDeathEvent) {}
- fun onPlayerBucketEmptyEvent(event: PlayerBucketEmptyEvent)
+ fun onPlayerBucketEmptyEvent(event: PlayerBucketEmptyEvent) {}
- fun onPlayerBucketFillEvent(event: PlayerBucketFillEvent)
+ fun onPlayerBucketFillEvent(event: PlayerBucketFillEvent) {}
- fun onPlayerDropItemEvent(event: PlayerDropItemEvent)
+ fun onPlayerDropItemEvent(event: PlayerDropItemEvent) {}
- fun onPlayerEatFoodEvent(event: PlayerEatFoodEvent)
+ fun onPlayerEatFoodEvent(event: PlayerEatFoodEvent) {}
- fun onPlayerFoodLevelChangeEvent(event: PlayerFoodLevelChangeEvent)
+ fun onPlayerFoodLevelChangeEvent(event: PlayerFoodLevelChangeEvent) {}
- fun onPlayerFormRespondedEvent(event: PlayerFormRespondedEvent)
+ fun onPlayerFormRespondedEvent(event: PlayerFormRespondedEvent) {}
- fun onPlayerGameModeChangeEvent(event: PlayerGameModeChangeEvent)
+ fun onPlayerGameModeChangeEvent(event: PlayerGameModeChangeEvent) {}
- fun onPlayerInteractEntityEvent(event: PlayerInteractEntityEvent)
+ fun onPlayerInteractEntityEvent(event: PlayerInteractEntityEvent) {}
- fun onPlayerInteractEvent(event: PlayerInteractEvent)
+ fun onPlayerInteractEvent(event: PlayerInteractEvent) {}
- fun onPlayerItemHeldEvent(event: PlayerItemHeldEvent)
+ fun onPlayerItemHeldEvent(event: PlayerItemHeldEvent) {}
- fun onPlayerJoinEvent(event: PlayerJoinEvent)
+ fun onPlayerJoinEvent(event: PlayerJoinEvent) {}
- fun onPlayerLoginEvent(event: PlayerLoginEvent)
+ fun onPlayerLoginEvent(event: PlayerLoginEvent) {}
- fun onPlayerMoveEvent(event: PlayerMoveEvent)
+ fun onPlayerMoveEvent(event: PlayerMoveEvent) {}
- fun onPlayerPreLoginEvent(event: PlayerPreLoginEvent)
+ fun onPlayerPreLoginEvent(event: PlayerPreLoginEvent) {}
- fun onPlayerQuitEvent(event: PlayerQuitEvent)
+ fun onPlayerQuitEvent(event: PlayerQuitEvent) {}
- fun onPlayerRespawnEvent(event: PlayerRespawnEvent)
+ fun onPlayerRespawnEvent(event: PlayerRespawnEvent) {}
- fun onPlayerTeleportEvent(event: PlayerTeleportEvent)
+ fun onPlayerTeleportEvent(event: PlayerTeleportEvent) {}
- fun onBlockBreakEvent(event: BlockBreakEvent)
+ fun onBlockBreakEvent(event: BlockBreakEvent) {}
- fun onBlockPlaceEvent(event: BlockPlaceEvent)
+ fun onBlockPlaceEvent(event: BlockPlaceEvent) {}
- fun onEntityArmorChangeEvent(event: EntityArmorChangeEvent)
+ fun onEntityArmorChangeEvent(event: EntityArmorChangeEvent) {}
- fun onEntityDamageByEntityEvent(event: EntityDamageByEntityEvent)
+ fun onEntityDamageByEntityEvent(event: EntityDamageByEntityEvent) {}
- fun onEntityDamageEvent(event: EntityDamageEvent)
+ fun onEntityDamageEvent(event: EntityDamageEvent) {}
- fun onEntityDeathEvent(event: EntityDeathEvent)
+ fun onEntityDeathEvent(event: EntityDeathEvent) {}
+
+ fun onCraftItemEvent(event: CraftItemEvent) {}
+
+ fun onInventoryPickupItemEvent(event: InventoryPickupItemEvent) {}
+
+ fun onInventoryTransactionEvent(event: InventoryTransactionEvent) {}
+
+ fun onWeatherChangeEvent(event: WeatherChangeEvent) {}
}
\ No newline at end of file