diff --git a/python-server/requirements.txt b/python-server/requirements.txt new file mode 100644 index 0000000..f0615cf --- /dev/null +++ b/python-server/requirements.txt @@ -0,0 +1,2 @@ +fastapi +uvicorn \ No newline at end of file diff --git a/python-server/server.py b/python-server/server.py new file mode 100644 index 0000000..51aaafc --- /dev/null +++ b/python-server/server.py @@ -0,0 +1,25 @@ +import winsound +from fastapi import FastAPI, HTTPException +import uvicorn + +app = FastAPI() + +@app.get("/notify/startup") +@app.post("/notify/startup") +async def notify_startup(): + """マイクラの起動通知を受け取るエンドポイント""" + print("🔔 マイクラの起動通知を受け取りました!") + + try: + winsound.Beep(1000, 200) # 1回目 + winsound.Beep(1500, 300) # 2回目(高めの音) + except Exception as e: + print(f"⚠️ 音の再生に失敗しました: {e}") + + return {"status": "success", "message": "通知を受け取り、音を鳴らしました!"} + + +if __name__ == "__main__": + # ローカルのポート 8000番 でサーバーを起動します + print("🚀 Python通知サーバーを起動します... (http://localhost:8000/notify/startup)") + uvicorn.run(app, host="0.0.0.0", port=8000) \ No newline at end of file diff --git a/src/main/kotlin/com/github/ringoame196_s_mcPlugin/core/Main.kt b/src/main/kotlin/com/github/ringoame196_s_mcPlugin/core/Main.kt index 642b1ad..1598e4d 100644 --- a/src/main/kotlin/com/github/ringoame196_s_mcPlugin/core/Main.kt +++ b/src/main/kotlin/com/github/ringoame196_s_mcPlugin/core/Main.kt @@ -14,7 +14,7 @@ class Main : JavaPlugin() { plugin.saveDefaultConfig() // configファイル生成 - server.pluginManager.registerEvents(Events(), plugin) + server.pluginManager.registerEvents(Events(plugin), plugin) // コマンド val devCommand = getCommand("dev") diff --git a/src/main/kotlin/com/github/ringoame196_s_mcPlugin/events/Events.kt b/src/main/kotlin/com/github/ringoame196_s_mcPlugin/events/Events.kt index bc36c85..c54d660 100644 --- a/src/main/kotlin/com/github/ringoame196_s_mcPlugin/events/Events.kt +++ b/src/main/kotlin/com/github/ringoame196_s_mcPlugin/events/Events.kt @@ -1,5 +1,15 @@ package com.github.ringoame196_s_mcPlugin.events +import com.github.ringoame196_s_mcPlugin.notion.NotifierServerStart +import org.bukkit.event.EventHandler import org.bukkit.event.Listener +import org.bukkit.event.server.ServerLoadEvent +import org.bukkit.plugin.Plugin -class Events : Listener +class Events(private val plugin: Plugin) : Listener { + @EventHandler + fun onServerLoad(e: ServerLoadEvent) { + val notionURL = plugin.config.getString("NotionURL") ?: return + NotifierServerStart.notifier(notionURL) + } +} diff --git a/src/main/kotlin/com/github/ringoame196_s_mcPlugin/notion/NotifierServerStart.kt b/src/main/kotlin/com/github/ringoame196_s_mcPlugin/notion/NotifierServerStart.kt new file mode 100644 index 0000000..0c33104 --- /dev/null +++ b/src/main/kotlin/com/github/ringoame196_s_mcPlugin/notion/NotifierServerStart.kt @@ -0,0 +1,24 @@ +package com.github.ringoame196_s_mcPlugin.notion + +import java.net.HttpURLConnection +import java.net.URL + +object NotifierServerStart { + fun notifier(urlText: String) { + Thread { + try { + val url = URL(urlText) + val conn = url.openConnection() as HttpURLConnection + conn.requestMethod = "POST" + conn.connectTimeout = 3000 // 接続タイムアウト(ms) + conn.readTimeout = 3000 // 読み込みタイムアウト(ms) + + val responseCode = conn.responseCode + println("通知送信結果: $responseCode") + conn.disconnect() + } catch (e: Exception) { + println("⚠️ Pythonサーバーへの通知に失敗しました: ${e.message}") + } + }.start() + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 92f5087..825f874 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,2 +1,3 @@ Port: 25585 -ReloadCommand : "pluginmanager reload @pluginName" \ No newline at end of file +ReloadCommand : "pluginmanager reload @pluginName" +NotionURL : "" \ No newline at end of file