This repository has been archived by the owner on Jun 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
iland-core.lua
5178 lines (4841 loc) · 156 KB
/
iland-core.lua
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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--[[ ------------------------------------------------------
__ __ ______ __ __ _____
/\ \ /\ \ /\ __ \ /\ "-.\ \ /\ __-.
\ \ \ \ \ \____ \ \ __ \ \ \ \-. \ \ \ \/\ \
\ \_\ \ \_____\ \ \_\ \_\ \ \_\\"\_\ \ \____-
\/_/ \/_____/ \/_/\/_/ \/_/ \/_/ \/____/
Author RedbeanW
Github https://github.com/LiteLDev-LXL/iLand-Core
License GPLv3 未经许可禁止商业使用
--]] ------------------------------------------------------
Plugin = {
Version = {
major = 2,
minor = 8,
revision = 4,
toString = function()
local ver = Plugin.Version
return tostring(ver.major)..'.'..tostring(ver.minor*10 + ver.revision)
end,
toNumber = function()
local ver = Plugin.Version
return ver.major*100+ver.minor*10+ver.revision
end,
getApi = function()
return 201
end
},
minLL = {2,1,0},
}
Server = {
link = "https://cdn.jsdelivr.net/gh/LiteLDev-LXL/Cloud/",
version = 203,
memData = {}
}
JSON = {
_base = require('dkjson'),
parse = function(str)
local stat,rtn = pcall(JSON._base.decode,str)
if stat then
return rtn
end
return nil
end,
stringify = function(object)
local stat,rtn = pcall(JSON._base.encode,object)
if stat then
return rtn
end
return nil
end
}
MEM = {}
DATA_PATH = 'plugins/iland/'
-- [Tpl] config.json
local cfg = {
version = Plugin.Version.toNumber(),
plugin = {
network = true,
language = "zh_CN"
},
land = {
operator = {},
max_lands = 5,
bought = {
three_dimension = {
enable = true,
calculate = "{square}*8+{height}*20",
},
two_dimension = {
enable = true,
calculate = "{square}*25",
},
square_range = {4,50000},
discount = 1
},
min_space = 15,
refund_rate = 0.9
},
economic = {
protocol = "llmoney",
scoreboard_objname = "",
currency_name = "Coin"
},
features = {
landsign = {
enable = true,
frequency = 2
},
buttomsign = {
enable = true,
frequency = 1
},
particles = {
enable = true,
name = "minecraft:villager_happy",
max_amount = 600
},
player_selector = {
include_offline_players = true
},
selection = {
dimension = {
true, -- overworld
true, -- nether
true -- end
},
tool_type = "minecraft:wooden_axe",
tool_name = "Wooden Axe"
},
landtp = true,
force_talk = false,
disable_creative_warn = false,
disabled_listener = {
'onDropItem'
},
chunk_side = 16
}
}
-- Init debug mode.
DEV_MODE = false
if File.exists("EnableILandDevMode") then
DEV_MODE = true
DATA_PATH = 'Project/iLand/iland/'
end
-- Init logger.
logger.setTitle("ILand")
logger.setConsole(true)
function INFO(msgtype,content)
if not content then
content = msgtype
msgtype = ""
else
msgtype = msgtype..' >> '
end
if string.find(content,'\n') then
for n,msg in pairs(string.split(content,'\n')) do
INFO(msg,nil)
end
return
end
logger.info(content)
end
function ERROR(content)
logger.error(content)
end
function WARN(content)
logger.warn(content)
end
-- Register to LiteLoader.
if not ll.requireVersion(Plugin.minLL[1],Plugin.minLL[2],Plugin.minLL[3]) then
error('Unsupported version of LiteLoader, plugin loading aborted.')
else
assert(ll.registerPlugin(
'iLand',
'Powerful land plugin.',
{
major = Plugin.Version.major,
minor = Plugin.Version.minor,
revision = Plugin.Version.revision
},
{
Author = 'RedbeanW',
Github = 'https://github.com/LiteLScript-Dev/iLand-Core',
License = 'GPLv3 with additional conditions.'
}
),'Plugin registration failed!')
end
-- Classes.
Map = {
Init = function()
INFO('Load',_Tr('console.loading.map.load'))
for landId,data in pairs(DataStorage.Land.Raw) do
Map.Land.Position.update(landId,'add')
Map.Land.Trusted.update(landId)
Map.Land.Owner.update(landId)
Map.Land.AXIS.update(landId,'add')
Map.Chunk.update(landId,'add')
Map.CachedQuery.Init(landId)
end
Map.Land.Operator.update()
Map.Control.build()
Map.Listener.build()
setInterval(Map.CachedQuery.CACHE_MANAGER,1000*8)
return true
end,
Chunk = {
data = {
[0] = {}, -- 主世界
[1] = {}, -- 地狱
[2] = {} -- 末地
},
update = function(landId,mode)
local TxTz = {} -- ChunkData(position)
local ra = Map.Land.Position.data[landId]
local posA,posB = ra.posA,ra.posB
local dimid = ra.dimid
local function chkNil(table,a,b)
table[a] = table[a] or {}
table[a][b] = table[a][b] or {}
end
local size = cfg.features.chunk_side
local sX = posA.x
local sZ = posA.z
local count = 0
while (sX+size*count<=posB.x+size) do
local Cx,Cz = Pos.ToChunkPos({x=sX+size*count,z=sZ+size*count})
chkNil(TxTz,Cx,Cz)
local count2 = 0
while (sZ+size*count2<=posB.z+size) do
Cx,Cz = Pos.ToChunkPos({x=sX+size*count,z=sZ+size*count2})
chkNil(TxTz,Cx,Cz)
count2 = count2 + 1
end
count = count + 1
end
-- [CODE] Add or Del some chunks.
for Tx,a in pairs(TxTz) do
for Tz,b in pairs(a) do
-- Tx Tz
if mode=='add' then
chkNil(Map.Chunk.data[dimid],Tx,Tz)
if not Array.Fetch(Map.Chunk.data[dimid][Tx][Tz],landId) then
table.insert(Map.Chunk.data[dimid][Tx][Tz],#Map.Chunk.data[dimid][Tx][Tz]+1,landId)
end
elseif mode=='del' then
Array.Remove(Map.Chunk.data[dimid][Tx][Tz],landId)
end
end
end
end
},
Land = {
Position = {
data = {},
update = function(landId,mode)
if mode=='add' then
local ra = DataStorage.Land.Raw[landId].range
local posA = Array.ToIntPos(ra.start_position)
local posB = Array.ToIntPos(ra.end_position)
Map.Land.Position.data[landId] = Cube.Create(posA,posB,ra.dimid)
elseif mode=='del' then
Map.Land.Position.data[landId] = nil
end
end
},
AXIS = {
data = {
[0] = {['x'] = {},['y'] = {},['z'] = {}}, -- Overworld
[1] = {['x'] = {},['y'] = {},['z'] = {}}, -- Nether
[2] = {['x'] = {},['y'] = {},['z'] = {}} -- End
},
update = function(landId,mode)
local ra = Map.Land.Position.data[landId]
local posA,posB,dimid = ra.posA,ra.posB,ra.dimid
if mode == 'add' then
for x = posA.x,posB.x do
local tar = Map.Land.AXIS.data[dimid]['x']
if not tar[x] then
tar[x] = {}
end
tar[x][#tar[x]+1] = landId
end
for y = posA.y,posB.y do
local tar = Map.Land.AXIS.data[dimid]['y']
if not tar[y] then
tar[y] = {}
end
tar[y][#tar[y]+1] = landId
end
for z = posA.z,posB.z do
local tar = Map.Land.AXIS.data[dimid]['z']
if not tar[z] then
tar[z] = {}
end
tar[z][#tar[z]+1] = landId
end
elseif mode == 'del' then
for x = posA.x,posB.x do
Array.Remove(Map.Land.AXIS.data[dimid]['x'][x],landId)
end
for y = posA.y,posB.y do
Array.Remove(Map.Land.AXIS.data[dimid]['y'][y],landId)
end
for z = posA.z,posB.z do
Array.Remove(Map.Land.AXIS.data[dimid]['z'][z],landId)
end
end
end
},
Trusted = {
data = {},
update = function(landId)
Map.Land.Trusted.data[landId] = Array.ToKeyMap(DataStorage.Land.Raw[landId].settings.share)
end
},
Owner = {
data = {},
update = function(landId)
Map.Land.Owner.data[landId] = Land.RelationShip.Owner.getXuid(landId)
end
},
Operator = {
data = {},
update = function()
Map.Land.Operator.data = Array.ToKeyMap(cfg.land.operator)
end
}
},
Listener = {
data = {},
build = function()
Map.Listener.data = Array.ToKeyMap(cfg.features.disabled_listener)
end,
check = function(listener)
return Map.Listener.data[listener] == nil
end
},
Control = {
data = {},
build = function()
Map.Control.data = {
-- # UseItem
[0] = Array.ToKeyMap({
'minecraft:bed','minecraft:chest','minecraft:trapped_chest','minecraft:crafting_table',
'minecraft:campfire','minecraft:soul_campfire','minecraft:composter','minecraft:undyed_shulker_box',
'minecraft:shulker_box','minecraft:noteblock','minecraft:jukebox','minecraft:bell',
'minecraft:daylight_detector_inverted','minecraft:daylight_detector','minecraft:lectern',
'minecraft:cauldron','minecraft:lever','minecraft:stone_button','minecraft:wooden_button',
'minecraft:spruce_button','minecraft:birch_button','minecraft:jungle_button','minecraft:acacia_button',
'minecraft:dark_oak_button','minecraft:crimson_button','minecraft:warped_button',
'minecraft:polished_blackstone_button','minecraft:respawn_anchor','minecraft:trapdoor',
'minecraft:spruce_trapdoor','minecraft:birch_trapdoor','minecraft:jungle_trapdoor',
'minecraft:acacia_trapdoor','minecraft:dark_oak_trapdoor','minecraft:crimson_trapdoor',
'minecraft:warped_trapdoor','minecraft:fence_gate','minecraft:spruce_fence_gate',
'minecraft:birch_fence_gate','minecraft:jungle_fence_gate','minecraft:acacia_fence_gate',
'minecraft:dark_oak_fence_gate','minecraft:crimson_fence_gate','minecraft:warped_fence_gate',
'minecraft:wooden_door','minecraft:spruce_door','minecraft:birch_door','minecraft:jungle_door',
'minecraft:acacia_door','minecraft:dark_oak_door','minecraft:crimson_door','minecraft:warped_door',
'minecraft:dragon_egg','minecraft:flower_pot'
}),
-- # onBlockInteracted
[1] = Array.ToKeyMap({
'minecraft:cartography_table','minecraft:smithing_table','minecraft:furnace','minecraft:blast_furnace',
'minecraft:smoker','minecraft:brewing_stand','minecraft:anvil','minecraft:grindstone','minecraft:enchanting_table',
'minecraft:barrel','minecraft:beacon','minecraft:hopper','minecraft:dropper','minecraft:dispenser',
'minecraft:loom','minecraft:stonecutter_block','minecraft:lit_furnace','minecraft:lit_blast_furnace',
'minecraft:lit_smoker'
}),
-- # ItemWhiteList
[2] = Array.ToKeyMap({
'minecraft:glow_ink_sac','minecraft:end_crystal','minecraft:ender_eye','minecraft:axolotl_bucket',
'minecraft:powder_snow_bucket','minecraft:pufferfish_bucket','minecraft:tropical_fish_bucket',
'minecraft:salmon_bucket','minecraft:cod_bucket','minecraft:water_bucket','minecraft:cod_bucket',
'minecraft:lava_bucket','minecraft:bucket','minecraft:flint_and_steel','minecraft:skull',
'minecraft:wooden_axe','minecraft:stone_axe','minecraft:iron_axe','minecraft:golden_axe',
'minecraft:diamond_axe','minecraft:netherite_axe','minecraft:banner'
}),
-- # Special attack.
[3] = Array.ToKeyMap({
'minecraft:ender_crystal','minecraft:armor_stand'
}),
-- # EntityTypeList
[4] = {
animals = Array.ToKeyMap({
'minecraft:axolotl','minecraft:bat','minecraft:cat','minecraft:chicken',
'minecraft:cod','minecraft:cow','minecraft:donkey','minecraft:fox',
'minecraft:glow_squid','minecraft:horse','minecraft:mooshroom','minecraft:mule',
'minecraft:ocelot','minecraft:parrot','minecraft:pig','minecraft:rabbit',
'minecraft:salmon','minecraft:snow_golem','minecraft:sheep','minecraft:skeleton_horse',
'minecraft:squid','minecraft:strider','minecraft:tropical_fish','minecraft:turtle',
'minecraft:villager_v2','minecraft:wandering_trader','minecraft:npc'
}),
mobs = Array.ToKeyMap({
-- type A
'minecraft:pufferfish','minecraft:bee','minecraft:dolphin','minecraft:goat',
'minecraft:iron_golem','minecraft:llama','minecraft:llama_spit','minecraft:wolf',
'minecraft:panda','minecraft:polar_bear','minecraft:enderman','minecraft:piglin',
'minecraft:spider','minecraft:cave_spider','minecraft:zombie_pigman',
-- type B
'minecraft:blaze','minecraft:small_fireball','minecraft:creeper','minecraft:drowned',
'minecraft:elder_guardian','minecraft:endermite','minecraft:evocation_illager','minecraft:evocation_fang',
'minecraft:ghast','minecraft:fireball','minecraft:guardian','minecraft:hoglin',
'minecraft:husk','minecraft:magma_cube','minecraft:phantom','minecraft:pillager',
'minecraft:ravager','minecraft:shulker','minecraft:shulker_bullet','minecraft:silverfish',
'minecraft:skeleton','minecraft:skeleton_horse','minecraft:slime','minecraft:vex',
'minecraft:vindicator','minecraft:witch','minecraft:wither_skeleton','minecraft:zoglin',
'minecraft:zombie','minecraft:zombie_villager_v2','minecraft:piglin_brute','minecraft:ender_dragon',
'minecraft:dragon_fireball','minecraft:wither','minecraft:wither_skull','minecraft:wither_skull_dangerous'
})
},
-- # AttackBlock
[5] = Array.ToKeyMap({
'minecraft:dragon_egg'
})
}
end,
check = function(mode,name)
return Map.Control.data[mode][name] ~= nil
end
},
CachedQuery = {
Init = function(landId)
local map = Map.CachedQuery
map.RangeArea.recorded_landId[landId] = {}
map.SinglePos.land_recorded_pos[landId] = {}
end,
UnInit = function(landId)
local map = Map.CachedQuery
map.RangeArea.recorded_landId[landId] = nil
map.SinglePos.land_recorded_pos[landId] = nil
end,
SinglePos = {
data = {},
land_recorded_pos = {}, -- query recorded strpos by landId.
non_land_pos = {}, -- non-land position recorded.
add = function(landId,pos)
local strpos = Pos.ToString(pos,true)
local map = Map.CachedQuery.SinglePos
if map.data[strpos] then
map.clear(strpos)
end
map.data[strpos] = {
landId = landId,
raw = Pos.ToIntPos(pos),
querying = true
}
if landId then
map.land_recorded_pos[landId][#map.land_recorded_pos[landId]+1] = strpos
else
map.non_land_pos[#map.non_land_pos+1] = strpos
end
end,
get = function(pos)
local strpos = Pos.ToString(pos,true)
local map = Map.CachedQuery.SinglePos
local record = map.data[strpos]
if record then
record.querying = true
return true,record.landId
end
return false,nil
end,
clear = function(strpos) -- clear single pos's cache
local map = Map.CachedQuery.SinglePos
local record = map.data[strpos]
if not record then
return
end
local landId = record.landId
if landId then
Array.Remove(map.land_recorded_pos[landId],strpos)
else
Array.Remove(map.non_land_pos,strpos)
end
map.data[strpos] = nil
end,
check_noland_pos = function() -- when new land created, clear old non-land cached pos.
local map = Map.CachedQuery.SinglePos
for n,strpos in pairs(map.non_land_pos) do
if Land.Query.Pos(map.data[strpos].raw,true) then
map.clear(strpos)
end
end
end,
refresh = function(landId) -- remove single land's cache
if not landId then
return
end
local map = Map.CachedQuery.SinglePos
for n,strpos in pairs(map.land_recorded_pos[landId]) do
map.data[strpos] = nil -- DO NOT USE map.clear!!
end
map.land_recorded_pos[landId] = {}
end
},
RangeArea = {
data = {},
recorded_landId = {},
add = function(lands,AABB)
local map = Map.CachedQuery.RangeArea
local cubestr = Cube.ToString(AABB)
map.data[cubestr] = {
raw = AABB,
landlist = lands,
querying = true
}
for n,landId in pairs(lands) do
map.recorded_landId[landId][#map.recorded_landId[landId]+1] = "this."..cubestr..".landlist.(*)"..n
end
end,
get = function(AABB)
local map = Map.CachedQuery.RangeArea
local cubestr = Cube.ToString(AABB)
local record = map.data[cubestr]
if record then
record.querying = true
return record.landlist
end
return nil
end,
clear_range = function(cubestr) -- clear single range's cache.
local map = Map.CachedQuery.RangeArea
for n,landId in pairs(map.data[cubestr].landlist) do
Array.Remove(map.recorded_landId[landId],"this."..cubestr..".landlist.(*)"..n)
end
map.data[cubestr] = nil
end,
clear_by_land = function(landId) -- clear cached "range" if "range" in this range.
local map = Map.CachedQuery.RangeArea
for cubestr,rangeInfo in pairs(map.data) do
if Array.Fetch(Land.Query.Area(rangeInfo.raw,true),landId) then
map.clear_range(cubestr)
end
end
end,
refresh = function(landId) -- remove single land's cache
local map = Map.CachedQuery.RangeArea
for n,path in pairs(map.recorded_landId[landId]) do
table.setKey(map.data,path,nil)
end
map.recorded_landId[landId] = {}
end
},
CACHE_MANAGER = function()
local map = Map.CachedQuery
for strpos,Info in pairs(map.SinglePos.data) do
if Info.querying then
map.SinglePos.data[strpos].querying = false
else
map.SinglePos.clear(strpos)
end
end
for cubestr,Info in pairs(map.RangeArea.data) do
if Info.querying then
map.RangeArea.data[cubestr].querying = false
else
map.RangeArea.clear_range(cubestr)
end
end
end
}
}
I18N = {
TriedAutoFix = false,
Init = function()
local lang = cfg.plugin.language
local stat = I18N.Load(lang)
if stat ~= 0 and not I18N.TriedAutoFix then
I18N.LangPack.Install(lang)
I18N.TriedAutoFix = true
I18N.Init()
return
end
if stat == 0 then
return true
elseif stat == -1 then
ERROR('Language pack not found!')
elseif stat == -2 then
ERROR('The language pack used is not suitable for this version!')
elseif stat == -3 then
ERROR('The language pack is corrupt and cannot be parsed.')
end
return false
end,
Load = function(lang)
local path = DATA_PATH..'lang/'..lang..'.json'
if not File.exists(path) then
return -1
end
local pack = JSON.parse(File.readFrom(path))
if not pack then
return -3
elseif pack.VERSION ~= Plugin.Version.toNumber() then
return -2
else
I18N.LangPack.data = pack
end
return 0
end,
Install = function(lang)
local stat = I18N.LangPack.Install(lang)
if stat==-1 then
ERROR(_Tr('console.languages.install.fail.stat'))
elseif stat==-2 then
ERROR(_Tr('console.languages.install.fail.verify','<a>',lang))
elseif stat==-3 then
ERROR(_Tr('console.languages.install.fail.version','<a>',lang))
elseif stat==-4 then
ERROR(_Tr('console.languages.install.fail.broken','<a>',lang))
end
end,
Update = function(lang)
local path = DATA_PATH..'lang/'
local list_o = I18N.LangPack.GetRepo()
local list_l = I18N.LangPack.GetInstalled()
if File.exists(path..lang..'.json') then
if not Array.Fetch(list_l,lang) then
ERROR(_Tr('console.languages.update.notfound','<a>',lang))
end
local pack = JSON.parse(File.readFrom(path..lang..'.json'))
if not pack then
ERROR(_Tr('console.languages.update.broken','<a>',lang))
elseif pack.VERSION == Plugin.Version.toNumber() then
ERROR(lang..': '.._Tr('console.languages.update.alreadylatest'))
elseif not Array.Fetch(list_o.official,lang) and not Array.Fetch(list_o['3-rd'],lang) then
ERROR(_Tr('console.languages.update.notfoundonline','<a>',lang))
elseif I18N.LangPack.Install(lang)==0 then
INFO(_Tr('console.languages.update.succeed','<a>',lang))
return true
end
else
ERROR(_Tr('console.languages.update.notfound','<a>',lang))
end
return false
end,
LangPack = {
data = {},
Set = function(lang)
local stat = I18N.Load(lang)
if stat==0 then
cfg.plugin.language = lang
DataStorage.Save({1,0,0})
end
return stat
end,
Install = function(lang)
local lang_n = network.httpGetSync(Server.GetLink()..'/languages/'..lang..'.json')
local lang_v = network.httpGetSync(Server.GetLink()..'/languages/'..lang..'.json.md5.verify')
if lang_n.status~=200 or lang_v.status~=200 then
return -1
end
local raw = string.gsub(lang_n.data,'\n','\r\n')
if data.toMD5(raw)~=lang_v.data then
return -2
end
local pack = JSON.parse(raw)
if not pack then
return -4
elseif pack.VERSION~=Plugin.Version.toNumber() then
return -3
end
File.writeTo(DATA_PATH..'lang/'..lang..'.json',raw)
return 0
end,
GetSign = function()
local rtn = ""
local count = 1
while(I18N.LangPack.data['#'..count]) do
rtn = '\n'.._Tr('#'..count)
count = count + 1
end
return rtn
end,
GetInstalled = function()
local langs = {}
for n,filename in pairs(File.getFilesList(DATA_PATH..'lang/')) do
local tmp = string.split(filename,'.')
if tmp[2] == 'json' then
langs[#langs+1] = tmp[1]
end
end
return langs
end,
GetRepo = function()
local server = Server.GetLink()
if server ~= false then
local raw = network.httpGetSync(server..'/languages/repo.json')
if raw.status==200 then
local rtn = JSON.parse(raw.data)
if rtn then
return rtn
else
ERROR(_Tr('console.getonline.failbybroken'))
end
else
ERROR(_Tr('console.getonline.failbycode','<a>',raw.status))
end
else
WARN(_Tr('console.getonline.failed'))
end
return false
end
}
}
Dimension = {
Get = function(id)
if id == 0 then
return {
name = _Tr('talk.dim.zero'),
max = 320,
min = -64
}
elseif id == 1 then
return {
name = _Tr('talk.dim.one'),
max = 128,
min = 0
}
elseif id == 2 then
return {
name = _Tr('talk.dim.two'),
max = 256,
min = 0
}
else
return {
name = _Tr('talk.dim.other'),
max = 0,
min = 0
}
end
end
}
DataStorage = {
Config = {
Load = function()
--- Init.
local save = false
--- Check file.
if not File.exists(DATA_PATH..'config.json') then
WARN(_Tr('console.loading.config.notfound'))
File.writeTo(DATA_PATH..'config.json',JSON.stringify(cfg))
end
local localcfg = JSON.parse(File.readFrom(DATA_PATH..'config.json'))
if not localcfg then
ERROR(_Tr('console.loading.config.broken'))
return false
elseif localcfg.version ~= Plugin.Version.toNumber() then
save = true
if not DataStorage.Config.Update(localcfg) then
return false
end
end
--- Load local configure.
for n,path in pairs(table.getAllPaths(cfg,false)) do
local item = table.getKey(localcfg,path)
if path ~= 'this.version' then
if item == nil then
save = true
WARN(_Tr('console.loading.config.itemlost','<a>',string.sub(path,6)))
else
table.setKey(cfg,path,item)
end
end
end
-- Auto correct.
if cfg.land.bought.square_range[1] > cfg.land.bought.square_range[2] then
WARN(_Tr('console.loading.config.autocorrect','<a>','cfg.land.bought.square_range'))
table.sort(cfg.land.bought.square_range)
save = true
end
if cfg.economic.protocol~='llmoney' and cfg.economic.protocol~='scoreboard' then
WARN(_Tr('console.loading.config.autocorrect','<a>','cfg.economic.protocol'))
cfg.economic.protocol = 'scoreboard'
save = true
end
-- Save if needed.
if save then
DataStorage.Save({1,0,0})
end
return true
end,
Update = function(origin)
if not origin.version or origin.version < 240 then
return false
end
--- Update
if origin.version < 242 then -- OLD STRUCTURE
local tpl = table.clone(cfg)
tpl.plugin.language = origin.manager.default_language
tpl.plugin.network = origin.update_check
tpl.land.operator = origin.manager.operator
tpl.land.max_lands = origin.land.player_max_lands
tpl.land.bought.three_dimension.enable = origin.features.land_3D
tpl.land.bought.three_dimension.calculate_method = origin.land_buy.calculation_3D
tpl.land.bought.three_dimension.price = origin.land_buy.price_3D
tpl.land.bought.two_dimension.enable = origin.features.land_2D
tpl.land.bought.two_dimension.calculate_method = origin.land_buy.calculation_2D
tpl.land.bought.two_dimension.price = origin.land_buy.price_2D
tpl.land.bought.square_range = {origin.land.land_min_square,origin.land.land_max_square}
tpl.land.bought.discount = origin.money.discount/100
tpl.land.refund_rate = origin.land_buy.refund_rate
tpl.economic.protocol = origin.money.protocol
tpl.economic.scoreboard_objname = origin.money.scoreboard_objname
tpl.economic.currency_name = origin.money.credit_name
tpl.features.landsign.enable = origin.features.landSign
tpl.features.landsign.frequency = origin.features.sign_frequency
tpl.features.buttomsign.enable = origin.features.landSign
tpl.features.buttomsign.frequency = origin.features.sign_frequency
tpl.features.particles.enable = origin.features.particles
tpl.features.particles.name = origin.features.particle_effects
tpl.features.particles.max_amount = origin.features.player_max_ple
tpl.features.player_selector.include_offline_players = origin.features.offlinePlayerInList
tpl.features.selection.disable_dimension = origin.features.blockLandDims
tpl.features.selection.tool_type = origin.features.selection_tool
tpl.features.selection.tool_name = origin.features.selection_tool_name
tpl.features.landtp = origin.features.landtp
tpl.features.force_talk = origin.features.force_talk
tpl.features.disabled_listener = origin.features.disabled_listener
tpl.features.chunk_side = origin.features.chunk_side
origin = tpl
end
if origin.version < 260 then
origin.land.bought.three_dimension.calculate_method = nil
origin.land.bought.three_dimension.price = nil
origin.land.bought.two_dimension.calculate_method = nil
origin.land.bought.two_dimension.price = nil
origin.land.bought.three_dimension.calculate = "{square}*8+{height}*20"
origin.land.bought.two_dimension.calculate = "{square}*25"
end
if origin.version < 262 then
if type(origin.land.bought.square_range)~='table' then
origin.land.bought.square_range = {4,50000}
end
end
if origin.version < 270 then
local sec = origin.features.selection
sec.dimension = {true,true,true}
if Array.Fetch(sec.disable_dimension,0) then
sec.dimension[1] = false
end
if Array.Fetch(sec.disable_dimension,1) then
sec.dimension[2] = false
end
if Array.Fetch(sec.disable_dimension,2) then
sec.dimension[3] = false
end
origin.land.min_space = 15
sec.disable_dimension = nil
end
if origin.version < 280 then
local res = origin.features
res.disable_creative_warn = false
res.player_selector.items_perpage = nil
if not Array.Fetch(res.disabled_listener,'onDropItem') then
res.disabled_listener[#res.disabled_listener+1] = 'onDropItem'
end
end
--- Rtn
return true
end,
Save = function()
File.writeTo(DATA_PATH..'config.json',JSON.stringify(cfg))
end
},
Land = {
Raw = {},
Unloaded = {},
Load = function()
--- Init.
local save = false
--- Check file.
if not File.exists(DATA_PATH..'data.json') then
WARN(_Tr('console.loading.land.notfound'))
File.writeTo(DATA_PATH..'data.json',JSON.stringify({
version = Plugin.Version.toNumber(),
Lands = {}
}))
end
local localdata = JSON.parse(File.readFrom(DATA_PATH..'data.json'))
if not localdata then
ERROR(_Tr('console.loading.land.broken'))
elseif localdata.version ~= Plugin.Version.toNumber() then
if not localdata.version then
localdata = {
version = 270,
Lands = table.clone(localdata)
}
end
DataStorage.Land.Update(localdata)
save = true
end
--- Load local land.
for landId,res in pairs(localdata.Lands) do
local m = DataStorage.Land.Template.Fill(res)
if m then
DataStorage.Land.Raw[landId] = m
else
WARN(_Tr('console.loading.land.invalild','<a>',landId))
Land.RelationShip.Owner.destroy(landId)
save = true
end
end
--- Save if needed.
if save then
DataStorage.Save({0,1,0})
end
return true
end,
Update = function(origin)
for landId,res in pairs(origin.Lands) do
local land = origin.Lands[landId]
local perm = land.permissions
local setting = land.settings
local range = land.range
if origin.version < 240 then
return false
end
if origin.version < 245 then
perm.use_armor_stand = false
perm.eat = false
end
if origin.version < 260 then
setting.ev_redstone_update = false
end
if origin.version < 262 then
perm.useitem = nil
end
if origin.version < 280 then
if range.start_position[2] == -64 and range.end_position[2] == 320 then
local dim = Dimension.Get(range.dimid)
range.start_position[2] = dim.min
range.end_position[2] = dim.max
end
end
if origin.version < 281 then
land.settings.teleport = table.clone(land.range.end_position)
end
if origin.version < 283 then
setting.nickname = string.gsub(setting.nickname,'%%','%')
setting.describe = string.gsub(setting.describe,'%%','%')
end
end
return true
end,
Template = {
data = {
settings = {
share = {},
teleport = {},
nickname = '',
describe = '',
signtome = true,
signtother = true,
signbuttom = true,
ev_explode = false,
ev_farmland_decay = false,
ev_piston_push = false,
ev_fire_spread = false,
ev_redstone_update = false
},
range = {
start_position = {},
end_position = {},
dimid = -1
},
permissions = {
allow_destroy = false,
allow_entity_destroy = false,
allow_place = false,
allow_attack_player = false,
allow_attack_animal = false,
allow_attack_mobs = true,
allow_open_chest = false,
allow_pickupitem = false,
allow_dropitem = true,
allow_shoot = false,
use_anvil = false,
use_barrel = false,
use_beacon = false,
use_bed = false,
use_bell = false,