-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkilly.lua
134 lines (111 loc) · 3.98 KB
/
killy.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
----------------------------------------
-- GLOBALS
----------------------------------------
-- queue containing the updates that need to be applied to the minecraft world
UpdateQueue = nil
-- array of container objects
Containers = {}
--
SignsToUpdate = {}
-- as a lua array cannot contain nil values, we store references to this object
-- in the "Containers" array to indicate that there is no container at an index
EmptyContainerSpace = {}
localPlayer = nil
----------------------------------------
-- FUNCTIONS
----------------------------------------
-- Tick is triggered by cPluginManager.HOOK_TICK
function Tick(TimeDelta)
UpdateQueue:update(MAX_BLOCK_UPDATE_PER_TICK)
end
-- Plugin initialization
function Initialize(Plugin)
Plugin:SetName("Killy")
Plugin:SetVersion(1)
UpdateQueue = NewUpdateQueue()
-- Hooks
cPluginManager:AddHook(cPluginManager.HOOK_PLAYER_JOINED, PlayerJoined);
cPluginManager:AddHook(cPluginManager.HOOK_PLAYER_USING_BLOCK, PlayerUsingBlock);
cPluginManager:AddHook(cPluginManager.HOOK_PLAYER_FOOD_LEVEL_CHANGE, OnPlayerFoodLevelChange);
cPluginManager:AddHook(cPluginManager.HOOK_TAKE_DAMAGE, OnTakeDamage);
cPluginManager:AddHook(cPluginManager.HOOK_WEATHER_CHANGING, OnWeatherChanging);
cPluginManager:AddHook(cPluginManager.HOOK_SERVER_PING, OnServerPing);
cPluginManager:AddHook(cPluginManager.HOOK_TICK, Tick);
-- Command Bindings
-- TODO
cPluginManager.BindCommand("/killy", "*", KillyCommand, " - docker CLI commands")
-- make all players admin
cRankManager:SetDefaultRank("Admin")
cNetwork:Connect("127.0.0.1",25566,TCP_CLIENT)
LOG("Initialised " .. Plugin:GetName() .. " v." .. Plugin:GetVersion())
return true
end
-- getStartStopLeverContainer returns the container
-- id that corresponds to lever at x,y coordinates
function getStartStopLeverContainer(x, z)
for i=1, table.getn(Containers)
do
if Containers[i] ~= EmptyContainerSpace and x == Containers[i].x + 1 and z == Containers[i].z + 1
then
return Containers[i].id
end
end
return ""
end
-- getRemoveButtonContainer returns the container
-- id and state for the button at x,y coordinates
function getRemoveButtonContainer(x, z)
for i=1, table.getn(Containers)
do
if Containers[i] ~= EmptyContainerSpace and x == Containers[i].x + 2 and z == Containers[i].z + 3
then
return Containers[i].id, Containers[i].running
end
end
return "", true
end
--
function PlayerJoined(Player)
-- enable flying
Player:SetCanFly(true)
LOG("player joined")
localPlayer = Player
-- updateTableRecordContainer(1,"?", "??")
-- updateTableRecordContainer(2,"!", "!!")
-- updateActiveInstanceContainer(1,"??",true)
-- updateActiveInstanceContainer(2,"!!",true)
end
--
function PlayerUsingBlock(Player, BlockX, BlockY, BlockZ, BlockFace, CursorX, CursorY, CursorZ, BlockType, BlockMeta)
LOG("Using block: " .. tostring(BlockX) .. "," .. tostring(BlockY) .. "," .. tostring(BlockZ) .. " - " .. tostring(BlockType) .. " - " .. tostring(BlockMeta))
end
function OnPlayerFoodLevelChange(Player, NewFoodLevel)
-- Don't allow the player to get hungry
return true, Player, NewFoodLevel
end
function OnTakeDamage(Receiver, TDI)
-- Don't allow the player to take falling or explosion damage
if Receiver:GetClass() == 'cPlayer'
then
if TDI.DamageType == dtFall or TDI.DamageType == dtExplosion then
return true, Receiver, TDI
end
end
return false, Receiver, TDI
end
function OnServerPing(ClientHandle, ServerDescription, OnlinePlayers, MaxPlayers, Favicon)
-- Change Server Description
local serverDescription = "A Docker client for Minecraft"
-- Change favicon
if cFile:IsFile("/srv/logo.png") then
local FaviconData = cFile:ReadWholeFile("/srv/logo.png")
if (FaviconData ~= "") and (FaviconData ~= nil) then
Favicon = Base64Encode(FaviconData)
end
end
return false, serverDescription, OnlinePlayers, MaxPlayers, Favicon
end
-- Make it sunny all the time!
function OnWeatherChanging(World, Weather)
return true, wSunny
end