@@ -8,53 +8,46 @@ class RealWeather(Plugin):
8
8
9
9
def __init__ (self ):
10
10
super ().__init__ ()
11
- self .update_period : float = 0
12
- self .city : str = ""
13
-
14
11
self .url : str = 'http://t.weather.sojson.com/api/weather/city/'
15
12
16
13
def on_enable (self ) -> None :
17
14
self .save_default_config ()
18
15
self .load_config ()
19
16
20
17
if not os .path .exists ("plugins/real_weather/city.json" ):
21
- self .logger .error ("Missing dependent file! Go to https://github.com/ZH-Server/endstone_real_weather/ read README.md at first!" )
18
+ self .logger .error ("Missing dependent file! Go to https://github.com/ZH-Server/endstone_real_weather read README.md at first!" )
22
19
23
20
self .server .scheduler .run_task (self , self .update_weather , delay = 0 , period = self .update_period * 72000 )
24
21
25
22
commands = {
26
- "realweather " : {
23
+ "rw " : {
27
24
"description" : "Real weather command" ,
28
- "usages" : ["/realweather (sync|info)<action: RWAction> [city: str]" ],
29
- "permissions" : ["realweather .command.realweather " ],
25
+ "usages" : ["/rw (sync|info)<action: RWAction> [city: str]" ],
26
+ "permissions" : ["rw .command.rw " ],
30
27
},
31
28
}
32
29
33
30
permissions = {
34
- "realweather .command.realweather " : {
35
- "desciption" : "Allow users to use the /realweather command" ,
31
+ "rw .command.rw " : {
32
+ "desciption" : "Allow users to use the /rw command" ,
36
33
"default" : "op" ,
37
34
},
38
35
}
39
36
40
37
def on_command (self , sender : CommandSender , command : Command , args : list [str ]) -> bool :
41
- if command .name == "realweather " :
38
+ if command .name == "rw " :
42
39
43
40
if str (args [0 ]) == "sync" :
44
- if len (str ( args [1 ]) ) > 0 :
45
- if not self .sync_weather (str ( args [1 ]) ) != "ERROR" :
46
- sender .send_message (f"{ str ( args [1 ]) } 's weather: { self .sync_weather (str ( args [1 ]) )} " )
47
- self .server .dispatch_command (self .server .command_sender , f"weather { self .sync_weather (str ( args [1 ]) )} " )
41
+ if len (args [1 ]) > 0 :
42
+ if not self .sync_weather (args [1 ]) != "ERROR" :
43
+ sender .send_message (f"{ args [1 ]} 's weather: { self .sync_weather (args [1 ])} " )
44
+ self .server .dispatch_command (self .server .command_sender , f"weather { self .sync_weather (args [1 ])} " )
48
45
sender .send_message (f"Has synchronized { args [1 ]} weather" )
49
- else :
50
- self .server .dispatch_command (self .server .command_sender , f"weather { self .sync_weather (str (self .city ))} " )
51
- sender .send_message (f"{ str (self .city )} 's weather: { self .sync_weather (str (self .city ))} " )
52
- sender .send_message ("Has used default config to sync weather" )
53
46
54
47
if str (args [0 ]) == "info" :
55
- if len (str ( args [1 ]) ) > 0 :
48
+ if len (args [1 ]) > 0 :
56
49
if self .sync_weather (str (args [1 ])) != "ERROR" :
57
- sender .send_message (f"{ str ( args [1 ]) } 's weather: { self .sync_weather (str ( args [1 ]) )} " )
50
+ sender .send_message (f"{ args [1 ]} 's weather: { self .sync_weather (args [1 ])} " )
58
51
return True
59
52
60
53
def sync_weather (self , city :str ) -> str :
@@ -75,21 +68,12 @@ def sync_weather(self, city:str) -> str:
75
68
return "thunder"
76
69
else :
77
70
return "clear"
78
- else :
79
- return "ERROR"
80
71
else :
81
72
return "ERROR"
82
73
83
- def change_weather (self , weather : str , time : int ) -> None :
84
- if weather != "ERROR" :
85
- self .server .dispatch_command (self .server .command_sender , "gamerule doWeatherCycle false" )
86
- self .server .dispatch_command (self .server .command_sender , f"weather { weather } { time } " )
87
- else :
88
- self .server .dispatch_command (self .server .command_sender , "gamerule doWeatherCycle true" )
89
-
90
74
def update_weather (self ):
91
- self .server .dispatch_command (self .server .command_sender , f"weather { self .sync_weather ( self .city ) {self .update_period } } " )
75
+ self .server .dispatch_command (self .server .command_sender , f"weather { self .sync_weather (self .city ) } { self .update_period } " )
92
76
93
77
def load_config (self ) -> None :
94
78
self .city = self .config ["city" ]
95
- self .update_period = self .config ["update_period" ]
79
+ self .update_period = self .config ["update_period" ]
0 commit comments