View difference between Paste ID: eEiSzWEP and VycB36NF
SHOW: | | - or go back to the newest paste.
1
"""
2-
Map Extensions+
2+
Extensions to the map metadata (e.g. water damage).
3-
Extensions to the map metadata;
3+
4-
 - Water Damage
4+
5-
 - Map-Specific Command Removal
5+
6-
 - Spawn Locations
6+
7-
 - Block Protection
7+
8
import random
9
10
def apply_script(protocol, connection, config):
11
    class MapExtensionConnection(connection):
12
        
13
        def on_position_update(self):
14
            extensions = self.protocol.map_info.extensions
15
            if (extensions.has_key('water_damage') and
16
                self.world_object.position.z>=61):
17
                water_damage = extensions['water_damage']
18
                self.environment_hit(water_damage)
19
            if (extensions.has_key('boundary_damage')):
20
                x = self.world_object.position.x
21
                y = self.world_object.position.y
22
                boundary_damage = extensions['boundary_damage']
23
                if (x<=boundary_damage['left'] or x>=boundary_damage['right'] or
24
                    y<=boundary_damage['top'] or y>=boundary_damage['bottom']):
25
                    self.environment_hit(boundary_damage['damage'])                
26
            connection.on_position_update(self)
27
    
28
        def environment_hit(self, value):
29
            if value < 0 and self.hp >= 100: # do nothing at max health
30
                return
31
            self.set_hp(self.hp - value)
32
        
33
        def on_command(self, command, parameters):
34
            disabled = self.protocol.map_info.extensions.get(
35
                'disabled_commands', [])
36
            if command in disabled:
37
                self.send_chat("Command '%s' disabled for this map" % command)
38
                return
39
            return connection.on_command(self, command, parameters)
40
            
41
            
42
        def on_spawn_location(self, pos):
43
            extensions = self.protocol.map_info.extensions
44
            if (extensions.has_key('blue_spawn')):
45
                blue_spawn_centre = extensions['blue_spawn']
46
            else:
47
                blue_spawn_centre = None
48
            if (extensions.has_key('green_spawn')):
49
                green_spawn_centre = extensions['green_spawn']
50
            else:
51
                green_spawn_centre = None
52
            if (extensions.has_key('blue_spawn_offset')):
53
                blue_spawn_offset = extensions['blue_spawn_offset']
54
            else:
55
                blue_spawn_offset = 100
56
            if (extensions.has_key('green_spawn_offset')):
57
                green_spawn_offset = extensions['green_spawn_offset']
58
            else:
59
                green_spawn_offset = 100
60
            if self.team == self.protocol.blue_team:
61
                spawn_centre = blue_spawn_centre
62
                spawn_offset = blue_spawn_offset
63
            elif self.team == self.protocol.green_team:
64
                spawn_centre = green_spawn_centre
65
                spawn_offset = green_spawn_offset
66
            if spawn_centre != None:
67
                spawn_choice = random.choice(spawn_centre)
68
                if len(spawn_choice) == 3:
69
                    x1, y1, z = spawn_choice
70
                    x, y = self.protocol.map.get_random_point((x1 - spawn_offset), (y1 - spawn_offset), (x1 + spawn_offset), (y1 + spawn_offset))
71
                    newpos = x, y, z
72
                    return newpos
73
                elif len(spawn_choice) == 2:
74
                    x1, y1 = spawn_choice
75
                    x, y = self.protocol.map.get_random_point((x1 - spawn_offset), (y1 - spawn_offset), (x1 + spawn_offset), (y1 + spawn_offset))
76
                    z = self.protocol.map.get_z(x, y)
77
                    newpos = x, y, z
78
                    return newpos
79
            return connection.on_spawn_location(self, pos)
80
                    
81
        def on_block_destroy(self, x, y, z, mode):
82
            if not self.god:
83
                extensions = self.protocol.map_info.extensions
84
                protect = False
85
                if (extensions.has_key('protected')):
86
                    protect = True
87
                    protected = extensions['protected']
88-
            if (extensions.has_key('protected')):
88+
                if (extensions.has_key('nodestroy')):
89-
                protected = extensions['protected']
89+
                    if protect:
90-
            if mode == 3:
90+
                        protected = extensions['nodestroy'] + extensions['protected']
91-
                grenade_prevention = 1
91+
                    else:
92
                        protected = extensions['nodestroy']
93-
                grenade_prevention = 0
93+
                    protect = True
94-
            for area in protected:
94+
                    if mode == 3:
95-
                start, finish = area
95+
                        grenade_prevention = 1
96-
                a, b, c = start
96+
                    else:
97-
                d, e, f = finish
97+
                        grenade_prevention = 0
98-
                if a <= d:
98+
                    for area in protected:
99-
                    start_x = a - grenade_prevention
99+
                        start, finish = area
100-
                    finish_x = d + grenade_prevention
100+
                        a, b, c = start
101-
                else:
101+
                        d, e, f = finish
102-
                    start_x = d - grenade_prevention
102+
                        if a <= d:
103-
                    finish_x = a + grenade_prevention
103+
                            start_x = a - grenade_prevention
104-
                if b <= e:
104+
                            finish_x = d + grenade_prevention
105-
                    start_y = b - grenade_prevention
105+
                        else:
106-
                    finish_y = e + grenade_prevention
106+
                            start_x = d - grenade_prevention
107-
                else:
107+
                            finish_x = a + grenade_prevention
108-
                    start_y = e - grenade_prevention
108+
                        if b <= e:
109-
                    finish_y = b + grenade_prevention
109+
                            start_y = b - grenade_prevention
110-
                if c <= f:
110+
                            finish_y = e + grenade_prevention
111-
                    start_z = c - grenade_prevention
111+
                        else:
112-
                    finish_z = f + grenade_prevention
112+
                            start_y = e - grenade_prevention
113-
                else:
113+
                            finish_y = b + grenade_prevention
114-
                    start_z = f - grenade_prevention
114+
                        if c <= f:
115-
                    finish_z = c + grenade_prevention
115+
                            start_z = c - grenade_prevention
116-
                if (start_x <= x <= finish_x and start_y <= y <= finish_y 
116+
                            finish_z = f + grenade_prevention
117-
                    and start_z <= z <= finish_z):
117+
                        else:
118-
                    self.send_chat('This area is protected!')
118+
                            start_z = f - grenade_prevention
119-
                    return False     
119+
                            finish_z = c + grenade_prevention
120
                        if (start_x <= x <= finish_x and start_y <= y <= finish_y 
121
                            and start_z <= z <= finish_z):
122
                                if self.admin:
123
                                    self.send_chat('You cannot destroy blocks in this area - activate GOD MODE to do so!')
124-
            if (extensions.has_key('protected')):
124+
                                else:
125-
                protected = extensions['protected']
125+
                                    self.send_chat('You cannot destroy blocks in this area!')
126-
            for area in protected:
126+
                                return False     
127-
                start, finish = area
127+
128-
                a, b, c = start
128+
129-
                d, e, f = finish
129+
130-
                if a <= d:
130+
            if not self.god:
131-
                    start_x = a
131+
                extensions = self.protocol.map_info.extensions
132-
                    finish_x = d
132+
                protect = False
133-
                else:
133+
                if (extensions.has_key('protected')):
134-
                    start_x = d
134+
                    protect = True
135-
                    finish_x = a
135+
                    protected = extensions['protected']
136-
                if b <= e:
136+
                if (extensions.has_key('nobuild')):
137-
                    start_y = b
137+
                    if protect:
138-
                    finish_y = e
138+
                        protected = extensions['nobuild'] + extensions['protected']
139-
                else:
139+
                    else:
140-
                    start_y = e
140+
                        protected = extensions['nobuild']
141-
                    finish_y = b
141+
                    protect = True
142-
                if c <= f:
142+
                if protect:
143-
                    start_z = c
143+
                    for area in protected:
144-
                    finish_z = f
144+
                        start, finish = area
145-
                else:
145+
                        a, b, c = start
146-
                    start_z = f
146+
                        d, e, f = finish
147-
                    finish_z = c
147+
                        if a <= d:
148-
                if (start_x <= x <= finish_x and start_y <= y <= finish_y 
148+
                            start_x = a
149-
                    and start_z <= z <= finish_z):
149+
                            finish_x = d
150-
                    self.send_chat('This area is protected!')
150+
                        else:
151-
                    return False    
151+
                            start_x = d
152
                            finish_x = a
153
                        if b <= e:
154
                            start_y = b
155
                            finish_y = e
156-
            if (extensions.has_key('protected')):
156+
                        else:
157-
                protected = extensions['protected']
157+
                            start_y = e
158-
            for area in protected:
158+
                            finish_y = b
159-
                start, finish = area
159+
                        if c <= f:
160-
                a, b, c = start
160+
                            start_z = c
161-
                d, e, f = finish
161+
                            finish_z = f
162-
                if a <= d:
162+
                        else:
163-
                    start_x = a
163+
                            start_z = f
164-
                    finish_x = d
164+
                            finish_z = c
165-
                else:
165+
                        if (start_x <= x <= finish_x and start_y <= y <= finish_y 
166-
                    start_x = d
166+
                            and start_z <= z <= finish_z):
167-
                    finish_x = a
167+
                                if self.admin:
168-
                if b <= e:
168+
                                    self.send_chat('You cannot build in this area - activate GOD MODE to do so!')
169-
                    start_y = b
169+
                                else:
170-
                    finish_y = e
170+
                                    self.send_chat('You cannot build in this area!')
171-
                else:
171+
                                return False    
172-
                    start_y = e
172+
173-
                    finish_y = b
173+
174-
                if c <= f:
174+
175-
                    start_z = c
175+
            if not self.god:
176-
                    finish_z = f
176+
                extensions = self.protocol.map_info.extensions
177-
                else:
177+
                protect = False
178-
                    start_z = f
178+
                if (extensions.has_key('protected')):
179-
                    finish_z = c
179+
                    protect = True
180-
                for point in points:
180+
                    protected = extensions['protected']
181-
                    x, y, z = point
181+
                if (extensions.has_key('nobuild')):
182-
                    if (start_x <= x <= finish_x and start_y <= y <= finish_y 
182+
                    if protect:
183-
                        and start_z <= z <= finish_z):
183+
                        protected = extensions['nobuild'] + extensions['protected']
184-
                        self.send_chat('This area is protected!')
184+
                    else:
185-
                        return False    
185+
                        protected = extensions['nobuild']
186
                    protect = True
187
                if protect:
188
                    for area in protected:
189
                        start, finish = area
190
                        a, b, c = start
191
                        d, e, f = finish
192
                        if a <= d:
193
                            start_x = a
194
                            finish_x = d
195
                        else:
196
                            start_x = d
197
                            finish_x = a
198
                        if b <= e:
199
                            start_y = b
200
                            finish_y = e
201
                        else:
202
                            start_y = e
203
                            finish_y = b
204
                        if c <= f:
205
                            start_z = c
206
                            finish_z = f
207
                        else:
208
                            start_z = f
209
                            finish_z = c
210
                        for point in points:
211
                            x, y, z = point
212
                            if (start_x <= x <= finish_x and start_y <= y <= finish_y 
213
                                and start_z <= z <= finish_z):
214
                                if self.admin:
215
                                    self.send_chat('You cannot build in this area - activate GOD MODE to do so!')
216
                                else:
217
                                    self.send_chat('You cannot build in this area!')
218
                                return False  
219
            return connection.on_line_build_attempt(self, points) 
220
            
221
            
222
    return protocol, MapExtensionConnection