-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlotUtils.py
430 lines (398 loc) · 15.4 KB
/
PlotUtils.py
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
import org.bukkit.Location as Location
from Helper import color
from Helper import sudo
import pickle
import time.ctime as ctime
import org.bukkit.block.Block.setTypeIdAndData as setBlock
import org.bukkit.Bukkit.getWorld as getWorld
import org.bukkit.World.getBlockAt as getBlock
import org.bukkit.block.Sign.setLine as setLine
config = open('Plots.config')
Conf = {'MiddleLayerEdge' : [155, 2],
'BaseLayerFiller' : [155, 0],
'XLineEdgeFiller' : [155, 0],
'ZLineEdgeFiller' : [155, 0],
'XCenteralFiller' : [155, 0],
'ZCenteralFiller' : [155, 0],
'IsClaimedBottom' : [152, 0],
'IsClaimedSymbol' : [124, 0],
'UnclaimedBottom' : [0, 0],
'UnclaimedSymbol' : [123, 0],
'SymbolXEdgeLine' : [155, 3],
'SymbolZEdgeLine' : [155, 4],
'MapSymbolCorner' : [155, 1],
'PlotMapPosition' : [0,30,0],
'PlotEdgeLengths' : [256 ],
}
for i in config.readlines():
if i.find('#') != -1:
i = i[:i.find('#')]
l = i.replace('\n','').split()
if len(l) > 1:
n = l.pop(0)
if n in Conf:
c = []
for p in l:
try:
c.append(int(p))
except:
c.append(0)
print 'Error while reading config'
print i
else:
Conf[n] = c
Xpos = Conf['PlotMapPosition'][0]
Ypos = Conf['PlotMapPosition'][1]
Zpos = Conf['PlotMapPosition'][2]
PlotSize = Conf['PlotEdgeLengths'][0]
#Loading xeodata files
plots = pickle.load(open("build/Plots.xeodata", "rb"))
players = pickle.load(open("build/Players.xeodata", "rb"))
#Loading op files
opfile = open('build/ops.txt')
ops = []
for i in opfile.readlines():
ops.append(i.replace('\n',''))
opfile.close()
def infreturn(i, sender):
sender.sendMessage(''.join([color('6'),i]))
def redreturn(i, sender):
sender.sendMessage(''.join([color('c'),i]))
def getMapRelative(sender):
loc = sender.getLocation()
X = int(loc.getX())
Z = int(loc.getZ())
X-=Xpos+1
Z-=Zpos+1
if X > 0:
X-=1
else:
X+=1
if Z > 0:
Z-=1
else:
Z+=1
return (X//3,Z//3)
def getMapReverse(X,Z):
X = X*3
Z = Z*3
if X < 0:
X-=1
else:
X+=1
if Z < 0:
Z-=1
else:
Z+=1
return (X+Xpos+2,Z+Zpos+2)
def getlocdual(sender):
if getMapRelative(sender) in plots:
return getMapRelative(sender)
if getloc(sender) in plots:
return getloc(sender)
return False
def getloc(sender):
loc = sender.getLocation()
X = int(loc.getX())
Z = int(loc.getZ())
return (X//PlotSize,Z//PlotSize)
def mapgen(Xa,Za,C,E):
V = getMapReverse(Xa,Za)
X = V[0]
Z = V[1]
if C:
Cb = Conf['IsClaimedBottom'][0]
Cd = Conf['IsClaimedBottom'][1]
else:
Cb = Conf['UnclaimedBottom'][0]
Cd = Conf['UnclaimedBottom'][1]
for x in range(-1,1):
for z in range(-1,1):
getWorld('build').getBlockAt(X+x,Ypos-1,Z+z).setTypeIdAndData(Cb, Cd, False)
if C:
Cb = Conf['IsClaimedSymbol'][0]
Cd = Conf['IsClaimedSymbol'][1]
else:
Cb = Conf['UnclaimedSymbol'][0]
Cd = Conf['UnclaimedSymbol'][1]
for x in range(-1,1):
for z in range(-1,1):
getWorld('build').getBlockAt(X+x,Ypos,Z+z).setTypeIdAndData(Cb, Cd, False)
for x in range(-1,1):
getWorld('build').getBlockAt(X+x,Ypos,Z+1).setTypeIdAndData(Conf['SymbolXEdgeLine'][0], Conf['SymbolXEdgeLine'][1], False)
for z in range(-1,1):
getWorld('build').getBlockAt(X+1,Ypos,Z+z).setTypeIdAndData(Conf['SymbolZEdgeLine'][0], Conf['SymbolZEdgeLine'][1], False)
if E:
for x in range(-1,1):
getWorld('build').getBlockAt(X+x,Ypos,Z-2).setTypeIdAndData(Conf['SymbolXEdgeLine'][0], Conf['SymbolXEdgeLine'][1], False)
for z in range(-1,1):
getWorld('build').getBlockAt(X-2,Ypos,Z+z).setTypeIdAndData(Conf['SymbolZEdgeLine'][0], Conf['SymbolZEdgeLine'][1], False)
getWorld('build').getBlockAt(X+1,Ypos,Z+1).setTypeIdAndData(Conf['MapSymbolCorner'][0], Conf['MapSymbolCorner'][1], False)
if E:
getWorld('build').getBlockAt(X+1,Ypos,Z-2).setTypeIdAndData(Conf['MapSymbolCorner'][0], Conf['MapSymbolCorner'][1], False)
getWorld('build').getBlockAt(X-2,Ypos,Z+1).setTypeIdAndData(Conf['MapSymbolCorner'][0], Conf['MapSymbolCorner'][1], False)
getWorld('build').getBlockAt(X-2,Ypos,Z-2).setTypeIdAndData(Conf['MapSymbolCorner'][0], Conf['MapSymbolCorner'][1], False)
def mapLines(D):
for x in range(-2-(3*D),(3*D)+3):
getWorld('build').getBlockAt(Xpos+x,Ypos,Zpos).setTypeIdAndData(Conf['XCenteralFiller'][0], Conf['XCenteralFiller'][1], False)
getWorld('build').getBlockAt(Xpos+x,Ypos,Zpos+2+(3*D)).setTypeIdAndData(Conf['XLineEdgeFiller'][0], Conf['XLineEdgeFiller'][1], False)
getWorld('build').getBlockAt(Xpos+x,Ypos,Zpos-2-(3*D)).setTypeIdAndData(Conf['XLineEdgeFiller'][0], Conf['XLineEdgeFiller'][1], False)
getWorld('build').getBlockAt(Xpos+x,Ypos-1,Zpos+2+(3*D)).setTypeIdAndData(Conf['MiddleLayerEdge'][0], Conf['MiddleLayerEdge'][1], False)
getWorld('build').getBlockAt(Xpos+x,Ypos-1,Zpos-2-(3*D)).setTypeIdAndData(Conf['MiddleLayerEdge'][0], Conf['MiddleLayerEdge'][1], False)
for z in range(-2-(3*D),(3*D)+3):
getWorld('build').getBlockAt(Xpos,Ypos,Zpos+z).setTypeIdAndData(Conf['ZCenteralFiller'][0], Conf['ZCenteralFiller'][1], False)
getWorld('build').getBlockAt(Xpos+2+(3*D),Ypos,Zpos+z).setTypeIdAndData(Conf['ZLineEdgeFiller'][0], Conf['ZLineEdgeFiller'][1], False)
getWorld('build').getBlockAt(Xpos-2-(3*D),Ypos,Zpos+z).setTypeIdAndData(Conf['ZLineEdgeFiller'][0], Conf['ZLineEdgeFiller'][1], False)
getWorld('build').getBlockAt(Xpos+2+(3*D),Ypos-1,Zpos+z).setTypeIdAndData(Conf['MiddleLayerEdge'][0], Conf['MiddleLayerEdge'][1], False)
getWorld('build').getBlockAt(Xpos-2-(3*D),Ypos-1,Zpos+z).setTypeIdAndData(Conf['MiddleLayerEdge'][0], Conf['MiddleLayerEdge'][1], False)
for x in range(-2-(3*D),(3*D)+3):
getWorld('build').getBlockAt(Xpos+x,Ypos-2,Zpos+z).setTypeIdAndData(Conf['BaseLayerFiller'][0], Conf['BaseLayerFiller'][1], False)
###Start of commands###
@hook.command('ploc', description='Find the plot you are on')
def onCommandsPloc(sender, args):
l = getlocdual(sender)
if l:
infreturn(''.join([color('e'),str(l)]),sender)
if plots[l][0] == False:
infreturn('Unclaimed',sender)
else:
infreturn(''.join(['Claimed by ',plots[l][0]]),sender)
return True
redreturn('No such plot',sender)
return False
@hook.command('pwarp', description='Warp to a particular plot')
def onCommandpwarp(sender, args):
X = None
Z = None
if len(args) == 0:
if getMapRelative(sender) in plots:
X = getMapRelative(sender)[0]
Z = getMapRelative(sender)[1]
else:
redreturn('/pwarp [X] [Z] OR /pwarp [player]', sender)
return False
elif args[0] in players:
if len(args) == 2:
if args[1].replace('-','').isdigit():
try:
C = players[args[0]][0][int(args[1])-1]
X = C[0]
Z = C[1]
except:
infreturn('No such plot', sender)
return False
else:
C = players[args[0]][0][0]
X = C[0]
Z = C[1]
elif len(args) == 2:
try:
X = int(args[0])
Z = int(args[1])
except:
redreturn('Coords must be two values', sender)
return False
O = plots.get((X,Z))
if O == None:
infreturn('No such plot', sender)
return False
if O[0] != False:
infreturn(''.join(['Teleporting to ',O[0],"'s plot #",str(plots[(X,Z)][1]),'; ',str(X),',',str(Z)]), sender)
else:
infreturn(''.join(['Teleporting to plot ',str(X),',',str(Z),' - Unclaimed']), sender)
sudo(' '.join(['tppos',sender.getName(),str((X * PlotSize) + (PlotSize/2)),'18',str((Z * PlotSize) + (PlotSize/2))]))
return True
@hook.command('pclaim', description='Claim a particular plot')
def onCommandClaim(sender, args):
global plots, players
if not len(args):
l = getlocdual(sender)
if l:
args.append(str(l[0]))
args.append(str(l[1]))
else:
redreturn('/punclaim [X] [Z]', sender)
return False
try:
X = int(args[0])
Z = int(args[1])
except:
redreturn('/claim [X] [Z]', sender)
return False
if (X,Z) in plots:
if plots[(X,Z)][0] == False:
n = sender.getName()
if not n in players:
players[n] = [[(X,Z)],1]
plots[(X,Z)] = [n,1,ctime()]
T = ctime().split()
mapgen(X,Z,True,False)
infreturn('New user defined, and given a plot', sender)
saveall()
return True
else:
p = players[n]
if len(p[0]) < p[1]:
p[0].append((X,Z))
plots[(X,Z)] = [n,len(p[0]),ctime()]
infreturn('Plot claimed', sender)
T = ctime().split()
mapgen(X,Z,True,False)
saveall()
return True
infreturn('You cannot claim another plot', sender)
return False
infreturn('That plot is claimed, or something, I dunno..', sender)
return False
infreturn('That plot does not exist yet', sender)
return False
@hook.command('pgenerate', description='Generate new plots')
def onCommandGenerate(sender, args):
global plots, players
if not sender.getName() in ops:
redreturn('No permission', sender)
return False
if len(args) == 0:
infreturn('/generate [diameter]', sender)
return False
ignore = False
if len(args) == 2:
if args[2] == 'ignore':
ignore = True
if args[0].isdigit():
d = int(args[0])
i = 0
for x in range(-d,d):
for z in range(-d,d):
if plots.get((x,z)) == None or ignore:
plots[(x,z)] = [False,0,'']
if x == -d or x == d-1 or z == -d or z == d-1 or x == 0 or z == 0:
E = True
else:
E = False
mapgen(x,z,False,E)
mapLines(d)
i+=1
saveall()
infreturn(''.join(['Generated ',str(i),'. plots']), sender)
return True
@hook.command('pgive', description='Give someone an extra plot')
def onCommandGiveplot(sender, args):
global players
if not sender.getName() in ops:
redreturn('No permission', sender)
return False
if len(args) == 0:
redreturn('/pgive [player]', sender)
n = args[0]
if n in players:
players[n][1] += 1
saveall()
infreturn(''.join([n,' now can have ',str(players[n][1]),' plots']), sender)
return True
infreturn('Not a valid player', sender)
return False
@hook.command('ptake', description='Take away the ability to claim an extra plot')
def onCommandGiveplot(sender, args):
global players
if not sender.getName() in ops:
redreturn('No permission', sender)
return False
if len(args) == 0:
redreturn('/ptake [player]', sender)
n = args[0]
if n in players:
if len(players[n][0]) == players[n][1]:
redreturn('That player must have a plot unclaimed first', sender)
return False
players[n][1] -= 1
saveall()
infreturn(''.join([n,' now can have ',str(players[n][1]),' plots']), sender)
return True
infreturn('Not a valid player', sender)
return False
@hook.command('punclaim', description='Unclaim a plot')
def onCommandUnclaim(sender, args):
global players, plots
if not len(args):
l = getlocdual(sender)
if l:
args.append(str(l[0]))
args.append(str(l[1]))
else:
redreturn('/punclaim [X] [Z]', sender)
return False
if len(args) == 2:
if args[0].replace('-','').isdigit() and args[1].replace('-','').isdigit():
X = int(args[0])
Z = int(args[1])
if (X,Z) in plots:
if plots[(X,Z)][0] != False:
if plots[(X,Z)][0] == sender.getName() or sender.getName() in ops:
players[plots[(X,Z)][0]][0].remove((X,Z))
plots[(X,Z)] = [False,0,'']
mapgen(X,Z,False,False)
saveall()
infreturn('Plot unclaimed', sender)
return True
redreturn('You do not own that plot', sender)
return False
redreturn('No such plot', sender)
return False
redreturn('Your coords must be integers', sender)
return False
redreturn('/punclaim [X] [Z]', sender)
return False
@hook.command('psearch', description='Search for a user or plot')
def onCommandPsearch(sender, args):
if not len(args):
l = getlocdual(sender)
if l:
args.append(str(l[0]))
args.append(str(l[1]))
else:
redreturn('/psearch [X] [Z] OR [Name] OR [Partial]', sender)
if args[0] in players:
p = players[args[0]]
for i, v in enumerate(p[0]):
infreturn(''.join(['Plot #',color('e'),str(i)]), sender)
infreturn(''.join([color('e'),str(v)]), sender)
infreturn(''.join(['Claimed ',color('e'),' '.join(plots[v][2].split())]), sender)
return True
if len(args) == 1:
for i in players:
if i.lower().find(args[0].lower()) != -1:
infreturn(''.join([color('e'),'']), sender)
for a, v in enumerate(players[i][0]):
infreturn(i, sender)
infreturn(''.join([color('6'),'Plot #',color('e'),str(a+1)]), sender)
infreturn(''.join([color('e'),str(v)]), sender)
infreturn(''.join([color('6'),'Claimed ',color('e'),' '.join(plots[v][2].split())]), sender)
return True
if len(args) == 2:
if args[0].replace('-','').isdigit() and args[1].replace('-','').isdigit():
if (int(args[0]),int(args[1])) in plots:
p = plots[(int(args[0]),int(args[1]))]
if p[0] != False:
infreturn(''.join([color('6'),'Claimed by ',color('e'),p[0]]), sender)
infreturn(''.join([color('6'),'Claimed ',color('e'),' '.join(p[2].split())]), sender)
return True
else:
infreturn('Unclaimed', sender)
return True
redreturn('Plot not generated', sender)
return False
redreturn('Your coords must be numeric', sender)
return False
redreturn('/psearch [Criteria]', sender)
return False
@hook.command('pusers', description='Lists all users')
def userlist(sender, args):
t = list(players)
t.sort()
infreturn(', '.join(t), sender)
return True
def saveall():
pickle.dump(plots, open("build/Plots.xeodata", "wb"))
pickle.dump(players, open("build/Players.xeodata", "wb"))
return