-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path11_init.py
More file actions
54 lines (45 loc) · 1.59 KB
/
11_init.py
File metadata and controls
54 lines (45 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
console = TSPlayer.Server
everyone = TSPlayer.All
# Invokes on IronPythonPlugin.Initialize()
def OnInit(args):
global loaded
loaded = True
puts("IronPython OnInit ===============================")
for f in Type.GetFields(GetDataHandlers):
if f.GetValue(None) is None:
f.SetValue(None, f.FieldType())
Plugin.Initialize()
def OnClose(args):
puts("IronPython OnClose ==============================")
Plugin.Dispose()
gc.collect()
def execute(script, args):
global me
me = args[0]
if script.startswith('\\'):
script = 'puts(' + script[1:] + ')'
elif script.startswith('='):
script = 'puts(dir(' + script[1:] + '))'
putsc(output_colors["white"], script)
# Extensions (clr.ImportExtensions) work with env.Engine.Execute but not with exec
return env.Engine.Execute(script, env.Scope)
def _hook(hc, h, priority=0):
if hc.ToString().startswith('TShockAPI.HandlerList'):
hc.Register(h)
elif hc.ToString().startswith('TerrariaApi.Server.HandlerCollection'):
hc.Register(IronPythonPlugin.Instance, h, priority)
elif str(type(hc)) == "<type 'BoundEvent'>":
hc += h
def _unhook(hc, h):
if hc.ToString().startswith('TShockAPI.HandlerList'):
hc.UnRegister(h)
elif hc.ToString().startswith('TerrariaApi.Server.HandlerCollection'):
hc.Deregister(IronPythonPlugin.Instance, h)
elif str(type(hc)) == "<type 'BoundEvent'>":
hc -= h
def _add_command(permission, f, names):
cmd = TShockAPI.Command(List[str]([permission]), TShockAPI.CommandDelegate(f), Array[str](names))
TShockAPI.Commands.ChatCommands.Add(cmd)
return cmd
def _remove_command(cmd):
TShockAPI.Commands.ChatCommands.Remove(cmd)