Documentation
¶
Index ¶
- Variables
- func ExtractZip(path string, destDir string) error
- func FindActiveWorldDir(serverDir string) (string, error)
- func FindAddonsInDir(dir string, recursive bool) ([]string, error)
- func FindManifestsRelativePathInAddon(addonPath string) ([]string, error)
- func FindWorldDirectories(serverDir string) ([]string, error)
- func GetDirectoryContentAbsolutePaths(dirPath string) ([]string, error)
- func GetFileSize(path string) (int64, error)
- func GetFileSizeSafe(path string) int64
- func GetPacksLongestCommonPathPrefix(packs []*Pack) string
- func IsPackRegisteredInRegistryFile(path string, uuid string, version Version) (bool, error)
- func IsValidAddonFile(path string) bool
- func IsValidAddonFileExtension(path string) bool
- func IsValidMcAddonFile(path string) bool
- func IsValidMcPackFile(path string) bool
- func IsValidServerDirectory(path string) bool
- func LoadLanguageProperties(path string) (*properties.Properties, error)
- func LoadLanguagePropertiesFromBytes(data []byte) (*properties.Properties, error)
- func LoadLanguages(filePath string) ([]string, error)
- func LoadLanguagesFromBytes(data []byte) ([]string, error)
- func LoadRegistryFile(path string) ([]registryEntry, error)
- func NotImplementedErr() error
- func RegisterPackInRegistryFile(path string, uuid string, version Version) error
- func RemoveFormattingInPackName(name string) string
- func RemoveInvalidFileSystemCharacters(s string) string
- func RemoveNonAsciiCharacters(s string) string
- func RemoveNonPrintableCharacters(s string) string
- func ReplaceInvalidFileSystemCharacters(s string, replacement string) string
- func ReplaceNonAsciiCharacters(s string, replacement string) string
- func ReplaceNonPrintableCharacters(s string, replacement string) string
- func ResolveAddonByUUID(uuid string, serverDir string) (string, error)
- func SanitizeString(s string, replacement string) string
- func SortPacksByKind(packs []*Pack)
- func SortPacksByNames(packs []*Pack)
- func StringsCompareN(s1, s2 string, n int) bool
- func UnregisterPackInRegistryFile(path string, uuid string, version Version) error
- func ValidateAddonFile(path string) error
- func ValidateDirectory(path string) error
- func ValidateServerDirectory(path string) error
- func WriteRegistryFile(path string, entries []registryEntry) error
- func ZipFilePathGetParentDir(path string) string
- func ZipFilePathJoin(elem ...string) string
- type AddonManifest
- type Command
- type Dependency
- type Header
- type Metadata
- type Module
- type Pack
- func FilterPacksByKind(packs []*Pack, kind PackKind) []*Pack
- func FilterPacksByUUID(packs []*Pack, uuid string) []*Pack
- func FindPackByUUID(packs []*Pack, uuid string) *Pack
- func InstallAddonInServer(addonPath string, serverDir string) ([]*Pack, error)
- func ListInstalledPacks(serverDir string) ([]*Pack, error)
- func LoadAllPacksFromDirectoriesOrSubdirectories(root string) ([]*Pack, error)
- func LoadPackFromDirectory(path string) (*Pack, error)
- func LoadPackFromZip(zipPath string, packDir string) (*Pack, error)
- func LoadPacksFromSubdirectories(path string) ([]*Pack, error)
- func LoadPacksFromZip(zipPath string) ([]*Pack, error)
- func UninstallAddonInServer(addonPath, serverDir string) ([]*Pack, error)
- func UninstallPackInServerByUUID(uuid, serverDir string) (*Pack, error)
- func (p Pack) Description() string
- func (p Pack) GetDefaultLocalizedTextValue(textKey string) (value string, exists bool)
- func (p Pack) GetFirstLocalizedLanguage() string
- func (p Pack) GetLocalizedTextValue(langKey, textKey string) (value string, exists bool)
- func (p Pack) HasLanguages() bool
- func (p Pack) Kind() (PackKind, error)
- func (p Pack) KindSafe() PackKind
- func (p Pack) Name() string
- func (p Pack) NameSanitized() string
- func (p Pack) NameWithoutFormatting() string
- func (p Pack) UUID() string
- type PackKind
- type Server
- type Version
- type World
- func (w World) InstallAddon(addonPath string) ([]*Pack, error)
- func (w World) InstallPack(pack *Pack) (*Pack, error)
- func (w World) IsPackOwnedByWorld(pack *Pack) bool
- func (w World) IsPackRegistered(pack *Pack) (bool, error)
- func (w World) Name() (string, error)
- func (w World) Packs() ([]*Pack, error)
- func (w World) PacksByKind(kind PackKind) ([]*Pack, error)
- func (w World) PacksByUUID(uuid string) (*Pack, error)
- func (w World) PacksInstallDir(kind PackKind) (string, error)
- func (w World) RegisterPack(pack *Pack) error
- func (w World) UninstallAddon(addonPath string) ([]*Pack, error)
- func (w World) UninstallPack(pack *Pack) (*Pack, error)
- func (w World) UnregisterPack(pack *Pack) error
Constants ¶
This section is empty.
Variables ¶
var AllPackKinds = []PackKind{BehaviorPack, ResourcePack}
AllPackKinds lists all the different kinds of Pack.
var ErrNotImplemented = errors.New("not implemented")
ErrNotImplemented serves as our foundational sentinel error
Functions ¶
func ExtractZip ¶
ExtractZip extracts the contents of the given file path into destDir. The destDir is created if it does not exist.
func FindActiveWorldDir ¶
FindActiveWorldDir identifies the active world directory inside a Minecraft Bedrock server installation directory. Returns the path to the active world directory. Returns an error otherwise.
func FindAddonsInDir ¶
FindAddonsInDir searches dir (resursively, if recursive is true) for files that are valid add-on packs. It returns their absolute paths.
func FindManifestsRelativePathInAddon ¶
FindManifestsRelativePathInAddon returns the archive-relative paths of every manifest.json file found inside the given archive add-on file. Note that returned paths are using forward slashes, as stored in the zip archive. Returns an error if no manifest.json is found in the addon.
func FindWorldDirectories ¶
FindActiveWorldDir found the world directories inside a Minecraft Bedrock server installation directory. Returns an error is the server is missing a `worlds` directory. Returns an empty list if the server `worlds` directory is empty. Returns the paths of the worlds otherwise.
func GetDirectoryContentAbsolutePaths ¶
GetDirectoryContentAbsolutePaths recursively walks through the given directory to find all the files under the given directory. Returns a list of all the files found in absolute paths.
func GetFileSize ¶
GetFileSize returns the size of a file in bytes or an error.
func GetFileSizeSafe ¶
GetFileSize returns the size of a file in bytes. Returns 0 if the file does not exists or there is an error.
func GetPacksLongestCommonPathPrefix ¶ added in v0.4.0
GetPacksLongestCommonPathPrefix finds the longest path prefix shared by all packs in the given slice.
func IsPackRegisteredInRegistryFile ¶
IsPackRegisteredInRegistryFile checks if a pack entry is registered in the given world registry file. Returns an error if the registry file can not be loaded
func IsValidAddonFile ¶
IsValidAddonFile validates that the given path is a directory that matches a Minecraft Bedrock dedicated server installation. Addon files are zip file archives. The file extension must be one of the following: `.zip`, `.mcaddon` or `.mcpack`. Returns true if the given path is a valid add-on. Returns false otherwise.
func IsValidAddonFileExtension ¶
IsValidAddonFileExtension checks if the given file path has a valid file extension for an add-on.
func IsValidMcAddonFile ¶
IsValidMcAddonFile checks that a given file path is a valid MCAddon file.
func IsValidMcPackFile ¶
IsValidMcPackFile checks that a given file path is a valid MCPack file.
func IsValidServerDirectory ¶
IsValidServerDirectory validates that the given path is a directory that matches a Minecraft Bedrock dedicated server installation. It is considered valid if it contains the following: * a server.properties file * a bedrock_server executable * a worlds directory. Returns true if the given path is valid server. Returns false otherwise.
func LoadLanguageProperties ¶ added in v0.4.0
func LoadLanguageProperties(path string) (*properties.Properties, error)
func LoadLanguagePropertiesFromBytes ¶ added in v0.4.0
func LoadLanguagePropertiesFromBytes(data []byte) (*properties.Properties, error)
LoadLanguagePropertiesFromBytes parses the raw JSON bytes of a language *.lang file file as a *properties.Properties.
func LoadLanguages ¶ added in v0.4.0
func LoadLanguagesFromBytes ¶ added in v0.4.0
LoadLanguagesFromBytes parses the raw JSON bytes of a languages.json file as an []string structure.
func LoadRegistryFile ¶
LoadRegistryFile reads the world registry file. A registry file contains a list of registryEntry. If the file does not exist, an empty (not nil-error) list is returned.
func NotImplementedErr ¶
func NotImplementedErr() error
NotImplementedErr dynamically grabs the name of whichever function invokes it
func RegisterPackInRegistryFile ¶
RegisterPackInRegistryFile adds (or updates) a pack entry in the given world registry file. Registering an already-registered pack updates the existing entry. It does not create duplicate the entry.
func RemoveFormattingInPackName ¶ added in v0.4.0
func RemoveInvalidFileSystemCharacters ¶
RemoveInvalidFileSystemCharacters removes characters from a string that are not compatible with most filesystems. It returns a string which can safely be used to create files or directories.
func RemoveNonAsciiCharacters ¶
RemoveNonAsciiCharacters removes non-ascii characters from a string
func RemoveNonPrintableCharacters ¶
RemoveNonPrintableCharacters removes non-printable characters from a string. It returns a string which all characters can be printed on the console or a terminal.
func ReplaceInvalidFileSystemCharacters ¶
ReplaceNonAsciiCharacters takes an input string and replaces any characters that are not filesystem compatible (characters such as control characters in a filesystem) with the specified replacement string.
func ReplaceNonAsciiCharacters ¶
ReplaceNonAsciiCharacters takes an input string and replaces any non-ASCII characters (characters with a code point value greater than 127) with the specified replacement string.
func ReplaceNonPrintableCharacters ¶
ReplaceNonPrintableCharacters takes an input string and replaces any non-printable characters (characters not writable on the console or a terminal) with the specified replacement string.
func ResolveAddonByUUID ¶
ResolveAddonByUUID searches serverDir (recursively) for an add-on file containing a pack whose manifest UUID matches the given UUID. Returns the path of the first matching add-on file found. Returns an empty path if no match is found. Returns an error otherwise.
func SanitizeString ¶
SanitizeString takes an input string and replaces all non-ASCII characters from a string, except for Latin alphabet letters (characters with accents such as ó, ò, ô, ö, õ, and ō) with the specified replacement string.
func SortPacksByKind ¶ added in v0.4.0
func SortPacksByKind(packs []*Pack)
SortPacksByKind orders a pack slice by kind then by name.
func SortPacksByNames ¶ added in v0.4.0
func SortPacksByNames(packs []*Pack)
SortPacksByNames orders a pack slice by name then by kind.
func StringsCompareN ¶
func UnregisterPackInRegistryFile ¶
UnregisterPackInRegistryFile removes a pack entry in the given world registry file. Does not return an error if the given uuid is not already registered. To know if a pack is actually unregistered, use IsPackRegisteredInRegistryFile() before and after the call which is expensive.
func ValidateAddonFile ¶
ValidateAddonFile asserts that the given path is a valid addon file. Addon files are zip file archives. The file extension must be one of the following: `.zip`, `.mcaddon` or `.mcpack`.
func ValidateDirectory ¶
ValidateDirectory asserts that the given path is a valid directory that exists.
func ValidateServerDirectory ¶
ValidateServerDirectory asserts that the given path is a directory that matches a Minecraft Bedrock dedicated server installation. It is considered valid if it contains the following: * a server.properties file * a bedrock_server executable * a worlds directory. Returns nil if the given path is server. Returns a valid error otherwise.
func WriteRegistryFile ¶
WriteRegistryFile write the given registry entries the world registry file. A registry file contains a list of registryEntry. If the file does not exist, the file is created an empty (not nil-error) list is returned.
func ZipFilePathGetParentDir ¶ added in v0.3.0
ZipFilePathGetParentDir returns the parent directory of a given path. The function supports both forward slashes and backslashes.
func ZipFilePathJoin ¶ added in v0.3.0
ZipFilePathJoin joins any number of path elements into a single path, separating them with a the ZIP specific separator `/`. Empty elements are ignored.
Types ¶
type AddonManifest ¶
type AddonManifest struct {
FormatVersion int `json:"format_version"`
Header Header `json:"header"`
Modules []Module `json:"modules,omitempty"`
Dependencies []Dependency `json:"dependencies,omitempty"`
Capabilities []string `json:"capabilities,omitempty"`
Metadata *Metadata `json:"metadata,omitempty"`
}
AddonManifest mirrors the structure of a Minecraft Bedrock pack manifest.json file.
func LoadManifestFromBytes ¶
func LoadManifestFromBytes(data []byte) (*AddonManifest, error)
LoadManifestFromBytes parses the raw JSON bytes of a manifest.json file as an AddonManifest structure.
func LoadManifestFromFile ¶
func LoadManifestFromFile(path string) (*AddonManifest, error)
LoadManifestFromFile loads a manifest.json data from a file path as an AddonManifest structure.
type Dependency ¶
type Dependency struct {
UUID string `json:"uuid,omitempty"`
ModuleName string `json:"module_name,omitempty"`
Version Version `json:"version,omitempty"`
}
Dependency mirrors an entry of the "dependencies" array of a manifest.json.
type Header ¶
type Header struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
UUID string `json:"uuid"`
Version Version `json:"version"`
MinEngineVersion Version `json:"min_engine_version,omitempty"`
}
Header mirrors the "header" object of a Minecraft Bedrock manifest.json.
type Metadata ¶
type Metadata struct {
Authors []string `json:"authors,omitempty"`
License string `json:"license,omitempty"`
URL string `json:"url,omitempty"`
}
Metadata mirrors the optional "metadata" object of a manifest.json.
type Module ¶
type Module struct {
Type string `json:"type"`
UUID string `json:"uuid,omitempty"`
Version Version `json:"version"`
Description string `json:"description,omitempty"`
Entry string `json:"entry,omitempty"`
}
Module mirrors an entry of the "modules" array of a manifest.json.
type Pack ¶
type Pack struct {
Path string
Manifest *AddonManifest
LanguageList []string
LanguageMap map[string]*properties.Properties
}
func FilterPacksByKind ¶
FilterPacksByKind filters a given list of packs by PackKind.
func FilterPacksByUUID ¶
FilterPacksByUUID filters a given list of packs by UUID. There should not be multiple packs with the same UUID in the same list. This function is mostly for cleanup and integrity.
func FindPackByUUID ¶
FindPackByUUID searches a given list of packs for a pack with the given UUID.
func InstallAddonInServer ¶
InstallAddonInServer installs every pack contained in the given add-on file (addonPath) into the given Minecraft Bedrock server located at serverDir. Returns the list of packs that were installed. Returns an error otherwise.
func ListInstalledPacks ¶
ListInstalledPacks lists the packs currently registered for a given Minecraft Bedrock server located at serverDir. For each registered UUID, it attempts to resolve the name of the pack by scanning the corresponding behavior_packs/ or resource_packs/ directories for a matching manifest.json.
func LoadAllPacksFromDirectoriesOrSubdirectories ¶
LoadAllPacksFromDirectoriesOrSubdirectories recursively traverses the given directory to detect and load directories containing Packs. This function is compatible with `.mcpack` and `.mcaddon` files. Extension `.mcpack` have a manifest.json file at the root directory. Extension `.mcaddon` have a manifest.json file in each sub directory. Returns an error if a directory containing a manifest.json which fails to load as a pack. Returns am empty pack list when no manifest.json files is found.
func LoadPackFromDirectory ¶
LoadPackFromDirectory loads a pack stored in the given directory. The given directory path must contains a manifest.json file to be a valid pack. Returns a valid pack or an error otherwise.
func LoadPackFromZip ¶ added in v0.3.0
LoadPackFromZip loads a pack stored in the given relative zip directory. The given relative directory path must contains a manifest.json file to be a valid pack. Returns a valid pack or an error otherwise.
func LoadPacksFromSubdirectories ¶
LoadPacksFromSubdirectories browse the sub directories from the given directory and loads a pack from each subdir. All sub directories must be a valid pack directory, otherwise the function returns an error. Returns a valid list of packs. Returns an empty list if there are no subdirectories. Returns an error otherwise.
func LoadPacksFromZip ¶ added in v0.3.0
LoadPacksFromZip recursively traverses the given zip file to detect and load directories containing Packs. This function is compatible with `.mcpack` and `.mcaddon` files. Extension `.mcpack` have a manifest.json file at the root directory. Extension `.mcaddon` have a manifest.json file in each sub directory. Returns an error if a directory containing a manifest.json which fails to load as a pack. Returns am empty pack list when no manifest.json files is found.
func UninstallAddonInServer ¶
UninstallAddonInServer uninstalls every pack contained in the add-on file at the given addonPath from the Minecraft Bedrock server installed at serverDir. It returns the list of packs that were uninstalled or an error.
func UninstallPackInServerByUUID ¶
UninstallPackInServerByUUID uninstalls a single pack, identified by a UUID from the Minecraft Bedrock server installed at serverDir. This function is useful when the original add-on file is no longer available or has been deleted.
func (Pack) Description ¶
func (Pack) GetDefaultLocalizedTextValue ¶ added in v0.4.0
func (Pack) GetFirstLocalizedLanguage ¶ added in v0.4.0
func (Pack) GetLocalizedTextValue ¶ added in v0.4.0
func (Pack) HasLanguages ¶ added in v0.4.0
func (Pack) NameSanitized ¶
func (Pack) NameWithoutFormatting ¶ added in v0.4.0
type PackKind ¶
type PackKind int
PackKind identifies whether a pack found inside an add-on is a behavior or a resource pack.
func IdentifyPackKind ¶
func IdentifyPackKind(m *AddonManifest) (PackKind, error)
IdentifyPackKind inspects a AddonManifest sutrct to determines if the manifest matches a behavior pack or a resource pack. Behavior packs use module types "data" or "script". Resource packs use module types "resources", "client_data" or "interface".
func (PackKind) InstallDirName ¶
InstallDirName returns the directory name where a pack of the given kind must be installed in a world. Possible return values are `behavior_packs`, `resource_packs` or an error.
func (PackKind) RegistryFileName ¶
RegistryFileName returns the world registry file name that manages the given kind of pack. Possible return values are `world_behavior_packs.json`, `world_resource_packs.json` or an error.
type Version ¶
type Version [3]int
Version represents a Minecraft Bedrock manifest [major, minor, patch] version triplet.
func (*Version) UnmarshalJSON ¶
UnmarshalJSON unmarshal a Version from an array of 3 integers (`[1, 2, 3]`) or from a string (`"4.5.6"`). Some manifest specifies versions as string instead of the offical 3 integer array.
type World ¶
type World struct {
Path string
}
func (World) InstallAddon ¶
InstallAddonInWorld installs every pack contained in the given add-on file (addonPath) into the given Minecraft Bedrock world directory at worldDir. Returns the list of packs that were installed. Returns an error otherwise.
func (World) InstallPack ¶
InstallPackInWorld installs the given pack into the given Minecraft Bedrock world directory at worldDir. During the installation process, the pack's original directory is moved to a new location. Returns the pack's updated information if installed succesfully. Returns an error otherwise.
func (World) IsPackOwnedByWorld ¶
IsPackOwnedByWorld defines if a given pack is owned by this world. A pack is owned when it is installed in an official kind directory. Returns true when the given pack is owned by this world. Returns false otherwise.
func (World) IsPackRegistered ¶
IsPackRegistered checks if the given pack is registered in the world. Returns an error if the registry file can not be loaded
func (World) Name ¶
Name returns the name of the World. The name of a level is stored in file `levelname.txt`. If this file is missing, the function fall back to using the directory name as the name of the world.
func (World) PacksByKind ¶
PacksByKind returns the packs installed in this world that matches the given kind of pack.
func (World) PacksByUUID ¶
PacksByKind searches the packs installed in this world and returns the pack that matches the given UUID. Returns nil if the pack is not found (no error)
func (World) PacksInstallDir ¶
PacksInstallDir provides the installation directory path for a given kind of packs.
func (World) RegisterPack ¶
RegisterPack registers the given pack in the world.
func (World) UninstallAddon ¶
UninstallAddonInWorld uninstalls every pack contained in the given add-on file (addonPath) from the given Minecraft Bedrock world directory at worldDir. Returns the list of packs that were installed. Returns an error otherwise.
func (World) UninstallPack ¶
UninstallPackInWorld uninstalls the given pack from the given Minecraft Bedrock world directory at worldDir.
func (World) UnregisterPack ¶
UnregisterPack unregisters the given pack in the world.