Date: 2015/02/13 19:24:35 UTC-08: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
109
110
111
112
113
dRegions_WaterSpreadEvent:
type: world
debug: false
events:
on water spreads:
- define world '<c.location.world.name.to_lowercase>'
# Build list of dRegions for <c.location> in priority order
- define regionPri 'li@'
- foreach <c.location.cuboids.parse[notable_name].filter[split[_].get[1].is[==].to[dRegions]].parse[after[dregions_%world%_]].include[__global__]> {
- define regionPri '<def[regionPri].include[<yaml[dRegions_%world%_regions].read[regions.%value%.priority]||0>/%value%]>'
}
- define oldLoc '<def[regionPri].alphanumeric.reverse.parse[split[/].get[2]].get[1]>'
# Build list of dRegions for <c.destination> in priority order
- define regionPri 'li@'
- foreach <c.destination.cuboids.parse[notable_name].filter[split[_].get[1].is[==].to[dRegions]].parse[after[dregions_%world%_]].include[__global__]> {
- define regionPri '<def[regionPri].include[<yaml[dRegions_%world%_regions].read[regions.%value%.priority]||0>/%value%]>'
}
- define orderedRegions '<def[regionPri].alphanumeric.reverse.parse[split[/].get[2]]>'
# Block liquid from crossing region borders
- if %oldLoc% != <def[orderedRegions].get[1]> determine cancelled
# We want to control what blocks water is allowed to destroy when it flows
- define target '<c.destination.material.bukkit_enum.to_lowercase>'
# Check global and world config files
- foreach '<el@val[%world%|global].as_list>' {
- define settingValue '<yaml[dRegions_%value%_config].read[config.spread.water]||true>'
- define targetList '<yaml[dRegions_%value%_config].read[config.spread.water-list]||li@>'
- if %settingValue% {
- if !<def[targetList].is_empty> {
- if %targetList% !contains %target% {
- determine CANCELLED
}
}
}
- if !%settingValue% {
- if <def[targetList].is_empty> {
- determine CANCELLED
}
- if %targetList% contains %target% {
- determine CANCELLED
}
}
}
# Process water-spread region flag
# Exhaustively search for a flag value
- foreach %orderedRegions% {
- define region %value%
# Check the (currently) highest priority region for a flag value
- define flagVal '<yaml[dRegions_%world%_regions].read[regions.%region%.flags.water-spread]||null>'
# If it doesn't set the flag, exhaust its ancestry
- if %flagVal% == null {
- define thisRegion '%region%'
- while <def[flagVal].is[==].to[null]||false> {
- define thisRegion '<yaml[dRegions_%world%_regions].read[regions.%thisRegion%.parent]||null>'
- if %thisRegion% == null {
- while stop
}
- define flagVal '<yaml[dRegions_%world%_regions].read[regions.%thisRegion%.flags.water-spread]||null>'
}
}
# If the flagVal is still null, check the next highest priority region for this location
- if %flagVal% == null {
# If there are no other regions at this location, set a default value
- if %loop_index% == <def[orderedRegions].size> {
- define flagVal '<def[FlagScript].yaml_key[flag_defaultValue]||allow>'
}
else foreach next
}
# Working with ONLY the current region, get a list of blocks water is/isn't allowed to destroy
- define targetList '<yaml[dRegions_%world%_regions].read[regions.%region%.flags.water-spreadblocks]||null>'
# If it doesn't set the flag, exhaust its ancestry
- if %targetList% == null {
- define thisRegion '%region%'
- while <def[targetList].is[==].to[null]||false> {
- define thisRegion '<yaml[dRegions_%world%_regions].read[regions.%thisRegion%.parent]||null>'
- if %thisRegion% == null {
- while stop
}
- define targetList '<yaml[dRegions_%world%_regions].read[regions.%thisRegion%.flags.water-spreadblocks]||null>'
}
# Set a default if we've exhausted the ancestry and still have no value for the targetList.
- if %targetList% == null {
- define targetList 'li@all'
}
}
}
# Now that we have a flagVal and a targetList, check for canceling
# If the flag is set to allow, cancel the event as needed
- if %flagVal% == allow {
- if %targetList% != li@all {
- if %targetList% !contains %target% {
- determine cancelled
}
}
- queue clear
}
# Must be a deny flag
- if %targetList% == li@all {
- determine cancelled
}
# Cancel the event if the target matches the list, otherwise it's not a denied target.
- if %targetList% contains %target% {
- determine cancelled
}