forked from TISUnion/PCRC-MCDR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PCRC-MCDR.py
87 lines (69 loc) · 2.08 KB
/
PCRC-MCDR.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# -*- coding: utf-8 -*-
import importlib
import time
from mcdreforged.api.all import *
PLUGIN_METADATA = {
'id': 'pcrc_mcdr',
'version': '1.0.0',
'name': 'PCRC MCDR',
'description': 'a MCDR plugin wrapper for PCRC',
'author': 'Fallen_Breath',
'link': 'https://github.com/TISUnion/PCRC-MCDR'
}
PCRC = None
PREFIX = '!!PCRC'
# 0=guest 1=user 2=helper 3=admin
Permission = 1
def permission_check(server, info, perm):
if info.is_user:
if info.source == 1:
return True
elif server.get_permission_level(info) >= perm:
return True
return False
def load_PCRC():
global PCRC
PCRC = importlib.import_module('PCRC-MCDR.PCRC')
@new_thread('PCRC-MCDR')
def on_user_info(server, info):
if PCRC is not None:
if permission_check(server, info, Permission) and info.content == '!!PCRC start':
server.reply(info, 'Starting PCRC')
if PCRC.is_working():
server.reply(info, 'PCRC is already running!')
else:
PCRC.start()
if info.source == 1 and info.content == '!!PCRC stop':
if PCRC.is_working():
PCRC.stop()
else:
server.reply(info, 'PCRC is not running!')
def on_load(server, old):
global PCRC
try:
if old is not None and old.PCRC is not None and old.PCRC.is_working():
PCRC = old.PCRC
else:
load_PCRC()
except:
load_PCRC()
def stopping(server):
global PCRC
if PCRC is None:
return
if PCRC.is_working():
PCRC.stop()
else:
for i in range(600):
if not PCRC.is_stopped():
server.logger.info('Waiting for PCRC to stop')
for i in range(10):
if not PCRC.is_stopped():
time.sleep(0.1)
if not PCRC.is_stopped():
server.logger.info('PCRC took too long to stop (more than 10min)! Exit anyway')
def on_mcdr_stop(server):
stopping(server)
@new_thread('PCRC-MCDR')
def on_remove(server):
stopping(server)