Skip to content

Commit

Permalink
style: 修改路径
Browse files Browse the repository at this point in the history
  • Loading branch information
limbang committed Jun 5, 2022
1 parent cde31ec commit aac3b59
Show file tree
Hide file tree
Showing 12 changed files with 215 additions and 113 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish-release-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ jobs:
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: build/mirai/mirai-console-minecraft-plugin-${{ steps.vars.outputs.version }}.mirai.jar
file: build/mirai/mirai-console-minecraft-plugin-${{ steps.vars.outputs.version }}.mirai2.jar
tag: ${{ github.ref }}

138 changes: 123 additions & 15 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,19 +1,127 @@
# mirai
bots/
config/
data/
plugins/
local.properties

# Gradle
# User-specific stuff
.idea/

# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

.gradle
build/

# Ignore Gradle GUI config
gradle-app.setting

# Cache of project
.gradletasknamecache

**/build/
!src/**/build/

# Idea
.idea/*.xml
*.iml
!.idea/copyright/
# Common working directory
run/

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar


# Local Test Launch point
#src/test/kotlin/RunTerminal.kt

# Mirai console files with direct bootstrap
/config
/data
/plugins
/bots

# mac os
.DS_Store
# Local Test Launch Point working directory
/debug-sandbox
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
* https://github.com/limbang/mirai-console-minecraft-plugin/blob/master/LICENSE
*/

package top.limbang.mirai.minecraft

package top.limbang.minecraft

import net.mamoe.mirai.console.command.CommandManager.INSTANCE.register
import net.mamoe.mirai.console.command.CommandManager.INSTANCE.unregister
Expand All @@ -19,34 +18,33 @@ import net.mamoe.mirai.contact.nameCardOrNick
import net.mamoe.mirai.event.events.NudgeEvent
import net.mamoe.mirai.event.globalEventChannel
import net.mamoe.mirai.event.subscribeGroupMessages
import top.limbang.mirai.minecraft.service.ImageService.createErrorImage
import top.limbang.mirai.minecraft.service.ServerService.getServerList
import top.limbang.mirai.minecraft.service.ServerService.getTPS
import top.limbang.mirai.minecraft.service.ServerService.pingALlServer
import top.limbang.mirai.minecraft.service.ServerService.pingServer

import top.limbang.minecraft.service.ImageService.createErrorImage
import top.limbang.minecraft.service.ServerService.getServerList
import top.limbang.minecraft.service.ServerService.getTPS
import top.limbang.minecraft.service.ServerService.pingALlServer
import top.limbang.minecraft.service.ServerService.pingServer

