0
0
mirror of https://github.com/yude-jp/yude.jp synced 2024-12-21 19:50:10 +09:00

Add page "minecraft/"

This commit is contained in:
yude 2021-05-30 12:55:44 +09:00
parent c8c40d1257
commit 3400be0357
Signed by: yude
GPG Key ID: EB0FE5D925C4A968
7 changed files with 93 additions and 1 deletions

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"git.ignoreLimitWarning": true
}

View File

@ -8,6 +8,7 @@
"/status": ["status", "common"],
"/house": ["house", "common"],
"/tos": ["tos", "common"],
"/hcunews": ["hcunews", "common"]
"/hcunews": ["hcunews", "common"],
"/minecraft": ["minecraft", "common"]
}
}

View File

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

View File

@ -0,0 +1,5 @@
{
"title": "Minecraft マルチプレイ",
"playing": "{{count}} 人がプレイしています。",
"no_one": "現在、誰もログインしていません。"
}

View File

@ -0,0 +1,47 @@
import React, { useState, useEffect } from 'react';
import useTranslation from 'next-translate/useTranslation'
import { useRouter } from 'next/router'
import axios from 'axios';
export default function Minecraft(props) {
const router = useRouter()
const { locale, locales, defaultLocale, pathname } = router
const { t, lang } = useTranslation("minecraft")
const [dataMinecraft, setDataMinecraft] = useState({ hits: [] });
const [data, setData] = useState({ hits: [] });
useEffect(() => {
const fetchData = async () => {
const result = await axios(
'https://mcapi.us/server/status?ip=yude.jp',
);
setData(result.data);
};
fetchData();
}, []);
if (data === undefined){
console.log("[Minecraft Query] データの取得に失敗しました。 / Failed to retrieve data.")
console.log(data)
return (
<p>Failed to retrieve data</p>
)
}else{
console.log(data)
const player = data.players && data.players.now
const playing = t('minecraft:playing', {count: player})
const no_one = t('minecraft:no_one')
return (
<p className="text-center">
{(() => {
if (player == 0) {
return <span>{no_one}</span>
} else {
return <span>{playing}</span>
}
})()}
</p>
)
}
}

31
pages/minecraft.js Normal file
View File

@ -0,0 +1,31 @@
import React, { useState, useEffect } from 'react';
import Layout from "./components/Layout"
import useTranslation from 'next-translate/useTranslation'
import { useRouter } from 'next/router'
import Minecraft from './components/Minecraft'
import Image from 'next/image'
export default function About(props) {
const router = useRouter()
const { locale, locales, defaultLocale, pathname } = router
const { t, lang } = useTranslation("minecraft")
const title = t('title')
return (
<Layout title={title}>
<div>
<p className="my-2 text-3xl text-center">{title}</p>
<div className="w-full">
<Image
src = "/static/images/dynmap.png"
alt = "Dynmap Header"
unoptimized = {true}
width = {1354}
height = {619}
/>
</div>
<Minecraft />
</div>
</Layout>
)
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB