Skip to content

Commit c194b66

Browse files
committed
Cleaned up the README
1 parent 0fb427f commit c194b66

1 file changed

Lines changed: 80 additions & 55 deletions

File tree

README.md

Lines changed: 80 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,123 @@
11
# JSONMessage
2+
23
A modern version of Fanciful
34

45
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.
56

67
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!
78

89
## Usage
10+
911
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+
1317
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:
1418

1519
Here's a more complicated example, showing the true power of JSONMessage:
1620

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+
2430
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.
2531

2632
One thing to note about tooltips is that they *themselves* can actually take a JSONMessage as a parameter:
2733

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+
3644
You can also make text which runs commands when you click on it:
3745

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+
4656
To send a JSONMessage, it's quite simple:
4757

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+
5264
You can pass as many players as you want into `send`, meaning you could send this to huge groups of players.
5365

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
5567
5668
You can now send titles and subtitles too. It's actually very much like send:
5769

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+
6377
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.
6478

6579
Adding a subtitle to this is just as easy:
6680

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+
7694
The only thing to note is that for subtitles you don't pass in times, as that's completely handled by the orginial title.
7795

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
7997
8098
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.
8199

82100
There are two ways that JSONMessage allows you to send action bars; a static method:
83101

84-
JSONMessage.actionbar("Hello", player);
85-
102+
```java
103+
JSONMessage.actionbar("Hello", player);
104+
```
105+
86106
To add coloring to this you can use `&` color codes:
87107

88-
JSONMessage.actionbar("&6I got &ccolors!", player);
89-
108+
```java
109+
JSONMessage.actionbar("&6I got &ccolors!", player);
110+
```
111+
90112
The other way to send action bars is by creating a JSONMessage like you normally would and then send it to the player:
91113

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+
97121
This will convert the JSON format to the legacy format and then send it to the player.
98122

99123
If you want to see all the available methods, you can find them just below this.
@@ -125,5 +149,6 @@ Method | Description
125149
`actionbar(Player...)` | Converts the JSONMessage to the legacy format and sends it to one or many players
126150

127151
### Method Notes
152+
128153
- `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.
129154
- `tooltip(JSONMessage)` takes another JSONMessage instance, allowing you to create fancy text for your tooltips.

0 commit comments

Comments
 (0)