Skip to content

Commit a4074e1

Browse files
committed
使得mcstatus加载优化
1 parent 8fb2433 commit a4074e1

3 files changed

Lines changed: 21 additions & 16 deletions

File tree

main.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
# -*- coding: UTF-8 -*-
2-
import os
32

4-
os.chdir(os.path.dirname(os.path.abspath(__file__)))
5-
6-
from main_gui import GUI
7-
8-
9-
def load():
3+
def main():
4+
from main_gui import GUI
105
root = GUI()
116
root.mainloop()
127

138

149
if __name__ == '__main__':
15-
load()
10+
import os
11+
12+
os.chdir(os.path.dirname(os.path.abspath(__file__)))
13+
main()

scanner.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,19 @@
77
from base64 import b64decode
88
from PIL import Image, ImageTk
99
from queue import Queue, Empty
10-
from mcstatus import JavaServer
1110
from threading import Thread, Lock
12-
from mcstatus.pinger import ServerPinger
13-
from mcstatus.protocol.connection import TCPSocketConnection
11+
12+
13+
def import_big_library():
14+
from mcstatus.address import Address
15+
from mcstatus.pinger import ServerPinger
16+
from mcstatus.protocol.connection import TCPSocketConnection
17+
globals()["Address"] = Address
18+
globals()["ServerPinger"] = ServerPinger
19+
globals()["TCPSocketConnection"] = TCPSocketConnection
20+
21+
22+
Thread(target=import_big_library).start()
1423

1524

1625
class ServerScanner:
@@ -148,12 +157,10 @@ def get_server_info(self) -> dict:
148157
获取服务器在`#Status_Response`包中的返回JSON
149158
https://wiki.vg/Server_List_Ping#Status_Response
150159
"""
151-
server = JavaServer(self.host, self.port, self.timeout)
152-
153160
info = {"host": self.host, "port": self.port}
154161
try:
155-
with TCPSocketConnection(server.address, server.timeout) as connection:
156-
pinger = ServerPinger(connection, address=server.address)
162+
with TCPSocketConnection((self.host, self.port), self.timeout) as connection:
163+
pinger = ServerPinger(connection, address=Address(self.host, self.port))
157164
pinger.handshake()
158165
info_data = pinger.read_status()
159166
ping_time = pinger.test_ping()

widgets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,4 +335,4 @@ def on_focus_out(self, *_):
335335
self.on_tip = True
336336

337337
def set_tip(self, tip: str):
338-
self.tip = tip
338+
self.tip = tip

0 commit comments

Comments
 (0)