A modification-free API for Minecraft utilizing log parsing
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

35 lines
587 B

package commands
import "strings"
type CommandHandler func(ctx *CommandContext)
var (
commandMap = make(map[string]*CommandHolder)
)
func Register(prefix string, f CommandHandler) {
h := parseCommandUsage(prefix)
h.Handler = f
commandMap[h.Name] = h
}
func Find(prefix, name, full string) *CommandHolder {
if strings.Index(name, prefix) == 0 {
name = name[len(prefix):]
if holder := Handler(name); holder != nil {
return holder
}
}
return nil
}
func Handler(name string) *CommandHolder {
if holder, ok := commandMap[name]; ok {
return holder
}
return nil
}