-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMessaging.java
148 lines (137 loc) · 5 KB
/
Messaging.java
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**
* iConomy v1.x
* Copyright (C) 2010 Nijikokun <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Messaging.java
* <br /><br />
* Lets us do fancy pantsy things with colors, messages, and broadcasting :D!
*
* @author Nijikokun <[email protected]>
*/
public class Messaging {
public static Player player = null;
/**
* Converts a list of arguments into points.
*
* @param original The original string necessary to convert inside of.
* @param arguments The list of arguments, multiple arguments are seperated by commas for a single point.
* @param points The point used to alter the argument.
*
* @return <code>String</code> - The parsed string after converting arguments to variables (points)
*/
public static String argument(String original, String[] arguments, String[] points) {
for (int i = 0; i < arguments.length; i++) {
if(arguments[i].contains(",")) {
for(String arg : arguments[i].split(",")) {
original = original.replace(arg, points[i]);
}
} else {
original = original.replace(arguments[i], points[i]);
}
}
return original;
}
/**
* Parses the original string against color specific codes. This one converts &[code] to §[code]
* <br /><br />
* Example:
* <blockquote><pre>
* Messaging.parse("Hello &2world!"); // returns: Hello §2world!
* </pre></blockquote>
*
* @param original The original string used for conversions.
*
* @return <code>String</code> - The parsed string after conversion.
*/
public static String parse(String original) {
return original.replaceAll("(&([a-z0-9]))", "§$2").replace("\\\\\u00A7", "&");
}
/**
* Converts color codes into the simoleon code. Sort of a HTML format color code tag.
* <p>
* Color codes allowed: black, navy, green, teal, red, purple, gold, silver, gray, blue, lime, aqua, rose, pink, yellow, white.</p>
* Example:
* <blockquote<pre>
* Messaging.colorize("Hello <green>world!"); // returns: Hello §2world!
* </pre></blockquote>
*
* @param original Original string to be parsed against group of color names.
*
* @return <code>String</code> - The parsed string after conversion.
*/
public static String colorize(String original) {
return original.replace("<black>", "§0").replace("<navy>", "§1").replace("<green>", "§2").replace("<teal>", "§3").replace("<red>", "§4").replace("<purple>", "§5").replace("<gold>", "§6").replace("<silver>", "§7").replace("<gray>", "§8").replace("<blue>", "§9").replace("<lime>", "§a").replace("<aqua>", "§b").replace("<rose>", "§c").replace("<pink>", "§d").replace("<yellow>", "§e").replace("<white>", "§f");
}
/**
* Helper function to assist with making brackets. Why? Dunno, lazy.
*
* @param message The message inside of brackets.
*
* @return <code>String</code> - The message inside [brackets]
*/
public static String bracketize(String message) {
return "[" + message + "]";
}
/**
* Save the player to be sent messages later. Ease of use sending messages.
* <br /><br />
* Example:
* <blockquote><pre>
* Messaging.save(player);
* Messaging.send("This will go to the player saved.");
* </pre></blockquote>
*
* @param player The player we wish to save for later.
*/
public static void save(Player player) {
Messaging.player = player;
}
/**
* Sends a message to a specific player.
* <br /><br />
* Example:
* <blockquote><pre>
* Messaging.send(player, "This will go to the player saved.");
* </pre></blockquote>
*
* @param player Player we are sending the message to.
* @param message The message to be sent.
*/
public static void send(Player player, String message) {
player.sendMessage(parse(message));
}
/**
* Sends a message to the stored player.
*
* @param message The message to be sent.
* @see Messaging#save(Player)
*/
public static void send(String message) {
if(Messaging.player != null)
player.sendMessage(parse(message));
}
/**
* Brodcast a message to every player online.
*
* @param message - The message to be sent.
*/
public static void broadcast(String message) {
for (Player p : etc.getServer().getPlayerList()) {
p.sendMessage(parse(message));
}
}
}