Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local key="lipAPI.public_key"
- -- http://pastebin.com/VStLRx0P
- -- Server Patched Version of LIP
- -- reduce results of WorldInterface.getBlockInfos() and EntityDetector.getEntityList()
- -- add methods WorldInterface.getBlockDatatags() and EntityDetector.getEntityListAdvanced()
- local modLIP_ServerPatchedVersion = true
- local timeout = 5
- local channel = 5480
- local id = os.getComputerID()
- --Set global to local
- local _max = math.max
- local _format = string.format
- local _find = peripheral.find
- local _startTimer,_cancelTimer = os.startTimer,os.cancelTimer
- local _pullEvent = os.pullEvent
- function setTimeout(n)
- if not tonumber(n) or n<=0 then
- error("LIP:Timeout should be a positive number",2)
- exit()
- end
- timeout = _max(.1,tonumber(n))
- end
- local function request(_p)
- local modem = _find("modem", function(name, object) return object.isWireless() end)
- if not modem then
- error("LIP:Not found: wireless modem",2)
- exit()
- end
- local data = {key,_p}
- local keepOpen = modem.isOpen(id)
- if not keepOpen then modem.open(id) end
- local _timeout = _startTimer(timeout)
- modem.transmit(channel,id,data)
- while true do
- local e, p, to, from, result, dist = _pullEvent()
- if e=="modem_message" and to==id and from==channel then
- _cancelTimer(_timeout)
- if not keepOpen then modem.close(id) end
- if result[1] then
- return result[2]
- else
- error("LIP_Server:"..result[2],2)
- exit()
- end
- elseif e=="timer" then
- error("LIP_Server:code_408 Request Timeout",2)
- exit()
- end
- end
- end
- WorldInterface = {
- getBiome = function(x,y,z) return request({"WorldInterface","getBiome",x,y,z}) end,
- getWeather = function() return request({"WorldInterface","getWeather"}) end,
- getBlockInfos = function(x,y,z) return request({"WorldInterface","getBlockInfos",x,y,z}) end,
- getRealDate = function() return request({"WorldInterface","getRealDate"}) end,
- getPlayerList = function() return request({"WorldInterface","getPlayerList"}) end,
- getMethods = function(methodName)
- methodName = methodName or false
- if methodName=="getBiome" then
- b = true
- r = [[WorldInterface.getBiome(X,Y,Z)
- Return the biome type at coordinates in the world.]]
- elseif methodName=="getWeather" then
- b = true
- r = [[WorldInterface.getWeather()
- Return the weather in the world like "Rain", "Thunder", "Clear".]]
- elseif methodName=="getBlockInfos" then
- b = true
- r = _format([[WorldInterface.getBlockInfos(X,Y,Z)
- Return %s informations about the block at one coordinate like name, metadatas,%s etc...]],
- modLIP_ServerPatchedVersion and "main" or "every",
- modLIP_ServerPatchedVersion and "" or " datatags,")
- elseif modLIP_ServerPatchedVersion and methodName=="getBlockDatatags" then
- b = true
- r = [[WorldInterface.getBlockDatatags(X,Y,Z)
- Return every datatags about the block at one coordinate like name, metadatas, datatags, etc...]]
- elseif methodName=="getRealDate" then
- b = true
- r = [[WorldInterface.getRealDate()
- Return the date of the server like
- "Sun Sep 04 23:39:44 CEST 2016"]]
- elseif methodName=="getPlayerList" then
- b = true
- r = [[WorldInterface.getPlayerList()
- Return the list of the online players.]]
- elseif methodName=="getMethods" then
- b = true
- r = [[WorldInterface.getMethods()
- WorldInterface.getMethods(MethodName)
- Return list of every function of World Interface.
- Return information about specific method, if MethodName is specified.]]
- else
- b = true
- r = string.format([[WorldInterface.getBiome(X,Y,Z)
- WorldInterface.getWeather()
- WorldInterface.getBlockInfos(X,Y,Z)%s
- WorldInterface.getRealDate()
- WorldInterface.getPlayerList()
- WorldInterface.getMethods(MethodName)]], modLIP_ServerPatchedVersion and "\nWorldInterface.BlockDatatags(X,Y,Z)" or "")
- end
- end,
- }
- EntityDetector = {
- getEntityList = function(r,x,y,z) return request({"EntityDetector","getEntityList",r,x,y,z}) end,
- getPlayerDetail = function(name) return request({"EntityDetector","getPlayerDetail",name}) end,
- getMethods = function(methodName)
- methodName = methodName or false
- if methodName=="getEntityList" then
- b = true
- r = _format([[EntityDetector.getEntityList(Range,X,Y,Z)
- Return %s informations about every entities like monsters and players in a radius, and coordinate define center of the radius.]],
- modLIP_ServerPatchedVersion and "main" or "every")
- elseif modLIP_ServerPatchedVersion and methodName=="getEntityListAdvanced" then
- b = true
- r = [[EntityDetector.getEntityListAdvanced(Range,X,Y,Z)
- Return every informations about every entities like monsters and players in a radius, and coordinate define center of the radius.]]
- elseif methodName=="getPlayerDetail" then
- b = true
- r = [[EntityDetector.getPlayerDetail(PlayerName)
- Return every informations about the player like health, armor etc.]]
- elseif methodName=="getMethods" then
- b = true
- r = [[EntityDetector.getMethods()
- EntityDetector.getMethods(MethodName)
- Return list of every function of Entity Detector.
- Return information about specific methode, if methodName is specified.]]
- else
- b = true
- r = _format([[EntityDetector.getEntityList(Range,X,Y,Z)%s
- EntityDetector.getPlayerDetail(PlayerName)
- EntityDetector.getMethods(MethodName)]],
- modLIP_ServerPatchedVersion and "\nEntityDetector.getEntityListAdvanced(Range,X,Y,Z)" or "")
- end
- end,
- }
- if modLIP_ServerPatchedVersion then
- WorldInterface.getBlockDatatags = function(x,y,z)
- return request({"WorldInterface","getBlockDatatags",x,y,z})
- end
- EntityDetector.getEntityListAdvanced = function(r,x,y,z)
- return request({"EntityDetector","getEntityListAdvanced",r,x,y,z})
- end
- end
Add Comment
Please, Sign In to add comment