Skip to content

Commit 6b7d1f0

Browse files
committed
Use exceptions for try/catch compatibility, fixes #39
Wire workshop was updated so here this is.
1 parent d79686b commit 6b7d1f0

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

lua/entities/gmod_wire_expression2/core/custom/webaudio.lua

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,19 @@ end
8989
-- @param table self 'self' from E2Functions.
9090
-- @param Entity? ent Optional entity to check if they have permissions to modify.
9191
local function checkPermissions(self, ent)
92-
if not Enabled:GetBool() then error("WebAudio is currently disabled on the server!") end
92+
if not Enabled:GetBool() then E2Lib.raiseException("WebAudio is currently disabled on the server!", nil, self.trace) end
9393
local ply = self.player
9494

9595
local required_lv = AdminOnly:GetInt()
9696
if required_lv == 1 then
97-
if not ply:IsAdmin() then error("WebAudio is currently restricted to admins!") end
97+
if not ply:IsAdmin() then E2Lib.raiseException("WebAudio is currently restricted to admins!", nil, self.trace) end
9898
elseif required_lv == 2 then
99-
if not ply:IsSuperAdmin() then error("WebAudio is currently restricted to super-admins!") end
99+
if not ply:IsSuperAdmin() then E2Lib.raiseException("WebAudio is currently restricted to super-admins!", nil, self.trace) end
100100
end
101101

102102
if ent then
103103
-- Checking if you have perms to modify this prop.
104-
if not E2Lib.isOwner(self, ent) then error("You do not have permissions to modify this prop!") end
104+
if not E2Lib.isOwner(self, ent) then E2Lib.raiseException("You do not have permissions to modify this prop!", nil, self.trace) end
105105
end
106106
end
107107

@@ -195,20 +195,20 @@ e2function webaudio webAudio(string url)
195195

196196
if not WebAudio.isWhitelistedURL(url) then
197197
if WebAudio.Common.CustomWhitelist then
198-
error("This URL is not whitelisted! The server has a custom whitelist.")
198+
E2Lib.raiseException("This URL is not whitelisted! The server has a custom whitelist.", nil, self.trace)
199199
else
200-
error("This URL is not whitelisted! See github.com/Vurv78/WebAudio/blob/main/WHITELIST.md")
200+
E2Lib.raiseException("This URL is not whitelisted! See github.com/Vurv78/WebAudio/blob/main/WHITELIST.md", nil, self.trace)
201201
end
202202
end
203203

204204
-- Creation Time Quota
205205
if not CreationBurst:use(ply) then
206-
error("You are creating WebAudios too fast. Check webAudioCanCreate before calling!")
206+
E2Lib.raiseException("You are creating WebAudios too fast. Check webAudioCanCreate before calling!", nil, self.trace)
207207
end
208208

209209
-- Stream Count Quota
210210
if not checkCounter(ply, true) then
211-
error("Reached maximum amount of WebAudio streams! Check webAudioCanCreate or webAudiosLeft before calling!")
211+
E2Lib.raiseException("Reached maximum amount of WebAudio streams! Check webAudioCanCreate or webAudiosLeft before calling!", nil, self.trace)
212212
end
213213

214214
return registerStream(self, url, ply)
@@ -248,6 +248,10 @@ e2function number webAudiosLeft()
248248
return MaxStreams:GetInt() - (StreamCounter[self.player] or 0)
249249
end
250250

251+
e2function number webAudioCanTransmit()
252+
return NetBurst:check(self.player) and 1 or 0
253+
end
254+
251255
__e2setcost(4)
252256
e2function number webaudio:isValid()
253257
return IsValid(this) and 1 or 0
@@ -267,14 +271,14 @@ end
267271
__e2setcost(15)
268272
e2function number webaudio:play()
269273
checkPermissions(self)
270-
if not NetBurst:use(self.player) then return 0 end
274+
if not NetBurst:use(self.player) then return self:throw("You are transmitting too fast, check webAudioCanTransmit!", 0) end
271275

272276
return this:Play() and 1 or 0
273277
end
274278

275279
e2function number webaudio:pause()
276280
checkPermissions(self)
277-
if not NetBurst:use(self.player) then return 0 end
281+
if not NetBurst:use(self.player) then return self:throw("You are transmitting too fast, check webAudioCanTransmit!", 0) end
278282

279283
return this:Pause() and 1 or 0
280284
end
@@ -324,14 +328,16 @@ end
324328
-- @return number Whether the WebAudio object successfully transmitted. Returns 0 if you are hitting quota.
325329
e2function number webaudio:update()
326330
checkPermissions(self)
327-
if not NetBurst:use(self.player) then return 0 end
331+
if not NetBurst:use(self.player) then return self:throw("You are transmitting too fast, check webAudioCanTransmit!", 0) end
328332

329333
return this:Transmit() and 1 or 0
330334
end
331335

332336
__e2setcost(5)
333337
e2function number webaudio:setParent(entity parent)
338+
if not IsValid(parent) then return self:throw("Parent is invalid!", 0) end
334339
checkPermissions(self, parent)
340+
335341
this:SetParent(parent)
336342
return 1
337343
end

0 commit comments

Comments
 (0)