-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce42e3a
commit 8c6b706
Showing
8 changed files
with
210 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
.idea/ | ||
.idea/ | ||
*.mcdr |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"id": "timed_quick_backup_multi", | ||
"version": "1.0.1", | ||
"name": "Timed QBM", | ||
"description": { | ||
"en_us": "A Quick-Backup-Multi extension for automatically trigger QBM at given interval", | ||
"zh_cn": "一个QuickBackupM插件的扩展,用于定时触发QBM从而进行自动备份" | ||
}, | ||
"author": "Fallen_Breath", | ||
"link": "https://github.com/TISUnion/TimedQBM", | ||
"dependencies": { | ||
"quick_backup_multi": ">=1.1.0" | ||
}, | ||
"entrypoint": "timed_quick_backup_multi.entry", | ||
"resources": [ | ||
"LICENSE" | ||
] | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import time | ||
from threading import Thread, Event | ||
|
||
from mcdreforged.api.all import * | ||
|
||
from timed_quick_backup_multi import stored, constants | ||
|
||
|
||
class TimedQBM(Thread): | ||
def __init__(self, server: PluginServerInterface): | ||
super().__init__() | ||
self.setDaemon(True) | ||
self.setName(self.__class__.__name__) | ||
self.time_since_backup = time.time() | ||
self.server = server | ||
self.stop_event = Event() | ||
self.is_enabled = False | ||
|
||
@staticmethod | ||
def __get_interval() -> float: | ||
from timed_quick_backup_multi.entry import config | ||
return config.interval | ||
|
||
@classmethod | ||
def get_backup_interval(cls): | ||
return cls.__get_interval() * 60 | ||
|
||
def broadcast(self, message): | ||
rtext = RTextList('[{}] '.format(stored.metadata.name), message) | ||
if self.server.is_server_startup(): | ||
self.server.broadcast(rtext) | ||
else: | ||
self.server.logger.info(rtext) | ||
|
||
def set_enabled(self, value: bool): | ||
self.is_enabled = value | ||
self.reset_timer() | ||
|
||
def reset_timer(self): | ||
self.time_since_backup = time.time() | ||
|
||
def get_next_backup_message(self): | ||
return '下次自动备份时间: §3{}§r'.format(time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(self.time_since_backup + self.get_backup_interval()))) | ||
|
||
def broadcast_next_backup_time(self): | ||
self.broadcast(self.get_next_backup_message()) | ||
|
||
def on_backup_created(self, slot_info: dict): | ||
self.broadcast('检测到新增的备份,重置定时器') | ||
self.reset_timer() | ||
self.broadcast_next_backup_time() | ||
|
||
def run(self): | ||
while True: # loop until stop | ||
while True: # loop for backup interval | ||
if self.stop_event.wait(1): | ||
return | ||
if time.time() - self.time_since_backup > self.get_backup_interval(): | ||
break | ||
if self.is_enabled and self.server.is_server_startup(): | ||
self.broadcast('每§6{}§r分钟一次的定时备份触发'.format(self.__get_interval())) | ||
self.server.dispatch_event(constants.TRIGGER_BACKUP_EVENT, (self.server.get_plugin_command_source(), '{} 定时备份'.format(stored.metadata.name)), on_executor_thread=False) | ||
|
||
def stop(self): | ||
self.stop_event.set() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from mcdreforged.api.all import * | ||
|
||
QBM_PID = 'quick_backup_multi' | ||
PREFIX = '!!tqb' | ||
|
||
TRIGGER_BACKUP_EVENT = LiteralEvent('{}.trigger_backup'.format(QBM_PID)) # <- source, comment | ||
BACKUP_DONE_EVENT = LiteralEvent('{}.backup_done'.format(QBM_PID)) # -> source, slot_info |
Oops, something went wrong.