This repository has been archived by the owner on Dec 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.1.0 add task api, fix screen show bug
- Loading branch information
Showing
11 changed files
with
118 additions
and
66 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
28 changes: 28 additions & 0 deletions
28
src/main/java/top/wetabq/easyapi/api/CommonDynamicIntegrateAPI.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,28 @@ | ||
package top.wetabq.easyapi.api | ||
|
||
|
||
abstract class CommonDynamicIntegrateAPI<T, out I: DynamicIntegrateAPI<*, I>> : DynamicIntegrateAPI<T, I> { | ||
|
||
protected val interfaceList = arrayListOf<T>() | ||
|
||
override fun add(t: T): I { | ||
interfaceList.add(t) | ||
return addInterface(t) | ||
} | ||
|
||
override fun remove(t: T): I { | ||
interfaceList.remove(t) | ||
return removeInterface(t) | ||
} | ||
|
||
abstract fun addInterface(t: T): I | ||
|
||
abstract fun removeInterface(t: T): I | ||
|
||
override fun getAll(): Collection<T> = interfaceList | ||
|
||
override fun removeAll() { | ||
interfaceList.forEach { remove(it) } | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/top/wetabq/easyapi/api/default/AsyncTaskAPI.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 top.wetabq.easyapi.api.default | ||
|
||
import cn.nukkit.Server | ||
import cn.nukkit.plugin.Plugin | ||
import cn.nukkit.scheduler.AsyncTask | ||
import top.wetabq.easyapi.api.CommonDynamicIntegrateAPI | ||
|
||
class AsyncTaskAPI(private val plugin: Plugin) : CommonDynamicIntegrateAPI<AsyncTask, AsyncTaskAPI>() { | ||
|
||
override fun addInterface(t: AsyncTask): AsyncTaskAPI { | ||
Server.getInstance().scheduler.scheduleAsyncTask(plugin, t) | ||
return this | ||
} | ||
|
||
override fun removeInterface(t: AsyncTask): AsyncTaskAPI { | ||
Server.getInstance().scheduler.scheduleAsyncTask(plugin, t) | ||
return this | ||
} | ||
|
||
|
||
} |
20 changes: 4 additions & 16 deletions
20
src/main/java/top/wetabq/easyapi/api/default/CommandAPI.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,32 +1,20 @@ | ||
package top.wetabq.easyapi.api.default | ||
|
||
import cn.nukkit.Server | ||
import top.wetabq.easyapi.api.DynamicIntegrateAPI | ||
import top.wetabq.easyapi.api.CommonDynamicIntegrateAPI | ||
import top.wetabq.easyapi.command.EasyCommand | ||
|
||
class CommandAPI: DynamicIntegrateAPI<EasyCommand, CommandAPI> { | ||
class CommandAPI: CommonDynamicIntegrateAPI<EasyCommand, CommandAPI>() { | ||
|
||
private val commandList = arrayListOf<EasyCommand>() | ||
|
||
override fun add(t: EasyCommand): CommandAPI { | ||
commandList.add(t) | ||
override fun addInterface(t: EasyCommand): CommandAPI { | ||
Server.getInstance().commandMap.register( "", t) | ||
return this | ||
} | ||
|
||
override fun remove(t: EasyCommand): CommandAPI { | ||
override fun removeInterface(t: EasyCommand): CommandAPI { | ||
// NOT SUPPORT ACTUALLY REMOVE | ||
commandList.remove(t) | ||
return this | ||
} | ||
|
||
override fun getAll(): Collection<EasyCommand> { | ||
return commandList | ||
} | ||
|
||
override fun removeAll() { | ||
commandList.forEach { t -> remove(t) } | ||
} | ||
|
||
|
||
} |
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,26 +1,18 @@ | ||
package top.wetabq.easyapi.api.default | ||
|
||
import top.wetabq.easyapi.api.DynamicIntegrateAPI | ||
import top.wetabq.easyapi.api.CommonDynamicIntegrateAPI | ||
import top.wetabq.easyapi.config.EasyConfig | ||
|
||
class ConfigAPI: DynamicIntegrateAPI<EasyConfig, ConfigAPI> { | ||
class ConfigAPI: CommonDynamicIntegrateAPI<EasyConfig, ConfigAPI>() { | ||
|
||
private val configList = arrayListOf<EasyConfig>() | ||
|
||
override fun add(t: EasyConfig): ConfigAPI { | ||
configList.add(t) | ||
override fun addInterface(t: EasyConfig): ConfigAPI { | ||
return this | ||
} | ||
|
||
override fun remove(t: EasyConfig): ConfigAPI { | ||
override fun removeInterface(t: EasyConfig): ConfigAPI { | ||
t.save() | ||
return this | ||
} | ||
|
||
override fun getAll(): Collection<EasyConfig> = configList | ||
|
||
override fun removeAll() { | ||
configList.forEach { t -> remove(t) } | ||
} | ||
|
||
} |
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
21 changes: 21 additions & 0 deletions
21
src/main/java/top/wetabq/easyapi/api/default/PluginTaskAPI.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 top.wetabq.easyapi.api.default | ||
|
||
import cn.nukkit.Server | ||
import cn.nukkit.plugin.Plugin | ||
import top.wetabq.easyapi.api.CommonDynamicIntegrateAPI | ||
import top.wetabq.easyapi.task.PluginTaskEntry | ||
|
||
class PluginTaskAPI<T: Plugin>(private val plugin: Plugin) : CommonDynamicIntegrateAPI<PluginTaskEntry<T>, PluginTaskAPI<T>>() { | ||
|
||
override fun addInterface(t: PluginTaskEntry<T>): PluginTaskAPI<T> { | ||
Server.getInstance().scheduler.scheduleDelayedRepeatingTask(plugin, t.pluginTask, t.delay, t.period) | ||
return this | ||
} | ||
|
||
override fun removeInterface(t: PluginTaskEntry<T>): PluginTaskAPI<T> { | ||
Server.getInstance().scheduler.cancelTask(t.pluginTask.taskId) | ||
return this | ||
} | ||
|
||
|
||
} |
16 changes: 4 additions & 12 deletions
16
src/main/java/top/wetabq/easyapi/api/default/SimpleCommandAPI.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,25 @@ | ||
package top.wetabq.easyapi.api.default | ||
|
||
import top.wetabq.easyapi.api.DynamicIntegrateAPI | ||
import top.wetabq.easyapi.api.CommonDynamicIntegrateAPI | ||
import top.wetabq.easyapi.command.EasySubCommand | ||
import top.wetabq.easyapi.command.default.EasyAPICommand | ||
|
||
/** | ||
* Use EasyAPIModule build-in command to add sub-command | ||
* Usage: /eapi | ||
*/ | ||
class SimpleCommandAPI : DynamicIntegrateAPI<EasySubCommand, SimpleCommandAPI> { | ||
class SimpleCommandAPI : CommonDynamicIntegrateAPI<EasySubCommand, SimpleCommandAPI>() { | ||
|
||
private val commandList = arrayListOf<EasySubCommand>() | ||
|
||
override fun add(t: EasySubCommand): SimpleCommandAPI { | ||
override fun addInterface(t: EasySubCommand): SimpleCommandAPI { | ||
EasyAPICommand.subCommand.add(t) | ||
EasyAPICommand.loadCommandBase() | ||
return this | ||
} | ||
|
||
override fun remove(t: EasySubCommand): SimpleCommandAPI { | ||
override fun removeInterface(t: EasySubCommand): SimpleCommandAPI { | ||
EasyAPICommand.subCommand.remove(t) | ||
EasyAPICommand.loadCommandBase() | ||
return this | ||
} | ||
|
||
override fun getAll(): Collection<EasySubCommand> = commandList | ||
|
||
override fun removeAll() { | ||
commandList.forEach { t -> remove(t) } | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package top.wetabq.easyapi.task | ||
|
||
import cn.nukkit.plugin.Plugin | ||
import cn.nukkit.scheduler.PluginTask | ||
|
||
data class PluginTaskEntry<T: Plugin> ( | ||
var pluginTask: PluginTask<T>, | ||
var period: Int, | ||
var delay: Int = 0 | ||
) |