/
__nbt_inspector.rb
76 lines (63 loc) · 2.61 KB
/
__nbt_inspector.rb
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
# ========
# = NOTE =
# ========
# This plugin is designed for Minecraft < 1.13 and will no longer be updated
# since the game provides a dedicated command `/locate' which does a better job.
# ========
module Mcl
Mcl.reloadable(:HMclNBTInspector)
## Inspector for server side NBT files
# !stronghold [-w --world WORLD]
class HMclNBTInspector < Handler
NBT_STRONGHOLDS = "data/Stronghold.dat"
def setup
register_stronghold(:admin)
end
def register_stronghold acl_level
register_command [:stronghold, :strongholds], desc: "examines strongholds.dat and shows you coordinates of portal rooms", acl: acl_level do |player, args|
world = $mcl.server.world
opt = OptionParser.new
opt.on("-w", "--world WORLD", String) {|v| world = v }
opt.parse!(args)
# check file
if !File.exist?(nbt_path(NBT_STRONGHOLDS, world))
tellm(player, {text: "couldn't find ", color: "red"}, {text: NBT_STRONGHOLDS, color: "aqua"}, {text: " for world ", color: "red"}, {text: world, color: "aqua"}, {text: "!", color: "red"})
throw :handler_exit
end
nbt = nbt_load(NBT_STRONGHOLDS, world)
data = nbt[1]["data"]["Features"]
data.each_with_index do |(chunk_coord, sh), i|
prc = sh["Children"].detect{|c| c["id"] == "SHPR" }
x1, y1, z1, x2, y2, z2 = prc["BB"]
xd, yd, zd = x2 - x1, y2 - y1, z2 - z1
yc = y1 + yd -3
case prc["O"]
when 0 then xc, zc, yr, xr = x1 + xd / 2, z1 - 1 + zd / 2, 0, 0 # north
when 1 then xc, zc, yr, xr = x1 + 2 + xd / 2, z1 + zd / 2, 90, 0 # east
when 2 then xc, zc, yr, xr = x1 + xd / 2, z1 + 2 + zd / 2, 180, 0 # south
when 3 then xc, zc, yr, xr = x1 - 1 + xd / 2, z1 + zd / 2, -90, 0 # west
end
tellm(player,
{text: "found stronghold ", color: "yellow"},
{text: "##{i+1}", color: "light_purple"},
{text: " #{chunk_coord}", color: "gray"},
{text: " => ", color: "yellow"},
{text: "#{xc} #{yc} #{zc}", color: "aqua", hoverEvent: {action: "show_text", value: {text: "click to teleport to portal room"}}, clickEvent: {action: "run_command", value: "!tp #{xc} #{yc} #{zc} #{yr} #{xr}"}}
)
end
end
end
module Helper
def tellm p, *msg
trawm(p, title("NBT"), *msg)
end
def nbt_path file, world = nil
"#{$mcl.server.world_root(world)}/#{file}"
end
def nbt_load file, world = nil
NBTFile.load(File.read(nbt_path(file, world)))
end
end
include Helper
end
end