-
Notifications
You must be signed in to change notification settings - Fork 11
/
hooks.lua
164 lines (151 loc) · 6 KB
/
hooks.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
function OnTakeDamage(Receiver, TDI)
--Avoid fall damage if player is flying
if Receiver:IsPlayer() and Receiver:CanFly() and TDI.DamageType == dtFalling then
return true
end
end
function OnPlayerRightClick(Player, BlockX, BlockY, BlockZ, BlockFace, CursorX, CursorY, CursorZ)
local World = Player:GetWorld()
if not Player:GetEquippedItem():IsCustomNameEmpty() then
cRoot:Get():GetPluginManager():ExecuteCommand(Player, Player:GetEquippedItem().m_CustomName)
end
local Read, Line1, Line2, Line3, Line4 = World:GetSignLines(BlockX, BlockY, BlockZ)
--If the sign is written like it should, teleport the player
if Line1 == "[SignWarp]" or Line1 == "[Warp]" then
cPluginManager:Get():ExecuteCommand(Player, "/warp " .. Line2)
return true
--If the sign is written like it should, enchant the item
elseif Line1 == "[Enchant]" and Line2 ~= "" and Line3 ~= "" and Line4 ~= "" then
local HeldItem = Player:GetEquippedItem()
HeldItemType = HeldItem.m_ItemType
local ItemEnchant = HeldItem.m_Enchantments
local Enchantment = cEnchantments:StringToEnchantmentID(Line2)
local CurrentItemLevel = HeldItem.m_Enchantments:GetLevel(Enchantment)
local NextLevel = CurrentItemLevel + 1
local toremove = tonumber(Line4) * NextLevel
if IsEnchantable() then
ItemEnchant:SetLevel(Enchantment, NextLevel)
Player:GetInventory():SetHotbarSlot(Player:GetInventory():GetEquippedSlotNum(), HeldItem)
Player:DeltaExperience(-toremove * 17)
Player:SendMessageSuccess("Successfully enchanted item")
else
Player:SendMessageWarning("This item is not enchantable")
end
return true
--If the sign is written like it should, execute the command
elseif Line1 == "[Command]" then
cPluginManager:Get():ExecuteCommand(Player, Line2 .. Line3 .. Line4)
return true
end
end
function OnUpdatingSign(World, BlockX, BlockY, BlockZ, Line1, Line2, Line3, Line4, Player)
--Avoid creating of warp signs by non-allowed users
if Line1 == "[SignWarp]" or Line1 == "[Warp]" then
if not Player:HasPermission("es.warpsign") then
Player:SendMessageFailure("You do not have permission to create a warp sign")
return true
elseif Line2 == "" then
Player:SendMessageFailure("You must specify a warp name")
return true
end
elseif Line1 == "[Portal]" then
if not Player:HasPermission("es.createportal") then
Player:SendMessageFailure("You do not have permission to create a portal sign")
return true
elseif Line2 == "" then
Player:SendMessageFailure("You must specify a warp name")
return true
end
elseif Line1 == "[Enchant]" then
if not Player:HasPermission("es.enchantsign") then
Player:SendMessageFailure("You do not have permission to create an enchant sign")
return true
end
elseif Line1 == "[Command]" then
if not Player:HasPermission("es.commandsign") then
Player:SendMessageFailure("You do not have permission to create a command sign")
return true
elseif Line2 == "" then
Player:SendMessageFailure("You must specify a command to execute")
return true
end
end
end
function OnPlayerBreakingBlock(Player, BlockX, BlockY, BlockZ, BlockFace, BlockType, BlockMeta)
if Jailed[Player:GetUUID()] and not IsDiggingEnabled then
Player:SendMessageInfo("You are not allowed to build while jailed")
return true
end
end
function OnPlayerPlacingBlock(Player, BlockX, BlockY, BlockZ, BlockFace, CursorX, CursorY, CursorZ, BlockType)
if Jailed[Player:GetUUID()] and not IsPlaceEnabled then
Player:SendMessageInfo("You are not allowed to build while jailed")
return true
end
end
function OnExecuteCommand(Player, CommandSplit)
if Player and Jailed[Player:GetUUID()] and not AreCommandsEnabled then
Player:SendMessageInfo("You are not allowed to use commands while jailed")
return true
end
local DisplayCommand = function(OtherPlayer)
if SocialSpyList[OtherPlayer:GetUUID()] ~= nil then
OtherPlayer:SendMessage(cChatColor.Gray .. "[" .. cChatColor.LightGray .. Player:GetName() .. cChatColor.Gray .. "] " .. cChatColor.White .. table.concat(CommandSplit , " " , 1))
end
end
if CommandSplit[1] == "/msg" and CommandSplit[2] ~= nil and CommandSplit[3] ~= nil or CommandSplit[1] == "/r" and CommandSplit[2] ~= nil or CommandSplit[1] == "/tell" and CommandSplit[2] ~= nil and CommandSplit[3] ~= nil then
cRoot:Get():ForEachPlayer(DisplayCommand)
end
end
function OnChat(Player, Message)
if Muted[Player:GetUUID()] then
Player:SendMessageInfo("You are muted")
return true
elseif Jailed[Player:GetUUID()] and not IsChatEnabled then
Player:SendMessageInfo("You are not allowed to chat while jailed")
return true
end
end
function OnWorldTick(World, TimeDelta)
--Check each 20 ticks if there's a sign above the player, if there is, teleport
if PortalTimer[World:GetName()] == nil then
PortalTimer[World:GetName()] = 0
elseif PortalTimer[World:GetName()] == 20 then
local CheckPortal = function(Player)
local CheckPortalPos = Player:GetPosY() - 2
local Read, Line1, Line2, Line3, Line4 = World:GetSignLines(Player:GetPosX(), CheckPortalPos, Player:GetPosZ())
if Line1 == "[Portal]" then
if Line4 ~= "" then
Player:TeleportToCoords(Line2, Line3, Line4)
else
cPluginManager:Get():ExecuteCommand(Player, "/warp " .. Line2)
end
end
end
World:ForEachPlayer(CheckPortal)
PortalTimer[World:GetName()] = 0
else
PortalTimer[World:GetName()] = PortalTimer[World:GetName()] + 1
end
end
function OnEntityChangingWorld(Entity, World)
if Entity:IsPlayer() then
BackWorld[Entity:GetName()] = Entity:GetWorld()
BackCoords[Entity:GetName()] = Vector3d(Entity:GetPosX(), Entity:GetPosY(), Entity:GetPosZ())
end
end
function OnEntityTeleport(Entity, OldPosition, NewPosition)
if Entity:IsPlayer() then
BackWorld[Entity:GetName()] = Entity:GetWorld()
BackCoords[Entity:GetName()] = Vector3d(OldPosition)
end
end
function OnKilled(Victim, TDI, DeathMessage)
if Victim:IsPlayer() then
BackWorld[Victim:GetName()] = Victim:GetWorld()
BackCoords[Victim:GetName()] = Vector3d(Victim:GetPosX(), Victim:GetPosY(), Victim:GetPosZ())
end
end
function OnPlayerJoined(Player)
CheckPlayer(Player)
end