-
Notifications
You must be signed in to change notification settings - Fork 1
/
recompile.msa
95 lines (88 loc) · 2.49 KB
/
recompile.msa
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
* Overrides CommandHelper's recompile command to:
* - Change default flags to -gfrx (use -g to clear globals)
* - Prevent recompile if certain scripts like games are running (use -f to force recompile)
* - Temporarily store some globals if they're cleared (use -p to also clear protected globals)
* - Clear orphan scoreboards and boss bars
* - Prints time to reload, compile and execute (use -s to silence this broadcast)
* - Broadcasts optional recompile reason text
*/
/recompile [$args] [$] = >>>
@clearGlobal = false; # -g clear all but protected exported global vars
@clearProtected = false; # -p clear protected global vars
@force = false; # -f force recompile even if games are running
@silent = false;
@message = '';
if($args) {
if($args[0] === '-') {
foreach(@i in range(1, length($args))) {
switch($args[@i]) {
case 'g':
@clearGlobal = true;
case 'p':
@clearProtected = true;
case 'f':
@force = true;
case 's':
@silent = true;
}
}
} else {
@message = $args.' ';
}
}
if($) {
@message .= $;
}
# check if a game is running before recompiling
@activities = import('activities');
if(@activities) {
msg(color('gold').'Currently in progress: '.array_keys(@activities));
if(!@force) {
die(color('red').'Halted recompile due to games in progress.');
} else {
foreach(@id: @activity in @activities) {
export(@id, null);
}
}
}
# if forcing a recompile, clear scoreboards and boss bars
if(@force) {
foreach(@scoreboard in get_scoreboards()) {
if(@scoreboard !== 'main') {
remove_scoreboard(@scoreboard);
}
}
foreach(@bar in get_bars()) {
remove_bar(@bar);
}
}
# If we're clearing global variables, let's store and restore some
if(@clearGlobal && !@clearProtected) {
@requests = import('requests');
if(is_array(@requests)) {
store_value('session.requests', @requests);
}
@conv = import('conv');
if(is_array(@conv)) {
store_value('session.conv', @conv);
}
@ignorelist = import('ignorelist');
if(is_array(@ignorelist)) {
store_value('session.ignorelist', @ignorelist);
}
@timers = import('timers');
if(is_array(@timers)) {
store_value('session.timers', @timers);
}
} else {
export('recompile', true);
}
@start = time();
run('/recompile -rfx'.if(!@clearGlobal, 'g'));
@stop = time();
if(!@silent) {
broadcast(color('yellow').'Recompiled scripts!'.if(@message, ' "'.@message.'"').' ('.round((@stop - @start) / 1000, 2).'s)');
}
export('recompile', null);
<<<