Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Minecraft Intranet
- Name registration
- --]]
- mcnet = mcnet or {}
- mcnet.names = mcnet.names or {}
- local names = mcnet.names
- local Names = common.newClass{}
- function names.new()
- return Names:new()
- end
- -- Constructor
- function Names:init()
- self.names = {}
- end
- -- Registration
- function Names:register(name, computerID)
- assert(type(name) == "string", "invalid name")
- assert(type(computerID) == "number", "invalid computer ID")
- self.names[name] = computerID
- return true
- end
- function Names:unregister(name)
- assert(type(name) == "string", "invalid name")
- self.names[name] = nil
- return true
- end
- -- Retrieval
- function Names:get(name)
- assert(type(name) == "string", "invalid name")
- return self.names[name]
- end
- function Names:getName(computerID)
- assert(type(computerID) == "number", "invalid computer ID")
- for name,id in pairs(self.names) do
- if (computerID == id) then
- return name
- end
- end
- return nil
- end
- function Names:getAll()
- return common.getValues(self.names)
- end
- function Names:getNames()
- return common.getKeys(self.names)
- end
Advertisement
Add Comment
Please, Sign In to add comment