-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsudo.lua
More file actions
134 lines (122 loc) · 4.31 KB
/
sudo.lua
File metadata and controls
134 lines (122 loc) · 4.31 KB
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
-- sudo.lua
-- Implements the /sudo command.
function GetPlayerLookPos(Player)
local World = Player:GetWorld()
local Start = Player:GetEyePosition()
local End = Start + Player:GetLookVector() * 150
local HitCoords = nil
local Callbacks =
{
OnNextBlock = function(BlockPos, BlockType)
if BlockType ~= E_BLOCK_AIR then
HitCoords = BlockPos
return true
end
end
}
cLineBlockTracer:Trace(World, Callbacks, Start, End)
return HitCoords
end
function HandleSudoCommand(Split, Player)
if #Split < 3 then
SendMessage(Player, "Usage: " .. Split[1] .. " <player> <command [...]>")
return true
end
-- Get the command and arguments.
local newSplit = table.concat(Split, " ", 3)
local FoundPlayerCallback = function(a_Player)
local pluginManager = cRoot:Get():GetPluginManager()
if (pluginManager:ExecuteCommand(a_Player, newSplit)) then
SendMessageSuccess(Player, "Executed that command as the player " .. Split[2] .. ".")
else
SendMessageFailure(Player, "Could not execute that command, are permissions set?")
end
return true
end
if not cRoot:Get():FindAndDoWithPlayer(Split[2], FoundPlayerCallback) then
SendMessageFailure(Player, "Could not find that player (" .. Split[2] .. "), are they online?")
return true
end
return true
end
function HandleConsoleSudo(Split, Player)
if #Split < 3 then
return true, "Usage: " .. Split[1] .. " <player> <command [...]>"
end
-- Get the command and arguments.
local newSplit = table.concat(Split, " ", 3)
local FoundPlayerCallback = function(a_Player)
local pluginManager = cRoot:Get():GetPluginManager()
if (pluginManager:ExecuteCommand(a_Player, newSplit)) then
return true, "Executed that command as the player " .. Split[2] .. "."
else
return true, "Could not execute that command, are permissions set?"
end
end
if not cRoot:Get():FindAndDoWithPlayer(Split[2], FoundPlayerCallback) then
return true, "Could not find that player, are they online?"
end
end
function HandleExecuteCommand(Split, Player)
if Split[2] == nil then
local LookPos = GetPlayerLookPos(Player)
local LookingAtCommandBlock = Player:GetWorld():DoWithBlockEntityAt(
LookPos.x, LookPos.y, LookPos.z,
function (CommandBlock)
local ExecuteCommandBlock = tolua.cast(CommandBlock, "cCommandBlockEntity")
ExecuteCommandBlock:Activate()
end
)
if LookingAtCommandBlock then
Player:SendMessageSuccess("Executed a cmdblock in your direction.")
else
Player:SendMessageFailure("Could not find a cmdblock in your direction.")
end
elseif Split[2] ~= nil and Split[3] ~= nil and Split[4] ~= nil then
if tonumber(Split[2]) == nil or tonumber(Split[3]) == nil or tonumber(Split[4]) == nil then
Player:SendMessageFailure("Could not use a non-numeric coordinate.")
return true
else
local IsCommandBlock = Player:GetWorld():DoWithBlockEntityAt(
Split[2], Split[3], Split[4],
function (CommandBlock)
local ExecuteCommandBlock = tolua.cast(CommandBlock, "cCommandBlockEntity")
ExecuteCommandBlock:Activate()
end
)
if IsCommandBlock then
Player:SendMessageSuccess("Executed a cmdblock at X: " ..Split[2].. ", Y: " ..Split[3].. ", Z: " ..Split[4].. ".")
else
Player:SendMessageFailure("Could not find a cmdblock in your direction.")
end
return true
end
else
Player:SendMessage(cChatColor.LightGray .. "Usage: " ..Split[1].. " [<x> <y> <z>]")
end
return true
end
function HandleConsoleExecute(Split, Player)
if Split[2] ~= nil and Split[3] ~= nil and Split[4] ~= nil and Split[5] ~= nil then
if tonumber(Split[2]) == nil or tonumber(Split[3]) == nil or tonumber(Split[4]) == nil then
return true, "Could not use a non-numeric coordinate."
end
if cRoot:Get():GetWorld(Split[5]) == nil then
return true, "Could not find that world, did you use Caps?"
end
local IsCommandBlock = cRoot:Get():GetWorld(Split[5]):DoWithBlockEntityAt(
Split[2], Split[3], Split[4],
function (CommandBlock)
local ExecuteCommandBlock = tolua.cast(CommandBlock, "cCommandBlockEntity")
ExecuteCommandBlock:Activate()
end
)
if IsCommandBlock == true then
return true, "Executed a cmdblock in that world at X: " .. Split[2] .. ", Y: " .. Split[3] .. ", Z: " .. Split[4] .. "."
else
return true, "Could not find a cmdblock at that location."
end
else
return true, "Usage: " .. Split[1] .. " <x> <y> <z> <world>"
end
end