forked from Tnze/go-mc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clickevent.go
61 lines (54 loc) · 1.96 KB
/
clickevent.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package chat
import "strconv"
// ClickEvent defines an event that occurs when this component is clicked.
type ClickEvent struct {
Action string `json:"action"`
Value string `json:"value"`
}
// OpenURL create a ClickEvent opens the given URL in the default web browser.
// Ignored if the player has opted to disable links in chat;
// may open a GUI prompting the user if the setting for that is enabled.
// The link's protocol must be set and must be http or https, for security reasons.
func OpenURL(url string) *ClickEvent {
return &ClickEvent{
Action: "open_url",
Value: url,
}
}
// RunCommand create a ClickEvent runs the given command. Not required to be a command -
// clicking this only causes the client to send the given content as a chat message,
// so if not prefixed with /, they will say the given text instead.
// If used in a book GUI, the GUI is closed after clicking.
func RunCommand(cmd string) *ClickEvent {
return &ClickEvent{
Action: "run_command",
Value: cmd,
}
}
// SuggestCommand create a ClickEvent replaces the content of the chat box with the given text -
// usually a command, but it is not required to be a command
// (commands should be prefixed with /).
// This is only usable for messages in chat.
func SuggestCommand(cmd string) *ClickEvent {
return &ClickEvent{
Action: "suggest_command",
Value: cmd,
}
}
// ChangePage create a ClickEvent usable within written books.
// Changes the page of the book to the given page, starting at 1.
// For instance, "value":1 switches the book to the first page.
// If the page is less than one or beyond the number of pages in the book, the event is ignored.
func ChangePage(page int) *ClickEvent {
return &ClickEvent{
Action: "change_page",
Value: strconv.Itoa(page),
}
}
// CopyToClipboard create a ClickEvent copies the given text to the client's clipboard when clicked.
func CopyToClipboard(text string) *ClickEvent {
return &ClickEvent{
Action: "copy_to_clipboard",
Value: text,
}
}