0
0
mirror of https://github.com/yude-jp/yude.jp synced 2024-06-09 23:36:01 +09:00

Change API source, Add server address

This commit is contained in:
yude 2021-05-30 13:31:17 +09:00
parent 3400be0357
commit b532bb04d3
Signed by: yude
GPG Key ID: EB0FE5D925C4A968
4 changed files with 15 additions and 5 deletions

View File

@ -1,5 +1,7 @@
{
"title": "Minecraft Multiplayer",
"playing": "{{count}} player(s) online.",
"no_one": "No one is playing."
"no_one": "No one is playing.",
"offline": "Server is down.",
"address": "Server address"
}

View File

@ -1,5 +1,7 @@
{
"title": "Minecraft マルチプレイ",
"playing": "{{count}} 人がプレイしています。",
"no_one": "現在、誰もログインしていません。"
"no_one": "現在、誰もログインしていません。",
"offline": "サーバーがオフラインのようです。",
"address": "サーバー アドレス"
}

View File

@ -14,7 +14,7 @@ export default function Minecraft(props) {
useEffect(() => {
const fetchData = async () => {
const result = await axios(
'https://mcapi.us/server/status?ip=yude.jp',
'https://eu.mc-api.net/v3/server/ping/yude.jp',
);
setData(result.data);
};
@ -29,16 +29,21 @@ export default function Minecraft(props) {
)
}else{
console.log(data)
const status = data.online
const player = data.players && data.players.now
const playing = t('minecraft:playing', {count: player})
const no_one = t('minecraft:no_one')
const offline = t('minecraft:offline')
return (
<p className="text-center">
{(() => {
if (player == 0) {
if (status) {
if (player == undefined) {
return <span>{no_one}</span>
} else {
return <span>{playing}</span>
}}else{
return <span>{offline}</span>
}
})()}
</p>

View File

@ -10,7 +10,7 @@ export default function About(props) {
const { locale, locales, defaultLocale, pathname } = router
const { t, lang } = useTranslation("minecraft")
const title = t('title')
const address = t('address')
return (
<Layout title={title}>
<div>
@ -25,6 +25,7 @@ export default function About(props) {
/>
</div>
<Minecraft />
<p className="text-center">{address}: <code>yude.jp</code></p>
</div>
</Layout>
)