Skip to content

Commit 5efdbee

Browse files
committed
U | update
1 parent 710adaa commit 5efdbee

File tree

1 file changed

+15
-31
lines changed

1 file changed

+15
-31
lines changed

src/endstone_real_weather/real_weather.py

+15-31
Original file line numberDiff line numberDiff line change
@@ -8,53 +8,46 @@ class RealWeather(Plugin):
88

99
def __init__(self):
1010
super().__init__()
11-
self.update_period: float = 0
12-
self.city: str = ""
13-
1411
self.url: str = 'http://t.weather.sojson.com/api/weather/city/'
1512

1613
def on_enable(self) -> None:
1714
self.save_default_config()
1815
self.load_config()
1916

2017
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!")
2219

2320
self.server.scheduler.run_task(self, self.update_weather, delay=0, period = self.update_period * 72000)
2421

2522
commands = {
26-
"realweather": {
23+
"rw": {
2724
"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"],
3027
},
3128
}
3229

3330
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",
3633
"default": "op",
3734
},
3835
}
3936

4037
def on_command(self, sender: CommandSender, command: Command, args: list[str]) -> bool:
41-
if command.name == "realweather":
38+
if command.name == "rw":
4239

4340
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])}")
4845
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")
5346

5447
if str(args[0]) == "info":
55-
if len(str(args[1])) > 0:
48+
if len(args[1]) > 0:
5649
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])}")
5851
return True
5952

6053
def sync_weather(self, city:str) -> str:
@@ -75,21 +68,12 @@ def sync_weather(self, city:str) -> str:
7568
return "thunder"
7669
else:
7770
return "clear"
78-
else:
79-
return "ERROR"
8071
else:
8172
return "ERROR"
8273

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-
9074
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}")
9276

9377
def load_config(self) -> None:
9478
self.city = self.config["city"]
95-
self.update_period = self.config["update_period"]
79+
self.update_period = self.config["update_period"]

0 commit comments

Comments
 (0)