Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added poi able to update & added try-except to print_log def #3

Merged
merged 8 commits into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ You can modify the config `dimension_region_folder` to make entities sync during
"source_world_directory": "./qb_multi/slot1/world",
"destination_world_directory": "./server/world",
"dimension_region_folder": {
"-1": ["DIM-1/region", "DIM-1/entities"],
"0": ["region", "entities"],
"1": ["DIM1/region", "DIM1/entities"]
"-1": ["DIM-1/region", "DIM-1/poi", "DIM-1/entities"],
"0": ["region", "poi", "entities"],
"1": ["DIM1/region", "DIM1/poi", "DIM1/entities"]
}
}
```
Expand Down
16 changes: 11 additions & 5 deletions region_file_updater/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class Config(Serializable):
source_world_directory: str = './qb_multi/slot1/world'
destination_world_directory: str = './server/world'
dimension_region_folder: Dict[str, Union[str, List[str]]] = {
'-1': 'DIM-1/region',
'0': 'region',
'1': 'DIM1/region'
'-1': ['DIM-1/region', 'DIM-1/poi'],
'0': ['region', 'poi'],
'1': ['DIM1/region', 'DIM1/poi']
}


Expand Down Expand Up @@ -79,8 +79,11 @@ def __repr__(self):

def print_log(server: ServerInterface, msg: str):
server.logger.info(msg)
with open(LogFilePath, 'a') as logfile:
logfile.write(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) + ': ' + msg + '\n')
try:
with open(LogFilePath, 'a') as logfile:
logfile.write(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) + ': ' + msg + '\n')
except Exception as e:
server.logger.info('错误写入日志文件: {}'.format(e))


def add_region(source: CommandSource, region: Region):
Expand Down Expand Up @@ -164,6 +167,9 @@ def region_update(source: CommandSource):
except Exception as e:
msg = '失败,错误信息:{}'.format(str(e))
flag = False
if isinstance(e, FileNotFoundError) and os.path.exists(destination):
os.remove(destination)
source.get_server().logger.info('在目的地被删除的文件: {}'.format(destination))
else:
msg = '成功'
flag = True
Expand Down