Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions python-server/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fastapi
uvicorn
25 changes: 25 additions & 0 deletions python-server/server.py
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -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()
}
}
3 changes: 2 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Port: 25585
ReloadCommand : "pluginmanager reload @pluginName"
ReloadCommand : "pluginmanager reload @pluginName"
NotionURL : ""
Loading