MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
# How-To 2: Controlling Minecraft server
|
|
|
|
|
2022-12-25 19:17:49 +04:00
|
|
|
In the previous part we've logged into an account and have started a server.
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
But python-aternos can do much more.
|
|
|
|
|
|
|
|
## Basic methods
|
|
|
|
```python
|
|
|
|
from python_aternos import Client
|
|
|
|
|
|
|
|
at = Client.from_credentials('username', 'password')
|
|
|
|
serv = at.list_servers()[0]
|
|
|
|
|
|
|
|
# Start
|
|
|
|
serv.start()
|
|
|
|
|
|
|
|
# Stop
|
|
|
|
serv.stop()
|
|
|
|
|
|
|
|
# Restart
|
|
|
|
serv.restart()
|
|
|
|
|
|
|
|
# Cancel starting
|
|
|
|
serv.cancel()
|
|
|
|
|
|
|
|
# Confirm starting
|
|
|
|
# at the end of a queue
|
|
|
|
serv.confirm()
|
|
|
|
```
|
|
|
|
|
|
|
|
## Starting
|
|
|
|
### Arguments
|
|
|
|
`start()` can be called with arguments:
|
|
|
|
|
|
|
|
- headstart (bool): Start server in headstart mode
|
2022-12-25 19:17:49 +04:00
|
|
|
which allows you to skip all the queue.
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
- accepteula (bool): Automatically accept Mojang EULA.
|
|
|
|
|
|
|
|
If you want to launch your server instantly, use this code:
|
|
|
|
```python
|
|
|
|
serv.start(headstart=True)
|
|
|
|
```
|
|
|
|
|
|
|
|
### Errors
|
|
|
|
`start()` raises `ServerStartError` if Aternos denies request.
|
|
|
|
This object contains an error code, on which depends an error message.
|
|
|
|
|
|
|
|
- EULA was not accepted (code: `eula`) -
|
2022-12-25 19:17:49 +04:00
|
|
|
remove `accepteula=False` or run `serv.eula()` before the server startup.
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
- Server is already running (code: `already`) -
|
2022-12-25 19:17:49 +04:00
|
|
|
you don't need to start the server, it is online.
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
- Incorrect software version installed (code: `wrongversion`) -
|
|
|
|
if you have *somehow* installed non-existent software version (e.g. `Vanilla 2.16.5`).
|
|
|
|
- File server is unavailable (code: `file`) -
|
2022-12-25 19:17:49 +04:00
|
|
|
problems on Aternos servers, view [https://status.aternos.gmbh](https://status.aternos.gmbh)
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
- Available storage size limit has been reached (code: `size`) -
|
|
|
|
files on your Minecraft server have reached 4GB limit
|
|
|
|
(for exmaple, too much mods or loaded chunks).
|
|
|
|
|
2022-12-25 19:17:49 +04:00
|
|
|
Always wrap `start` into try-except.
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
```python
|
|
|
|
from python_aternos import ServerStartError
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
try:
|
|
|
|
serv.start()
|
|
|
|
except ServerStartError as err:
|
|
|
|
print(err.code) # already
|
|
|
|
print(err.message) # Server is already running
|
|
|
|
```
|
|
|
|
|
|
|
|
## Cancellation
|
|
|
|
Server launching can be cancelled only when you are waiting in a queue.
|
|
|
|
After queue, when the server starts and writes something to the log,
|
2022-12-25 19:17:49 +04:00
|
|
|
you can just `stop()` it, **not** `cancel()`.
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
|
|
|
|
## Server info
|
|
|
|
```python
|
|
|
|
>>> serv.address
|
|
|
|
'test.aternos.me:15172'
|
|
|
|
|
|
|
|
>>> serv.domain
|
|
|
|
'test.aternos.me'
|
|
|
|
|
|
|
|
>>> serv.subdomain
|
|
|
|
'test'
|
|
|
|
|
|
|
|
>>> serv.port
|
|
|
|
15172
|
|
|
|
|
|
|
|
>>> from python_aternos import Edition
|
|
|
|
>>> serv.edition
|
|
|
|
0
|
|
|
|
>>> serv.edition == Edition.java
|
|
|
|
True
|
|
|
|
>>> serv.edition == Edition.bedrock
|
|
|
|
False
|
|
|
|
|
|
|
|
>>> serv.software
|
|
|
|
'Forge'
|
|
|
|
>>> serv.version
|
|
|
|
'1.16.5 (36.2.34)'
|
|
|
|
|
|
|
|
>>> serv.players_list
|
|
|
|
['DarkCat09', 'jeb_']
|
|
|
|
>>> serv.players_count
|
|
|
|
2
|
|
|
|
>>> serv.slots
|
|
|
|
20
|
|
|
|
|
|
|
|
>>> print('Online:', serv.players_count, 'of', serv.slots)
|
|
|
|
Online: 2 of 20
|
|
|
|
|
|
|
|
>>> serv.motd
|
|
|
|
'§7Welcome to the §9Test Server§7!'
|
|
|
|
|
|
|
|
>>> from python_aternos import Status
|
|
|
|
>>> serv.css_class
|
|
|
|
'online'
|
|
|
|
>>> serv.status
|
|
|
|
'online'
|
|
|
|
>>> serv.status_num
|
|
|
|
1
|
|
|
|
>>> serv.status_num == Status.on
|
|
|
|
True
|
|
|
|
>>> serv.status_num == Status.off
|
|
|
|
False
|
|
|
|
>>> serv.status_num == Status.starting
|
|
|
|
False
|
|
|
|
|
|
|
|
>>> serv.restart()
|
|
|
|
|
2022-12-25 19:17:49 +04:00
|
|
|
# Title on the web site: "Loading"
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
>>> serv.css_class
|
|
|
|
'loading'
|
|
|
|
>>> serv.status
|
|
|
|
'loading'
|
|
|
|
>>> serv.status_num
|
|
|
|
6
|
|
|
|
>>> serv.status_num == Status.loading
|
|
|
|
True
|
|
|
|
>>> serv.status_num == Status.preparing
|
|
|
|
False
|
|
|
|
>>> serv.status_num == Status.starting
|
|
|
|
False
|
|
|
|
|
2022-12-25 19:17:49 +04:00
|
|
|
# Title on the web site: "Preparing"
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
>>> serv.css_class
|
|
|
|
'loading'
|
|
|
|
>>> serv.status
|
|
|
|
'preparing'
|
|
|
|
>>> serv.status_num
|
|
|
|
10
|
|
|
|
>>> serv.status_num == Status.preparing
|
|
|
|
True
|
|
|
|
>>> serv.status_num == Status.starting
|
|
|
|
False
|
|
|
|
>>> serv.status_num == Status.on
|
|
|
|
False
|
|
|
|
|
2022-12-25 19:17:49 +04:00
|
|
|
# Title on the web site: "Starting"
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
>>> serv.css_class
|
|
|
|
'loading starting'
|
|
|
|
>>> serv.status
|
|
|
|
'starting'
|
|
|
|
>>> serv.status_num
|
|
|
|
2
|
|
|
|
>>> serv.status_num == Status.starting
|
|
|
|
True
|
|
|
|
>>> serv.status_num == Status.on
|
|
|
|
False
|
|
|
|
|
|
|
|
>>> serv.ram
|
|
|
|
2600
|
|
|
|
```
|
|
|
|
|
|
|
|
## Changing subdomain and MOTD
|
2022-12-25 19:17:49 +04:00
|
|
|
To change the server's subdomain or Message-of-the-Day,
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
just assign a new value to the corresponding fields:
|
|
|
|
```python
|
|
|
|
serv.subdomain = 'new-test-server123'
|
|
|
|
serv.motd = 'Welcome to the New Test Server!'
|
|
|
|
```
|
|
|
|
|
|
|
|
## Updating status
|
2022-12-25 19:17:49 +04:00
|
|
|
Python-Aternos don't refresh server information by default.
|
|
|
|
This can be done with [WebSockets API](/howto/websocket) automatically
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
(but it will be explained later in the 6th part of how-to guide),
|
|
|
|
or with `fetch()` method manually (much easier).
|
|
|
|
|
2022-12-25 19:17:49 +04:00
|
|
|
`fetch()` is also called when an AternosServer object is created
|
|
|
|
to get this info about the server:
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
|
|
|
|
- full address,
|
|
|
|
- MOTD,
|
|
|
|
- software,
|
|
|
|
- connected players,
|
|
|
|
- status,
|
|
|
|
- etc.
|
|
|
|
|
2022-12-25 19:17:49 +04:00
|
|
|
Use it if you want to see the new data *one time*:
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
```python
|
|
|
|
import time
|
|
|
|
from python_aternos import Client
|
|
|
|
|
|
|
|
at = Client.from_credentials('username', 'password')
|
|
|
|
serv = at.list_servers()[0]
|
|
|
|
|
|
|
|
# Start
|
|
|
|
serv.start()
|
|
|
|
# Wait 10 sec
|
|
|
|
time.sleep(10)
|
|
|
|
# Check
|
|
|
|
serv.fetch()
|
|
|
|
print('Server is', serv.status) # Server is online
|
|
|
|
```
|
2022-12-25 19:17:49 +04:00
|
|
|
But this method is **not** a good choice if you want to get *real-time* updates.
|
|
|
|
Read [How-To 6: Real-time updates](/howto/websocket) about WebSockets API
|
MkDocs, Readme, Files API, Automated session saving, v2.0.1
MkDocs: sphinx docstrings rewritten to google, improved config, written the major part of how-to.
Readme: centered title + logo, added badges, features list, updated changelog.
Improved Files API, added automatical session saving and restoring to Client.
Some changes in makefile and gitignore.
License Notice now refers to all contributors.
2022-08-26 16:14:07 +04:00
|
|
|
and use it instead of refreshing data in a while-loop.
|
2022-12-23 17:38:51 +04:00
|
|
|
|
|
|
|
## Countdown
|
|
|
|
Aternos stops a server when there are no players connected.
|
2022-12-25 19:17:49 +04:00
|
|
|
You can get the remained time in seconds using `serv.countdown`.
|
2022-12-23 17:38:51 +04:00
|
|
|
|
|
|
|
For example:
|
|
|
|
```python
|
|
|
|
# Start
|
|
|
|
serv.start()
|
|
|
|
|
|
|
|
# Get the countdown value
|
|
|
|
print(serv.countdown, 'seconds')
|
|
|
|
# -1 seconds
|
|
|
|
# means "null" in countdown field
|
|
|
|
|
|
|
|
# Wait for start up
|
|
|
|
time.sleep(10)
|
|
|
|
|
|
|
|
# Refresh info
|
|
|
|
serv.fetch()
|
|
|
|
# Get countdown value
|
|
|
|
print(serv.countdown, 'seconds')
|
|
|
|
# 377 seconds
|
|
|
|
|
|
|
|
# Check if countdown changes
|
|
|
|
time.sleep(10)
|
|
|
|
serv.fetch()
|
|
|
|
print(serv.countdown, 'seconds')
|
|
|
|
# 367 seconds
|
|
|
|
|
|
|
|
# ---
|
|
|
|
# Convert to minutes and seconds
|
|
|
|
mins, secs = divmod(serv.countdown, 60)
|
|
|
|
print(f'{mins}:{secs:02}') # 6:07
|
|
|
|
# OR
|
|
|
|
cd = serv.countdown
|
|
|
|
print(f'{cd // 60}:{cd % 60:02}') # 6:07
|
|
|
|
```
|