Date: 2016/04/11 20:32:04 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
start:
- inject locally loadYaml
- foreach '<server.list_flags[dRegions]>' {
- flag server '%value%:!'
}
- define flags '<server.list_scripts.filter[starts_with[s@dRegions_Flag_]].parse[name.after[dRegions_Flag_].to_lowercase].alphanumeric||li@>'
- flag server 'dRegions.Flags:|:%flags%'
- foreach '%flags%' {
- flag server 'dRegions.EventMap.<s@dRegions_Flag_%value%.yaml_key[event_hook]>:->:<s@dRegions_Flag_%value%.yaml_key[event_priority]>/%value%'
}
- foreach '<server.list_flags[dRegions.EventMap.]>' {
- define e '<server.flag[%value%]>'
- flag server '%value%:!'
- flag server '%value%:|:<def[e].alphanumeric.parse[after[/]]>'
}
- if <queue.exists[dRegions_saveCache]> {
- queue q@dRegions_saveCache stop
}
- run locally saveCache delay:5s id:dRegions_saveCache
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>'
# EventHooks are parsed and prioritized on server start so all that's needed here is to get the list of flags and run them.
- define eventHooks 'li@ENTITY_Target_Player'
- define flags '<server.flag[dRegions.EventMap.Entity_Target_Player].as_list>'
- foreach %flags% {
- define flag '%value%'
- inject 's@dRegions_Flags_Processor' 'p:<s@dRegions_Flag_%flag%.yaml_key[flag_type]>'
}
################################################################################
dRegions_Flags_Processors:
type: task
speed: 0
debug: false
#---------------------------------------
# Region flag pre-processors
#
state-withTarget-withGroup:
# 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||null>' != '<def[player].location.cuboids||null>' {
- define sameRegion 'false'
- goto '<t[<def[player].location.cuboids.is_empty>]:GLOBAL||REGION>'
}
- goto 'g<def[player].flag[dRegions.rateLimit.%flag%.%target%]||a>'
- mark 'ga'
- define sameRegion 'true'
- goto '<t[<def[player].location.cuboids.is_empty>]:GLOBAL||REGION>'
# 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'
- goto 'g<def[player].flag[dRegions.cache.%world%.__global__.%flag%.%target%]||null>'
- mark 'gnull'
- define thisRegion '__global__'
- define flagObj '<proc[dRegions_GetInheritedFlag].context[%world%|__global__|%flag%]>'
- define targetList '<proc[dRegions_GetInheritedFlag].context[%world%|__global__|<s@dRegions_Flag_%value%.yaml_key[flag_targetList]||null>].replace[, ].with[|].as_list>'
- goto 'g<def[flagObj].before[/]>'
- mark 'gallow'
- goto 'g<proc[dRegions_PlayerMatchRegionGroup].context[<def[flagObj].after[/]||all>|__global__|%world%|%player%].not.or[<def[targetList].contains_any[none|all|%target%].not>]>'
- mark 'gdeny'
- goto 'g<proc[dRegions_PlayerMatchRegionGroup].context[<def[flagObj].after[/]||all>|__global__|%world%|%player%].and[<def[targetList].contains_any[none|all|%target%]>]>'
- mark 'gnone'
- goto 'gtrue'
- mark 'gfalse'
- inject 's@dRegions_Flag_%flag%' 'p:event-cancelled'
- determine cancelled
- mark 'gtrue'
- inject 's@dRegions_Flag_%flag%' 'p:event-allowed'
- foreach next
- 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%_]]>|__global__' {
- define regionPri '%regionPri%<yaml[dRegions_%world%_regions].read[regions.%value%.priority]||0>/%value%|'
}
- define orderedRegions '<def[regionPri].alphanumeric.reverse.parse[after[/]]>'