2021-12-11 18:55:57 +09:00
|
|
|
// React
|
2021-05-30 12:55:44 +09:00
|
|
|
import React, { useState, useEffect } from 'react';
|
2021-12-11 18:55:57 +09:00
|
|
|
|
|
|
|
// i18n
|
|
|
|
import { useTranslation, useLanguageQuery } from 'next-export-i18n';
|
|
|
|
|
2021-05-30 12:55:44 +09:00
|
|
|
import axios from 'axios';
|
|
|
|
|
|
|
|
export default function Minecraft(props) {
|
2021-12-11 18:55:57 +09:00
|
|
|
const { t } = useTranslation();
|
|
|
|
const [query] = useLanguageQuery();
|
2021-05-30 12:55:44 +09:00
|
|
|
const [data, setData] = useState({ hits: [] });
|
2021-06-14 12:36:18 +09:00
|
|
|
|
2021-05-30 12:55:44 +09:00
|
|
|
useEffect(() => {
|
|
|
|
const fetchData = async () => {
|
|
|
|
const result = await axios(
|
2021-05-31 10:03:55 +09:00
|
|
|
'https://api.mcsrvstat.us/2/yude.jp',
|
2021-05-30 12:55:44 +09:00
|
|
|
);
|
|
|
|
setData(result.data);
|
|
|
|
};
|
|
|
|
fetchData();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
if (data === undefined){
|
|
|
|
console.log("[Minecraft Query] データの取得に失敗しました。 / Failed to retrieve data.")
|
|
|
|
return (
|
2021-12-11 18:55:57 +09:00
|
|
|
<p>{t('fail')}</p>
|
2021-05-30 12:55:44 +09:00
|
|
|
)
|
|
|
|
}else{
|
2021-05-30 13:31:17 +09:00
|
|
|
const status = data.online
|
2021-05-30 13:37:20 +09:00
|
|
|
const player = data.players && data.players.online
|
2021-06-14 12:36:18 +09:00
|
|
|
|
2021-05-30 12:55:44 +09:00
|
|
|
return (
|
2021-06-02 08:23:02 +09:00
|
|
|
<div className="text-center">
|
2021-05-30 12:55:44 +09:00
|
|
|
{(() => {
|
2021-05-31 09:59:14 +09:00
|
|
|
if (status == true) {
|
2021-05-30 13:37:20 +09:00
|
|
|
if (player == undefined || player == 0) {
|
2021-12-11 18:55:57 +09:00
|
|
|
return <span>{t('no_one')}</span>
|
2021-05-30 12:55:44 +09:00
|
|
|
} else {
|
2021-12-11 18:55:57 +09:00
|
|
|
return <span>{t('playing', {count: player})}</span>
|
2021-05-31 09:59:14 +09:00
|
|
|
}}else if (status == false) {
|
2021-12-11 18:55:57 +09:00
|
|
|
return <span>{t('offline')}</span>
|
2021-05-31 09:59:14 +09:00
|
|
|
}else {
|
2021-12-11 18:55:57 +09:00
|
|
|
return <span>{t('loading')}</span>
|
2021-05-30 12:55:44 +09:00
|
|
|
}
|
|
|
|
})()}
|
2021-06-02 08:23:02 +09:00
|
|
|
|
2021-06-02 08:15:01 +09:00
|
|
|
{(() => {
|
|
|
|
if (data.players && data.players.list){
|
|
|
|
var list = [];
|
|
|
|
var url = [];
|
|
|
|
for (var i in data.players.list){
|
|
|
|
url.push('https://mc-heads.net/avatar/' + data.players.list[i])
|
|
|
|
}
|
|
|
|
for (var i in url){
|
2021-12-11 19:19:50 +09:00
|
|
|
list.push(<img src={url[i]} key={i} className="inline" height="50" width="50" alt={i}/>)
|
2021-06-02 08:15:01 +09:00
|
|
|
}
|
|
|
|
return <div>{list}</div>
|
|
|
|
}
|
|
|
|
})()}
|
2021-06-02 08:23:02 +09:00
|
|
|
</div>
|
2021-05-30 12:55:44 +09:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|