Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local stringhelperLib = require("stringhelper")
- local exceptionsFile = "stripminingexceptions.txt"
- local exceptions = {}
- local args = { ... }
- --Write the exception file
- local function serialize()
- local string = textutils.serialiseJSON(exceptions)
- local file = fs.open(exceptionsFile, "w")
- file.write(string)
- file.close()
- end
- --Read the exceptions file and load
- local function unserialize()
- local file = fs.open(exceptionsFile, "r")
- local json = file.readAll()
- exceptions = textutils.unserialiseJSON(json)
- file.close()
- end
- --Append a new string to the exception table
- local function appendToTable(table, string)
- table[#table + 1] = string
- end
- --Write user help
- local function writeHelp()
- term.setTextColor(colors.white)
- print("To modify the list of exceptions use:")
- term.write("StripMiningExceptions ")
- term.setTextColor(colors.orange)
- term.write("add ")
- term.setTextColor(colors.lightBlue)
- print("block_id1 block_id2 ...")
- term.setTextColor(colors.white)
- term.write("StripMiningExceptions ")
- term.setTextColor(colors.orange)
- term.write("remove ")
- term.setTextColor(colors.lightBlue)
- print("block_id1 block_id2 ...")
- end
- local file = fs.open(exceptionsFile, "r")
- if not file or stringhelper.isBlank(file.readAll()) then --Created the file if it doesn't exists or its empty
- local file = fs.open(exceptionsFile, "w")
- file.write("{}")
- file.close()
- end
- unserialize()
- local command = args[1]
- if command == "add" then
- for i = 2, #args do
- local string = args[i]
- if not stringhelper.isInTable(string, exceptions) then
- appendToTable(exceptions, string)
- term.setTextColor(colors.lightBlue)
- textutils.pagedPrint("Added " .. string)
- else
- term.setTextColor(colors.orange)
- textutils.pagedPrint(string .. " already present")
- end
- end
- serialize()
- elseif command == "remove" then
- local removedStrings = {} --Hold string to be removed
- for i = 2, #args do --Get the string to remove
- local string = args[i]
- if stringhelper.isInTable(string, exceptions) then
- appendToTable(removedStrings, string)
- term.setTextColor(colors.lightBlue)
- textutils.pagedPrint("Removed " .. string)
- else
- term.setTextColor(colors.orange)
- textutils.pagedPrint(string .. " is not present")
- end
- end
- local newExceptions = {}
- for _, string in ipairs(exceptions) do --Make a new table without removed strings
- if not stringhelper.isInTable(string, removedStrings) then
- appendToTable(newExceptions, string)
- end
- end
- exceptions = newExceptions
- serialize()
- elseif command == "help" then
- writeHelp()
- else
- term.setTextColor(colors.red)
- print("Invalid command.")
- writeHelp()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement