From 56f8dedb6b0c8922257055d22c6166e85f5e066f Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sat, 26 Nov 2016 19:24:24 +0100 Subject: [PATCH] Debuggers: Added commands to investigate item's custom name. --- Server/Plugins/Debuggers/Debuggers.lua | 47 ++++++++++++++++++++++++++ Server/Plugins/Debuggers/Info.lua | 14 +++++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/Server/Plugins/Debuggers/Debuggers.lua b/Server/Plugins/Debuggers/Debuggers.lua index 27440027e..914da8036 100644 --- a/Server/Plugins/Debuggers/Debuggers.lua +++ b/Server/Plugins/Debuggers/Debuggers.lua @@ -987,6 +987,28 @@ end; +function HandleGetCustomNameCmd(a_Split, a_Player) + local item = a_Player:GetInventory():GetEquippedItem() + if (not(item.m_CustomName) or (item.m_CustomName == "")) then + a_Player:SendMessage("The custom name is empty") + return true + end + local dispCN = string.gsub(item.m_CustomName, ".", + function(a_Char) + if (a_Char < " ") then + return string.byte(a_Char) + end + return a_Char + end + ) + a_Player:SendMessage(string.format("The custom name is %d bytes: %s", string.len(item.m_CustomName), dispCN)) + return true +end + + + + + function HandleGetLoreCmd(a_Split, a_Player) local item = a_Player:GetInventory():GetEquippedItem() if (not(item.m_Lore) or (item.m_Lore == "")) then @@ -1062,6 +1084,31 @@ end +function HandleSetCustomNameCmd(a_Split, a_Player, a_EntireCmd) + if not(a_Split[2]) then + a_Player:SendMessageFatal("Missing an argument: the custom name to set"); + return true + end + local nameToSet = a_EntireCmd:match("/setcustomname%s(.*)") + if not(nameToSet) then + a_Player:SendMessageFatal("Failed to extract the custom name to set") + return true + end + nameToSet = nameToSet:gsub("\\([0-9][0-9][0-9])", string.char) + + local inv = a_Player:GetInventory() + local slotNum = inv:GetEquippedSlotNum() + local item = cItem(inv:GetEquippedItem()) -- Make a copy of the item + item.m_CustomName = nameToSet + inv:SetHotbarSlot(slotNum, item) + a_Player:SendMessage("Custom name set to " .. nameToSet) + return true +end + + + + + function HandleSetLoreCmd(a_Split, a_Player, a_EntireCmd) if not(a_Split[2]) then a_Player:SendMessageFatal("Missing an argument: the lore to set"); diff --git a/Server/Plugins/Debuggers/Info.lua b/Server/Plugins/Debuggers/Info.lua index 06fabad14..dcdcdd17f 100644 --- a/Server/Plugins/Debuggers/Info.lua +++ b/Server/Plugins/Debuggers/Info.lua @@ -100,11 +100,17 @@ g_PluginInfo = Handler = HandleGCCmd, HelpString = "Activates the Lua garbage collector" }, + ["/getcustomname"] = + { + Permission = "debuggers", + Handler = HandleGetCustomNameCmd, + HelpString = "Displays the exact custom name of currently held item (including non-printables)", + }, ["/getlore"] = { Permission = "debuggers", Handler = HandleGetLoreCmd, - HelpString = "Displays the Lore of currently held item", + HelpString = "Displays the exact Lore of currently held item (including non-printables)", }, ["/hunger"] = { @@ -172,6 +178,12 @@ g_PluginInfo = Handler = HandleSched, HelpString = "Schedules a simple countdown using cWorld:ScheduleTask()" }, + ["/setcustomname"] = + { + Permission = "debuggers", + Handler = HandleSetCustomNameCmd, + HelpString = "Sets the custom name for the item currently in hand", + }, ["/setlore"] = { Permission = "debuggers",