Date: 2016/04/09 19:48:35 UTC-07:00
Type: Denizen Script
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
dRegions_Events_ETP:
type: world
speed: 0
debug: false
events:
on entity targets player:
# %player% is the variable used in abstract methods to refrence the player object.
- define player '<c.target>'
# %world% is the variable used in abstract methods to refrence world in which the event took place.
- define world '<c.entity.world.name>'
# %object% is the variable used in abstract methods to refrence the object the player is interacting with.
- define object '<c.entity>'
# %target% is a generic variable used in abstract methods that applies to the TYPE of object in question.
- define target '<c.entity.entity_type>'
# Debating whether I should fully abstractify handlers.
- define eventHooks 'li@ENTITY_Target_Player'
- define FlagMap '<server.flag[dRegions_FlagMap].filter[contains_any[%eventHooks%]].parse[after[/]].alphanumeric.parse[split[/].get[2]]>'
# This is a rate limiter implemented BEFORE caching. The idea here is that if the player and target are in
# the same region (even Global) we can safely expect that the values will be consistent (because we clear
# rateLimit values on region enter/exit). Normal processing will follow if the rateLimit value is stale.
- if '<def[object].location.cuboids.alphanumeric.unseparated||null>' != '<def[player].location.cuboids.alphanumeric.unseparated||null>' {
- define sameRegion 'false'
- goto 'GLOBAL'
}
- foreach '%FlagMap%' {
- define flag '%value%'
- define rateLimit '<def[player].flag[dRegions.rateLimit.%flag%.%target%]||null>'
- if '%rateLimit%' != 'null' {
- if '%rateLimit%' {
- foreach next
- queue clear
}
- run delay:1t s@dRegions_Flag_%flag% p:cleanup 'def:%object%'
- determine cancelled
}
}
- define sameRegion 'true'
# Global Event Handler. Cache values can be null, true, or false. If the cache value
# is null, then we need to send to the flag script for processing. If the cache value
# is false then we cancel the event and send to flag script for cleanup. If the cache
# value is true then the event is allowed to pass. Cache values are cleared on server
# restart, and when regions are modified.
- mark 'GLOBAL'
- if !<def[player].location.cuboids.is_empty> {
- goto 'REGION'
}
- foreach '%FlagMap%' {
- define flag '%value%'
- define cache '<def[player].flag[dRegions.cache.%world%.__global__.%flag%.%target%]||null>'
- if %cache% == 'null' {
- inject s@dRegions_Flag_%flag% p:event-global
- foreach next
- queue clear
}
- if !%cache% {
- if %sameRegion% {
- flag %player% 'dRegions.rateLimit.%flag%.%target%:false' d:10s
}
- run delay:1t s@dRegions_Flag_%flag% p:cleanup 'def:%object%'
- determine cancelled
}
- if %sameRegion% {
- flag %player% 'dRegions.rateLimit.%flag%.%target%:true' d:10s
}
}
- queue clear
# Region Event Handler. Builds region list and runs flag scripts in priority order.
- mark 'REGION'
- define regionPri 'li@'
- foreach <def[player].location.cuboids.parse[notable_name].filter[starts_with[dRegions_]].parse[after[dregions_%world%_]].include[__global__]> {
- define regionPri '%regionPri%<yaml[dRegions_%world%_regions].read[regions.%value%.priority]||0>/%value%|'
}
- define orderedRegions '<def[regionPri].alphanumeric.reverse.parse[split[/].get[2]]>'
- foreach '%FlagMap%' {
- define flag '%value%'
- inject s@dRegions_Flag_%flag% p:event
}