✨ Add feature for auto stop render when player enter the server
This commit is contained in:
parent
502b643537
commit
f4c6a3e335
|
@ -1,4 +1,5 @@
|
|||
import json
|
||||
import re
|
||||
from json import JSONDecodeError
|
||||
|
||||
from mcdreforged.api.command import SimpleCommandBuilder, Integer, Text, GreedyText
|
||||
|
@ -6,6 +7,7 @@ from mcdreforged.command.builder.common import CommandContext
|
|||
from mcdreforged.command.builder.nodes.arguments import QuotableText
|
||||
from mcdreforged.command.builder.nodes.basic import Literal
|
||||
from mcdreforged.command.command_source import CommandSource, PlayerCommandSource
|
||||
from mcdreforged.info_reactor.info import Info
|
||||
from mcdreforged.minecraft.rtext.style import RColor
|
||||
from mcdreforged.minecraft.rtext.text import RText, RTextList
|
||||
from mcdreforged.plugin.server_interface import PluginServerInterface
|
||||
|
@ -15,6 +17,8 @@ from bluemap_helper.bluemap import read_config, insert_mark, get_bluemap_dimensi
|
|||
from bluemap_helper.poi_utils import get_poi_marker, get_position
|
||||
from bluemap_helper.utils import named_thread
|
||||
|
||||
PLAYER_COUNT: int = 0
|
||||
|
||||
|
||||
def on_load(server: PluginServerInterface, prev_module):
|
||||
server.register_command(
|
||||
|
@ -38,6 +42,44 @@ def on_load(server: PluginServerInterface, prev_module):
|
|||
Literal("list").runs(list_markers)
|
||||
)
|
||||
)
|
||||
server.execute("list")
|
||||
|
||||
|
||||
def on_player_joined(server: PluginServerInterface, player: str, info: Info):
|
||||
global PLAYER_COUNT
|
||||
if not get_player_name(player).startswith("bot_"):
|
||||
PLAYER_COUNT += 1
|
||||
if PLAYER_COUNT - 1 == 0:
|
||||
server.say("发现玩家进入服务器,Bluemap渲染已暂停")
|
||||
server.execute("bluemap stop")
|
||||
|
||||
|
||||
def on_player_left(server: PluginServerInterface, player: str):
|
||||
global PLAYER_COUNT
|
||||
if not get_player_name(player).startswith("bot_"):
|
||||
PLAYER_COUNT -= 1
|
||||
print(PLAYER_COUNT)
|
||||
if PLAYER_COUNT == 0:
|
||||
print("最后一个玩家已经退出,渲染继续")
|
||||
server.execute("bluemap start")
|
||||
|
||||
|
||||
def on_info(server: PluginServerInterface, info: Info):
|
||||
global PLAYER_COUNT
|
||||
mat = re.match(r'There are ([0-9]*) of a max of ([0-9]*) players online: (.*)', info.content)
|
||||
if mat:
|
||||
players: list[str] = mat.group(3).split(",")
|
||||
for player in players:
|
||||
if not get_player_name(player).startswith("bot_"):
|
||||
PLAYER_COUNT += 1
|
||||
if PLAYER_COUNT > 0:
|
||||
server.execute("bluemap stop")
|
||||
else:
|
||||
server.execute("bluemap start")
|
||||
|
||||
|
||||
def get_player_name(player: str):
|
||||
return player.strip().lower()
|
||||
|
||||
|
||||
@named_thread
|
||||
|
|
|
@ -43,6 +43,7 @@ def del_mark(area, marker_set, marker_id):
|
|||
sets.pop(marker_id)
|
||||
write_config(config, path)
|
||||
|
||||
|
||||
def get_marker_list(area):
|
||||
set_list: list[MarkerSet] = []
|
||||
path = get_path(area)
|
||||
|
|
Loading…
Reference in New Issue