Skip to content

Commit

Permalink
v1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxkad committed Jan 7, 2022
1 parent f952aef commit 0d863ca
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Delay ExE

- A plugin for delay execute command until there are no player online
- A plugin for delay execute command until all player have left
- You can use it API

### Example for API
Expand Down
2 changes: 1 addition & 1 deletion README_zh.MD
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Delay ExE

- 一个延迟 _(直到服务器没有玩家)_ 执行命令的插件
- 一个延迟 _(直到服务器没有玩家)_ 才执行指定命令的插件
- 可以当做*API*
- ~~原理非常简单, 就不多介绍了~~

Expand Down
4 changes: 4 additions & 0 deletions delayexe/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def register(server: MCDR.PluginServerInterface):
MCDR.Literal(Prefix).
runs(command_help).
then(GL.Config.literal('help').runs(command_help)).
then(GL.Config.literal('query').runs(command_query)).
then(GL.Config.literal('restart').runs(command_restart)).
then(GL.Config.literal('run').
then(MCDR.GreedyText('command').runs(lambda src, ctx: command_run(src, ctx['command'])))).
Expand All @@ -58,6 +59,9 @@ def register(server: MCDR.PluginServerInterface):
def command_help(source: MCDR.CommandSource):
send_block_message(source, HelpMessage)

def command_query(source: MCDR.CommandSource):
send_block_message(source, '当前共有{}个任务:'.format(len(delaylist)), *['- ' + c for c in delaylist if isinstance(c, str)])

def command_restart(source: MCDR.CommandSource):
add_delay_task(new_thread(source.get_server().restart))

Expand Down
3 changes: 3 additions & 0 deletions delayexe/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ class DLEConfig(MCDR.Serializable):
# 0:guest 1:user 2:helper 3:admin 4:owner
minimum_permission_level: Dict[str, int] = {
'help': 0,
'query': 0,
'restart': 2,
'run': 3,
'cancel': 2,
'reload': 3,
'save': 3,
}
Expand Down
8 changes: 7 additions & 1 deletion delayexe/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

import functools

import mcdreforged.api.all as MCDR
from . import globals as GL

Expand All @@ -9,11 +11,16 @@

def new_thread(call):
@MCDR.new_thread('delayexe')
@functools.wraps(call)
def c(*args, **kwargs):
return call(*args, **kwargs)
return c

def join_rtext(*args, sep=' '):
if len(args) == 0:
return ''
if len(args) == 1:
return args[0]
return MCDR.RTextList(args[0], *(MCDR.RTextList(sep, a) for a in args[1:]))

def send_block_message(source: MCDR.CommandSource, *args, sep='\n', log=False):
Expand All @@ -23,7 +30,6 @@ def send_block_message(source: MCDR.CommandSource, *args, sep='\n', log=False):
if log and not source.is_console:
source.get_server().logger.info(t)


def send_message(source: MCDR.CommandSource, *args, sep=' ', prefix=GL.MSG_ID, log=False):
if source is not None:
t = join_rtext(prefix, *args, sep=sep)
Expand Down
7 changes: 5 additions & 2 deletions mcdreforged.plugin.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"id": "delayexe",
"version": "1.0.1",
"version": "1.0.2",
"name": "Delay Exe",
"description": "Delay execute command when all player was leave",
"description": {
"en_us": "Delay execute command until all player have left",
"zh_cn": "延迟执行命令, 直到所有玩家都离开游戏"
},
"dependencies": {
"mcdreforged": ">=2.0.0"
},
Expand Down

0 comments on commit 0d863ca

Please sign in to comment.