format

package
v0.0.0-...-03afc55 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2015 License: Apache-2.0 Imports: 8 Imported by: 16

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	True = &vTrue

	False         = &vFalse
	Missing *bool = nil
)

Optional boolean values

Functions

func ConvertLegacy

func ConvertLegacy(c AnyComponent)

Types

type AnyComponent

type AnyComponent struct {
	Value interface{}
}

AnyComponent can respresent any valid chat component. This is designed to be used as a target for json unmarshalling where the type of the component isn't known.

This also has the benefit of allowing plain strings or arrays to be converted into text components simplifing handling of those cases.

func Wrap

func Wrap(i interface{}) AnyComponent

Wrap wraps the passed component with an AnyComponent

func (*AnyComponent) MarshalJSON

func (s *AnyComponent) MarshalJSON() ([]byte, error)

MarshalJSON marshals the contained value to json.

func (AnyComponent) String

func (a AnyComponent) String() string

String provides a string version of the component without formatting.

func (AnyComponent) Type

func (s AnyComponent) Type() Type

Type returns the type of the component this contains. It is genernally prefered to type switch over the result of Value().

func (*AnyComponent) UnmarshalJSON

func (s *AnyComponent) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the passed json as a component. This allows for objects, arrays and strings.

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder allows for easy creation of simple messages.

func Build

func Build(msg string) *Builder

Build creates a builder starting with the initial message.

func (*Builder) Append

func (b *Builder) Append(msg string) *Builder

Append adds the message to the builder and sets it as the current target.

func (*Builder) Color

func (b *Builder) Color(c Color) *Builder

Color changes the color of current message

func (*Builder) Create

func (b *Builder) Create() AnyComponent

Create returns the component created by this builder

type ClickAction

type ClickAction string

ClickAction is an action that will be preformed on clicking.

const (
	OpenURL        ClickAction = "open_url"
	OpenFile       ClickAction = "open_file"
	RunCommand     ClickAction = "run_command"
	SuggestCommand ClickAction = "suggest_command"
)

Valid ClickActions.

type ClickEvent

type ClickEvent struct {
	Action ClickAction `json:"action"`
	Value  string      `json:"value"`
}

ClickEvent is an event which will be preformed when the area of text is clicked.

type Color

type Color string

Color represents one of the 16 valid colors in Minecraft.

const (
	Black       Color = "black"
	DarkBlue    Color = "dark_blue"
	DarkGreen   Color = "dark_green"
	DarkAqua    Color = "dark_aqua"
	DarkRed     Color = "dark_red"
	DarkPurple  Color = "dark_purple"
	Gold        Color = "gold"
	Gray        Color = "gray"
	DarkGray    Color = "dark_gray"
	Blue        Color = "blue"
	Green       Color = "green"
	Aqua        Color = "aqua"
	Red         Color = "red"
	LightPurple Color = "light_purple"
	Yellow      Color = "yellow"
	White       Color = "white"
)

Valid colors.

func (Color) Color

func (c Color) Color() (r, g, b int)

type Component

type Component struct {
	Extra         []AnyComponent `json:"extra,omitempty"`
	Bold          *bool          `json:"bold,omitempty"`
	Italic        *bool          `json:"italic,omitempty"`
	Underlined    *bool          `json:"underlined,omitempty"`
	Strikethrough *bool          `json:"strikethrough,omitempty"`
	Obfuscated    *bool          `json:"obfuscated,omitempty"`
	Color         Color          `json:"color,omitempty"`

	ClickEvent *ClickEvent `json:"clickEvent,omitempty"`
	HoverEvent *HoverEvent `json:"hoverEvent,omitempty"`
	Insertion  string      `json:"insertion,omitempty"`
}

Component is the base for any chat component.

func (*Component) String

func (c *Component) String() string

String provides a string version of the component without formatting.

type HoverAction

type HoverAction string

HoverAction is an action that will be preformed on hovering.

const (
	ShowText        HoverAction = "show_text"
	ShowAchievement HoverAction = "show_achievement"
	ShowItem        HoverAction = "show_item"
)

Valid HoverActions.

type HoverEvent

type HoverEvent struct {
	Action HoverAction `json:"action"`
	Value  string      `json:"value"`
}

HoverEvent is an event which will be preformed when the area of text is hovered over.

type ScoreComponent

type ScoreComponent struct {
	Score struct {
		Name      string `json:"name,omitempty"`
		Objective string `json:"objective,omitempty"`
	} `json:"score"`
	Component
}

ScoreComponent is a component whos value is based on the contents of the scoreboard.

type SelectorComponent

type SelectorComponent struct {
	Selector string `json:"selector,omitempty"`
	Component
}

SelectorComponent is a component whos value is based on evalutating the contained selector.

type TextComponent

type TextComponent struct {
	Text string `json:"text,omitempty"`
	Component
}

TextComponent is a component with a plain text value.

func (*TextComponent) String

func (t *TextComponent) String() string

String provides a string version of the component without formatting.

type TranslateComponent

type TranslateComponent struct {
	Translate string         `json:"translate,omitempty"`
	With      []AnyComponent `json:"with,omitempty"`
	Component
}

TranslateComponent is a component whos value is loaded from a locale file on the client based on the Translate key and the client's language, substituting in values from the With slice.

type Type

type Type int

Type represents a type of a component.

const (
	// Invalid is returned for unknown component types.
	Invalid Type = iota
	// Text is a simple text only component.
	Text
	// Translate is a translatable component.
	Translate
	// Score is a component whos contents depends on a scoreboard value.
	Score
	// Selector is a component whos contents follows Minecraft's
	// selector rules.
	Selector
)

func (Type) String

func (i Type) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL