LoginSignup
5
5

More than 1 year has passed since last update.

MinecraftサーバーをPythonから制御

Last updated at Posted at 2021-07-31

MinecraftサーバーをPythonから制御

PythonからMinecraftサーバーを制御できるモジュールがあるらしい。

環境
  • Python3.9(だったっけ?)
  • Windows 10 Pro
  • Mcipc 2.3.3

server設定ファイルで

enable-rcon=True

にしておいてください

いんすとーる

pip3 install mcipc

python3 -m pip3 install mcipc

前者でできなければ後者を試してみてください。
できなかったら「python パス 通し方」ググってください。

コードを書く。

サーバーを停止する

まずはサーバーをストップさせることから。

from mcipc.rcon.je import Client
with Client('127.0.0.1', 25575, passwd='minecraft') as client:
    log = client.stop()
print(log)

補足

二行目のClient()はの引数は左からサーバーのIPアドレス、RCONクライアントのポート、
パスワードの順です。
log変数には実行結果が帰ってきます。

よく使うコマンドをまとめる

from mcipc.rcon.je import Client
while True:
    ans = input("")
    with Client('127.0.0.1', 25575, passwd='minecraft') as client:
        if ans == "1":
            log = client.stop()
        if ans == "2":
            log = client.kill("@e[type=player]") #[]の文字も同じ引数の中に入れる
        if ans == "3"
            log =client.effect.give("@p","speed") #client.effect("give","@p","speed")ではないことに注意
        print(log)

(工事中) djangoから制御できるようにする

参考

公式ドキュメント

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5