-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprotect.py
More file actions
73 lines (57 loc) · 2.45 KB
/
protect.py
File metadata and controls
73 lines (57 loc) · 2.45 KB
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
"""
Protects areas against block destroying/building.
Commands
^^^^^^^^
* ``/protect <area coordinates>`` puts an area under protected status *admin only*
* ``/protect`` clears all protected areas *admin only*
.. codeauthor:: hompy
"""
from piqueserver.commands import command, admin
from pyspades.common import coordinates
@command(admin_only=True)
def protect(connection, value=None):
protocol = connection.protocol
if value is None:
protocol.protected = None
protocol.broadcast_chat('All areas unprotected', irc=True)
else:
if protocol.protected is None:
protocol.protected = set()
pos = coordinates(value)
protocol.protected.symmetric_difference_update([pos])
message = 'The area at %s is now %s' % (
value.upper(),
'protected' if pos in protocol.protected else 'unprotected')
protocol.broadcast_chat(message, irc=True)
def apply_script(protocol, connection, config):
class ProtectConnection(connection):
def _block_available(self, x, y, z):
if not self.god and self.protocol.is_protected(x, y, z):
return False
def on_block_build_attempt(self, x, y, z):
if not self.god and self.protocol.is_protected(x, y, z):
return False
return connection.on_block_build_attempt(self, x, y, z)
def on_line_build_attempt(self, points):
if not self.god:
for point in points:
if self.protocol.is_protected(*point):
return False
return connection.on_line_build_attempt(self, points)
class ProtectProtocol(protocol):
protected = None
def on_map_change(self, map):
self.protected = set(coordinates(s) for s in
getattr(self.map_info.info, 'protected', []))
protocol.on_map_change(self, map)
def is_indestructable(self, x, y, z):
if self.is_protected(x, y, z):
return True
return protocol.is_indestructable(self, x, y, z)
def is_protected(self, x, y, z):
if self.protected:
for sx, sy in self.protected:
if x >= sx and y >= sy and x < sx + 64 and y < sy + 64:
return True
return False
return ProtectProtocol, ProtectConnection