diff --git a/server/app/config.go b/server/app/config.go index 7a64406..923aa68 100644 --- a/server/app/config.go +++ b/server/app/config.go @@ -61,6 +61,7 @@ type MapObjectConfig struct { ATM bool `json:"atm"` Train bool `json:"train"` Minecart bool `json:"minecart"` + Locator bool `json:"locator"` } type WebApiConfig struct { @@ -148,6 +149,7 @@ func ParseConfig(filename string) (*Config, error) { ATM: true, Train: true, Minecart: false, + Locator: false, } mapblockaccessor := MapBlockAccessorConfig{ diff --git a/server/mapobject/locator.go b/server/mapobject/locator.go new file mode 100644 index 0000000..2df41d8 --- /dev/null +++ b/server/mapobject/locator.go @@ -0,0 +1,29 @@ +package mapobject + +import ( + "mapserver/mapblockparser" + "mapserver/mapobjectdb" +) + +type Locator struct{} + +func (this *Locator) onMapObject(x, y, z int, block *mapblockparser.MapBlock) *mapobjectdb.MapObject { + md := block.Metadata.GetMetadata(x, y, z) + nodename := block.GetNodeName(x, y, z) + + var level = "1" + switch nodename { + case "locator:beacon_2": + level = "2" + case "locator:beacon_3": + level = "3" + } + + o := mapobjectdb.NewMapObject(block.Pos, x, y, z, "locator") + o.Attributes["owner"] = md["owner"] + o.Attributes["name"] = md["name"] + o.Attributes["active"] = md["active"] + o.Attributes["level"] = level + + return o +} diff --git a/server/mapobject/setup.go b/server/mapobject/setup.go index ab1da40..5e4a5cd 100644 --- a/server/mapobject/setup.go +++ b/server/mapobject/setup.go @@ -150,5 +150,13 @@ func Setup(ctx *app.App) { l.AddMapObject("atm:atm", &ATM{}) } + //locator + if ctx.Config.MapObjects.Locator { + loc := &Locator{} + l.AddMapObject("locator:beacon_1", loc) + l.AddMapObject("locator:beacon_2", loc) + l.AddMapObject("locator:beacon_3", loc) + } + ctx.BlockAccessor.Eventbus.AddListener(&l) }