object MiraiConsoleMinecraftPlugin : KotlinPlugin(
object Minecraft : KotlinPlugin(
JvmPluginDescription(
id = "top.limbang.minecraft",
name = "minecraft",
version = "1.1.8",
version = "1.1.9",
) {
author("limbang")
info("""Minecraft插件""")
}
) {
override fun onDisable() {
MinecraftPluginCompositeCommand.unregister()
PluginCompositeCommand.unregister()
}

override fun onEnable() {
MinecraftPluginData.reload()
MinecraftPluginCompositeCommand.register()
val ping = MinecraftPluginData.commandMap[CommandName.PING] ?: "!"
val list = MinecraftPluginData.commandMap[CommandName.LIST] ?: "!list"
val tps = MinecraftPluginData.commandMap[CommandName.TPS] ?: "!tps"
val pingAll = MinecraftPluginData.commandMap[CommandName.PING_ALL] ?: "!all"
PluginData.reload()
PluginCompositeCommand.register()
val ping = PluginData.commandMap[CommandName.PING] ?: "!"
val list = PluginData.commandMap[CommandName.LIST] ?: "!list"
val tps = PluginData.commandMap[CommandName.TPS] ?: "!tps"
val pingAll = PluginData.commandMap[CommandName.PING_ALL] ?: "!all"

globalEventChannel().subscribeGroupMessages {
case(list) quoteReply { getServerList() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* https://github.com/limbang/mirai-console-minecraft-plugin/blob/master/LICENSE
*/

package top.limbang.mirai.minecraft
package top.limbang.minecraft

import net.mamoe.mirai.console.command.CommandSender
import net.mamoe.mirai.console.command.CompositeCommand
Expand All @@ -17,13 +17,11 @@ import net.mamoe.mirai.console.command.getGroupOrNull
/**
* ### 插件指令
*/
object MinecraftPluginCompositeCommand : CompositeCommand(
MiraiConsoleMinecraftPlugin, "mc"
) {
object PluginCompositeCommand : CompositeCommand(Minecraft, "mc") {
@SubCommand
@Description("设置触发指令")
suspend fun CommandSender.setCommand(name: CommandName, command: String) {
MinecraftPluginData.commandMap[name] = command
PluginData.commandMap[name] = command
sendMessage("配置[$name]触发指令[$command],需重启机器人生效.")
}

Expand All @@ -32,7 +30,7 @@ object MinecraftPluginCompositeCommand : CompositeCommand(
@Description("查看登陆信息")
suspend fun CommandSender.loginInfo() {
var loginInfo = ""
MinecraftPluginData.loginMap.forEach {
PluginData.loginMap.forEach {
loginInfo += "[${it.key}] "
}
if (loginInfo.isEmpty())
Expand All @@ -52,14 +50,14 @@ object MinecraftPluginCompositeCommand : CompositeCommand(
return
}
LoginInfo(authServerUrl, sessionServerUrl, username, password)
.also { MinecraftPluginData.loginMap[name] = it }
.also { PluginData.loginMap[name] = it }
sendMessage("[$name]登陆配置添加成功.")
}

@SubCommand
@Description("删除登陆信息")
suspend fun CommandSender.deleteLogin(name: String) {
if (MinecraftPluginData.loginMap.keys.remove(name)) {
if (PluginData.loginMap.keys.remove(name)) {
sendMessage("登陆配置[$name]删除成功.")
} else {
sendMessage("登陆配置[$name]删除失败.")
Expand All @@ -69,27 +67,27 @@ object MinecraftPluginCompositeCommand : CompositeCommand(
@SubCommand
@Description("添加服务器,端口默认 25565")
suspend fun CommandSender.addServer(name: String, address: String, port: Int = 25565) {
MinecraftPluginData.serverMap[name] = ServerAddress(address, port, null)
PluginData.serverMap[name] = ServerAddress(address, port, null)
sendMessage("服务器[$name]添加成功.")
}

@SubCommand
@Description("添加带登陆信息带服务器,端口默认 25565")
suspend fun CommandSender.addServerLogin(loginName: String ,name: String, address: String, port: Int = 25565) {
val loginInfo = MinecraftPluginData.loginMap[loginName]
val loginInfo = PluginData.loginMap[loginName]
if (loginInfo == null) {
sendMessage("[$loginName]该登陆信息尚未配置.")
return
}

MinecraftPluginData.serverMap[name] = ServerAddress(address, port, loginInfo)
PluginData.serverMap[name] = ServerAddress(address, port, loginInfo)
sendMessage("服务器[$name]添加成功.")
}

@SubCommand
@Description("删除服务器")
suspend fun CommandSender.deleteServer(name: String) {
if (MinecraftPluginData.serverMap.keys.remove(name)) {
if (PluginData.serverMap.keys.remove(name)) {
sendMessage("服务器[$name]删除成功.")
} else {
sendMessage("服务器[$name]删除失败.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* https://github.com/limbang/mirai-console-minecraft-plugin/blob/master/LICENSE
*/

package top.limbang.mirai.minecraft
package top.limbang.minecraft

import kotlinx.serialization.Serializable
import net.mamoe.mirai.console.data.AutoSavePluginData
Expand Down Expand Up @@ -47,7 +47,7 @@ enum class CommandName{
/**
* ### 插件配置
*/
object MinecraftPluginData : AutoSavePluginData("minecraft") {
object PluginData : AutoSavePluginData("minecraft") {
var serverMap: MutableMap<String, ServerAddress> by value()
var loginMap: MutableMap<String, LoginInfo> by value()
var commandMap: MutableMap<CommandName, String> by value()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* https://github.com/limbang/mirai-console-minecraft-plugin/blob/master/LICENSE
*/

package top.limbang.mirai.minecraft.extension
package top.limbang.minecraft.extension

import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* https://github.com/limbang/mirai-console-minecraft-plugin/blob/master/LICENSE
*/

package top.limbang.mirai.minecraft.extension
package top.limbang.minecraft.extension


import java.awt.BasicStroke
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
* https://github.com/limbang/mirai-console-minecraft-plugin/blob/master/LICENSE
*/

package top.limbang.mirai.minecraft.service
package top.limbang.minecraft.service

import top.limbang.mirai.minecraft.MiraiConsoleMinecraftPlugin
import top.limbang.mirai.minecraft.extension.addSubtitles
import top.limbang.mirai.minecraft.extension.readImage
import top.limbang.mirai.minecraft.extension.toInput
import top.limbang.minecraft.Minecraft
import top.limbang.minecraft.extension.addSubtitles
import top.limbang.minecraft.extension.readImage
import top.limbang.minecraft.extension.toInput
import java.io.ByteArrayInputStream

object ImageService {
Expand Down Expand Up @@ -43,7 +43,7 @@ object ImageService {
*/
fun createSubtitlesImage(subtitles: String, resourceName: String): ByteArrayInputStream {
val resourceImageStream =
MiraiConsoleMinecraftPlugin.getResourceAsStream(resourceName) ?: throw RuntimeException("读取不到资源文件.")
Minecraft.getResourceAsStream(resourceName) ?: throw RuntimeException("读取不到资源文件.")
val image = resourceImageStream.use { resourceImageStream -> resourceImageStream.readImage() }
return image.addSubtitles(subtitles).toInput()
}
Expand Down
Loading

0 comments on commit aac3b59

Please sign in to comment.