|
1 | 1 | # JSONMessage |
| 2 | + |
2 | 3 | A modern version of Fanciful |
3 | 4 |
|
4 | 5 | This library aims to completely replace [Fanciful](https://bukkit.org/threads/lib-fanciful-pleasant-chat-message-formatting.195148/), which sadly has stopped being updated. I figured I'd take a stab at re-creating it, and even making it better. |
5 | 6 |
|
6 | 7 | The best thing about this library? It's only a [single class file](https://github.com/Rayzr522/JSONMessage/blob/master/src/main/java/com/perceivedev/jsonmessage/JSONMessage.java), so you can just drag and drop it into your project! |
7 | 8 |
|
8 | 9 | ## Usage |
| 10 | + |
9 | 11 | This library is extremely easy to use! It uses a nearly identical system as Fanciful. Example: |
10 | | - |
11 | | - JSONMessage.create("Hello!").color(ChatColor.RED); |
12 | | - |
| 12 | + |
| 13 | +```java |
| 14 | +JSONMessage.create("Hello!").color(ChatColor.RED); |
| 15 | +``` |
| 16 | + |
13 | 17 | This creates a simple message saying "Hello!", with red text. Now you might say to yourself, why use this? I can easily make red text and send it to the player! Well my friend, there are many more features. Be patient :wink: |
14 | 18 |
|
15 | 19 | Here's a more complicated example, showing the true power of JSONMessage: |
16 | 20 |
|
17 | | - JSONMessage.create("Go to the ") |
18 | | - .color(ChatColor.GOLD) |
19 | | - .then("best website ever!") |
20 | | - .color(ChatColor.BLUE) |
21 | | - .tooltip("Click to go") |
22 | | - .openURL("http://www.youtube.com/"); |
23 | | - |
| 21 | +```java |
| 22 | +JSONMessage.create("Go to the ") |
| 23 | + .color(ChatColor.GOLD) |
| 24 | + .then("best website ever!") |
| 25 | + .color(ChatColor.BLUE) |
| 26 | + .tooltip("Click to go") |
| 27 | + .openURL("http://www.youtube.com/"); |
| 28 | +``` |
| 29 | + |
24 | 30 | This example creates a message in two parts, one gold, one blue, and gives the second part a tooltip as well as an action! When you click on this, it will open YouTube. |
25 | 31 |
|
26 | 32 | One thing to note about tooltips is that they *themselves* can actually take a JSONMessage as a parameter: |
27 | 33 |
|
28 | | - JSONMessage.create("This has a fancy tooltip!") |
29 | | - .color(ChatColor.GOLD); |
30 | | - .tooltip(JSONMessage.create("Green text!") |
31 | | - .color(ChatColor.GREEN) |
32 | | - .style(ChatColor.BOLD) |
33 | | - .then("\nUse the newline character to\nadd lines to the tooltip") |
34 | | - .color(ChatColor.YELLOW)) |
35 | | - |
| 34 | +```java |
| 35 | +JSONMessage.create("This has a fancy tooltip!") |
| 36 | + .color(ChatColor.GOLD); |
| 37 | + .tooltip(JSONMessage.create("Green text!") |
| 38 | + .color(ChatColor.GREEN) |
| 39 | + .style(ChatColor.BOLD) |
| 40 | + .then("\nUse the newline character to\nadd lines to the tooltip") |
| 41 | + .color(ChatColor.YELLOW)) |
| 42 | +``` |
| 43 | + |
36 | 44 | You can also make text which runs commands when you click on it: |
37 | 45 |
|
38 | | - JSONMessage.create("Click") |
39 | | - .color(ChatColor.GOLD) |
40 | | - .then(" here ") |
41 | | - .color(ChatColor.RED) |
42 | | - .runCommand("/warp spawn") |
43 | | - .then("to go to spawn") |
44 | | - .color(ChatColor.GOLD); |
45 | | - |
| 46 | +```java |
| 47 | +JSONMessage.create("Click") |
| 48 | + .color(ChatColor.GOLD) |
| 49 | + .then(" here ") |
| 50 | + .color(ChatColor.RED) |
| 51 | + .runCommand("/warp spawn") |
| 52 | + .then("to go to spawn") |
| 53 | + .color(ChatColor.GOLD); |
| 54 | +``` |
| 55 | + |
46 | 56 | To send a JSONMessage, it's quite simple: |
47 | 57 |
|
48 | | - JSONMessage.create("Hello!") |
49 | | - .tooltip("World!") |
50 | | - .send(player); |
51 | | - |
| 58 | +```java |
| 59 | +JSONMessage.create("Hello!") |
| 60 | + .tooltip("World!") |
| 61 | + .send(player); |
| 62 | +``` |
| 63 | + |
52 | 64 | You can pass as many players as you want into `send`, meaning you could send this to huge groups of players. |
53 | 65 |
|
54 | | -*Note: If you don't have the following features then please make sure to download the latest version of the class file* |
| 66 | +> Note: If you don't have the following features then please make sure to download the latest version of the class file |
55 | 67 |
|
56 | 68 | You can now send titles and subtitles too. It's actually very much like send: |
57 | 69 |
|
58 | | - JSONMessage.create("I am a title") |
59 | | - .color(ChatColor.GREEN) |
60 | | - .style(ChatColor.ITALIC) |
61 | | - .title(10, 20, 10, player); |
62 | | - |
| 70 | +```java |
| 71 | +JSONMessage.create("I am a title") |
| 72 | + .color(ChatColor.GREEN) |
| 73 | + .style(ChatColor.ITALIC) |
| 74 | + .title(10, 20, 10, player); |
| 75 | +``` |
| 76 | + |
63 | 77 | Explanation time. What are those numbers? They are quite simply the `fadeIn`, `stay`, and `fadeOut` variables. These control various aspects of the timing of the title, and they're measured in ticks. So for this example it fades in over 0.5 seconds, stays visible for 1 second, then fades out again over 0.5 seconds. |
64 | 78 |
|
65 | 79 | Adding a subtitle to this is just as easy: |
66 | 80 |
|
67 | | - JSONMessage.create("I am a title") |
68 | | - .color(ChatColor.GREEN) |
69 | | - .style(ChatColor.ITALIC) |
70 | | - .title(10, 20, 10, player); |
71 | | - |
72 | | - JSONMessage.create("A wild subtitle has appeared!") |
73 | | - .color(ChatColor.GOLD) |
74 | | - .subtitle(player); |
75 | | - |
| 81 | +```java |
| 82 | +JSONMessage.create("I am a title") |
| 83 | + .color(ChatColor.GREEN) |
| 84 | + .style(ChatColor.ITALIC) |
| 85 | + .title(10, 20, 10, player); |
| 86 | +``` |
| 87 | + |
| 88 | +```java |
| 89 | +JSONMessage.create("A wild subtitle has appeared!") |
| 90 | + .color(ChatColor.GOLD) |
| 91 | + .subtitle(player); |
| 92 | +``` |
| 93 | + |
76 | 94 | The only thing to note is that for subtitles you don't pass in times, as that's completely handled by the orginial title. |
77 | 95 |
|
78 | | -*Note: If you don't have the following features then please make sure to download the latest version of the class file* |
| 96 | +> Note: If you don't have the following features then please make sure to download the latest version of the class file |
79 | 97 |
|
80 | 98 | Actionbar messages can be sent as well, however there's some oddities with them. They don't use the new JSON format, they actually use the legacy format which uses actual color codes. As such, they don't support click events, hover events, that sort of thing. |
81 | 99 |
|
82 | 100 | There are two ways that JSONMessage allows you to send action bars; a static method: |
83 | 101 |
|
84 | | - JSONMessage.actionbar("Hello", player); |
85 | | - |
| 102 | +```java |
| 103 | +JSONMessage.actionbar("Hello", player); |
| 104 | +``` |
| 105 | + |
86 | 106 | To add coloring to this you can use `&` color codes: |
87 | 107 |
|
88 | | - JSONMessage.actionbar("&6I got &ccolors!", player); |
89 | | - |
| 108 | +```java |
| 109 | +JSONMessage.actionbar("&6I got &ccolors!", player); |
| 110 | +``` |
| 111 | + |
90 | 112 | The other way to send action bars is by creating a JSONMessage like you normally would and then send it to the player: |
91 | 113 |
|
92 | | - JSONMessage.create("I am a title") |
93 | | - .color(ChatColor.GREEN) |
94 | | - .style(ChatColor.ITALIC) |
95 | | - .actionbar(player); |
96 | | - |
| 114 | +```java |
| 115 | +JSONMessage.create("I am a title") |
| 116 | + .color(ChatColor.GREEN) |
| 117 | + .style(ChatColor.ITALIC) |
| 118 | + .actionbar(player); |
| 119 | +``` |
| 120 | + |
97 | 121 | This will convert the JSON format to the legacy format and then send it to the player. |
98 | 122 |
|
99 | 123 | If you want to see all the available methods, you can find them just below this. |
@@ -125,5 +149,6 @@ Method | Description |
125 | 149 | `actionbar(Player...)` | Converts the JSONMessage to the legacy format and sends it to one or many players |
126 | 150 |
|
127 | 151 | ### Method Notes |
| 152 | + |
128 | 153 | - `color(ChatColor)` and `style(ChatColor)` both use ChatColors but require different types. Attempting to pass the wrong type in (e.g. doing `style(ChatColor.GREEN)`, or doing `color(ChatColor.BOLD)`) will result in an IllegalArgumentException. |
129 | 154 | - `tooltip(JSONMessage)` takes another JSONMessage instance, allowing you to create fancy text for your tooltips. |
0 commit comments