Skip to content

Instantly share code, notes, and snippets.

@airone01
Last active November 21, 2021 00:15
Show Gist options
  • Save airone01/3334c2d358f7cb0f460bcdbb1d7cd405 to your computer and use it in GitHub Desktop.
Save airone01/3334c2d358f7cb0f460bcdbb1d7cd405 to your computer and use it in GitHub Desktop.
Tests for Client:Send functions
function Initialize(Plugin)
Plugin:SetName("SendTests")
cPluginManager.BindCommand("/sendblockbreak", "permissionnode", CmdBlockBreak, " - Show a block break packet to the block below you")
cPluginManager.BindCommand("/sendcollect", "permissionnode", CmdCollectEntity, " - Send a collect packet for items near you")
cPluginManager.BindCommand("/senddestroy", "permissionnode", CmdDestroyEntity, " - Send a destroy packet for (non-players) entities near you")
cPluginManager.BindCommand("/senddestroyplayer", "permissionnode", CmdDestroyEntityPlayer, " - Send a destroy packet for your entity")
cPluginManager.BindCommand("/senddetach", "permissionnode", CmdDetachEntity, " - Send a detach packet for your player")
cPluginManager.BindCommand("/sendeditsign", "permissionnode", CmdEditSign, " - Send a sign edit packet")
cPluginManager.BindCommand("/sendleashentity", "permissionnode", CmdLeashEntity, " - Send leash packets for entities near you")
cPluginManager.BindCommand("/sendresourcepack", "permissionnode", CmdResourcePack, " - Send a resource pack URL packet")
cPluginManager.BindCommand("/sendunleashentity", "permissionnode", CmdUnleashEntity, " - Send a unleash packet for entities near you")
cPluginManager.BindCommand("/sendthunderbolt", "permissionnode", CmdThunderbolt, " - Send a thunderbolt on you")
LOG("Initialised " .. Plugin:GetName() .. " v." .. Plugin:GetVersion())
return true
end
math.randomseed(os.time()) -- reset randomness
-- SendBlockBreakAnim
-- changes the breaking state of the block below you
-- works
function CmdBlockBreak(Split, Player)
TestStart(Player, "SendBlockBreakAnim")
Client = Player:GetClientHandle()
Client:SendBlockBreakAnim(math.floor(math.random()*10^8), Player:GetPosX(), Player:GetPosY()-1, Player:GetPosZ()-1, math.floor(math.random()*9))
TestEnd(Player)
return true
end
-- SendCollectEntity
-- collects items 2 blocks around you
-- works
function CmdCollectEntity(Split, Player)
TestStart(Player, "SendCollectEntity")
BoxExecute(Player, function(Client, Entity)
if (Entity:IsPickup()) then
Client:SendCollectEntity(Entity, Player, 1)
end
end)
TestEnd(Player)
return true
end
-- SendDestroyEntity
-- removes entities 2 blocks around you
-- works
function CmdDestroyEntity(Split, Player)
TestStart(Player, "SendDestroyEntity")
BoxExecute(Player, function(Client, Entity)
if (not Entity:IsPlayer()) then
Client:SendDestroyEntity(Entity)
end
end)
TestEnd(Player)
return true
end
-- SendDestroyEntity (2nd test)
-- removes player entity
-- doesn't work
function CmdDestroyEntityPlayer(Split, Player)
TestStart(Player, "SendDestroyEntity")
Client = Player:GetClientHandle()
Client:SendDestroyEntity(Player)
TestEnd(Player)
return true
end
-- SendDetachEntity
-- detaches player from rided entity
-- works
function CmdDetachEntity(Split, Player)
TestStart(Player, "SendDetachEntity")
BoxExecute(Player, function(Client, Entity)
if (not Entity:IsPlayer()) then
Client:SendDetachEntity(Player, Entity)
end
end)
TestEnd(Player)
return true
end
-- SendEditSign
-- edits an invisible sign
-- works
function CmdEditSign(Split, Player)
TestStart(Player, "SendEditSign")
Client = Player:GetClientHandle()
Client:SendEditSign(Player:GetPosX(), Player:GetPosY(), Player:GetPosZ())
TestEnd(Player)
return true
end
-- SendLeashEntity
-- leashes all mobs to you
-- works
function CmdLeashEntity(Split, Player)
TestStart(Player, "SendLeashEntity")
Client = Player:GetClientHandle()
Player:GetWorld():ForEachEntity(function(Entity)
if (Entity:IsMob()) then
Client:SendLeashEntity(Entity, Player)
end
end)
TestEnd(Player)
return true
end
-- SendResourcePack
-- loads the dumb "Leviosa" ressource pack (https://www.curseforge.com/minecraft/texture-packs/leviosa)
-- works
function CmdResourcePack(Split, Player)
TestStart(Player, "SendResourcePack")
Client = Player:GetClientHandle()
Client:SendResourcePack("https://media.forgecdn.net/files/2931/151/Leviosa.zip")
TestEnd(Player)
return true
end
-- SendThunderbolt
-- spawns a thunderbolt on you. it will be silent and might spawn behind you.
-- works
function CmdThunderbolt(Split, Player)
TestStart(Player, "SendThunderbolt")
Client = Player:GetClientHandle()
Client:SendThunderbolt(Player:GetPosX(), Player:GetPosY(), Player:GetPosZ())
TestEnd(Player)
return true
end
-- SendUnleashEntity
-- unleashes entities
-- works
function CmdUnleashEntity(Split, Player)
TestStart(Player, "SendUnleashEntity")
BoxExecute(Player, function(Client, Entity)
if (not Entity:IsPlayer()) then
Client:SendUnleashEntity(Entity)
end
end)
TestEnd(Player)
return true
end
function TestStart(Player, PacketName)
Player:SendMessage("§e[SendTests]§r testing §o" ..PacketName.. "§r...")
end
function TestEnd(Player)
Player:SendMessage("§e[SendTests]§r testing successful")
end
function BoxExecute(Player, Callback)
Client = Player:GetClientHandle()
X = math.floor(Player:GetPosX())
Y = math.floor(Player:GetPosY())
Z = math.ceil(Player:GetPosZ())
Box = cBoundingBox(Vector3d(X-3, Y-3, Z-3), Vector3d(X+3, Y+3, Z+3))
Player:GetWorld():ForEachEntityInBox(Box, function(Entity) Callback(Client, Entity) end)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment