import React, { useEffect, useState } from 'react'; import { ServerContext } from '@/state/server'; import Modal from '@/components/elements/Modal'; import tw from 'twin.macro'; import Button from '@/components/elements/Button'; import saveFileContents from '@/api/server/files/saveFileContents'; import FlashMessageRender from '@/components/FlashMessageRender'; import useFlash from '@/plugins/useFlash'; const EulaModalFeature = () => { const [ visible, setVisible ] = useState(false); const [ loading, setLoading ] = useState(false); const uuid = ServerContext.useStoreState(state => state.server.data!.uuid); const status = ServerContext.useStoreState(state => state.status.value); const { clearFlashes, clearAndAddHttpError } = useFlash(); const { connected, instance } = ServerContext.useStoreState(state => state.socket); useEffect(() => { if (!connected || !instance || status === 'running') return; const listener = (line: string) => { if (line.toLowerCase().indexOf('you need to agree to the eula in order to run the server') >= 0) { setVisible(true); } }; instance.addListener('console output', listener); return () => { instance.removeListener('console output', listener); }; }, [ connected, instance, status ]); const onAcceptEULA = () => { setLoading(true); clearFlashes('feature:eula'); saveFileContents(uuid, 'eula.txt', 'eula=true') .then(() => { if (status === 'offline' && instance) { instance.send('set state', 'restart'); } setLoading(false); setVisible(false); }) .catch(error => { console.error(error); clearAndAddHttpError({ key: 'feature:eula', error }); }) .then(() => setLoading(false)); }; useEffect(() => () => { clearFlashes('feature:eula'); }, []); return ( !visible ? null : setVisible(false)} closeOnBackground={false} showSpinnerOverlay={loading}>

Accept Minecraft® EULA

By pressing {'"I Accept"'} below you are indicating your agreement to the  Minecraft® EULA .

); }; export default EulaModalFeature;