├── .gitignore
├── LICENSE
├── README.md
├── pom.xml
└── src
└── main
├── java
└── me
│ └── electroid
│ └── nicknamer
│ ├── MinecraftNameGenerator.java
│ └── NicknamePlugin.java
└── resources
└── plugin.yml
/.gitignore:
--------------------------------------------------------------------------------
1 | *.class
2 |
3 | # Mobile Tools for Java (J2ME)
4 | .mtj.tmp/
5 |
6 | # Package Files #
7 | *.jar
8 | *.war
9 | *.ear
10 |
11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
12 | hs_err_pid*
13 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Electroid
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # UsernameGenerator
2 | A small library and test plugin for generating minecraft usernames.
3 |
4 | - `MinecraftUsernameGenerator.java` is the object the generates minecraft usernames given a "seed" string.
5 |
6 | - `NicknamePlugin.java` is a extremely basic implementation of the generator to create random nicknames.
7 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | me.electroid.Nicknamer
8 | Nicknamer
9 | 0.1
10 |
11 | Nicknamer
12 | A test plugin for random nickname and skin generation.
13 |
14 |
15 |
16 | tc.oc
17 | sportbukkit-api
18 | 1.8-R0.1-SNAPSHOT
19 |
20 |
21 | xerces
22 | xercesImpl
23 | 2.11.0
24 |
25 |
26 | org.jsoup
27 | jsoup
28 | 1.8.2
29 |
30 |
31 |
32 |
33 |
34 |
35 | org.apache.maven.plugins
36 | maven-compiler-plugin
37 | 3.1
38 |
39 | 1.6
40 | 1.6
41 |
42 |
43 |
44 | org.apache.maven.plugins
45 | maven-shade-plugin
46 | 2.2
47 |
48 |
49 | package
50 |
51 | shade
52 |
53 |
54 |
55 |
56 | org.jsoup:jsoup
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 | src/main/resources
67 | true
68 |
69 |
70 |
71 |
72 |
73 | UTF-8
74 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/src/main/java/me/electroid/nicknamer/MinecraftNameGenerator.java:
--------------------------------------------------------------------------------
1 | package me.electroid.nicknamer;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.IOException;
5 | import java.io.InputStreamReader;
6 | import java.net.MalformedURLException;
7 | import java.net.URL;
8 | import java.util.ArrayList;
9 | import java.util.Calendar;
10 | import java.util.Collection;
11 | import java.util.HashMap;
12 | import java.util.Map;
13 | import java.util.regex.Pattern;
14 | import java.util.Random;
15 |
16 | /**
17 | * A username generator that mutates strings into minecraft usernames.
18 | * @author ElectroidFilms
19 | *
20 | */
21 | public class MinecraftNameGenerator {
22 |
23 | /** Mutation number constants. */
24 | private static final int MAX_MUTATIONS = 3;
25 | private static final int MAX_NUMBERS = 4;
26 | private static final int MAX_YEAR_RANGE = 15;
27 | private static final int MAX_UNDERSCORES = 2;
28 | private static final int MAX_CAPITALIZED = 3;
29 | private static final int MAX_PHOENETIC_REPLACEMENTS = 1;
30 |
31 | /** String comparison constants. */
32 | private static final String NUMBER = "\\d";
33 | private static final String UPPERCASE_LETTER = "[A-Z]";
34 | private static final String UNDERSCORE = "_";
35 |
36 | /** Verification variables. */
37 | private static final String MOJANG_URL = "https://api.mojang.com/users/profiles/minecraft/";
38 | private static final String LETTER_REGEX = "[a-zA-Z0-9_]";
39 | private static final String USERNAME_REGEX = "[a-zA-Z0-9_]{1,16}";
40 | private static final int MAX_USERNAME_LENGTH = 16;
41 |
42 | private final int minNameLength;
43 |
44 | /**
45 | * Create a new minecraft name generator.
46 | * @param minNameLength The minimum characters allowed.
47 | */
48 | public MinecraftNameGenerator(int minNameLength) {
49 | this.minNameLength = minNameLength;
50 | }
51 |
52 | /**
53 | * Generate a username based on the seed string provided.
54 | * @param seed The base for generating the username.
55 | * @return The new username.
56 | */
57 | public String generate(String seed) {
58 | String username = scrambleNumbers(seed);
59 | int amount = random(MAX_MUTATIONS - 1) + 1;
60 | for (int i = 0; i <= amount; i++) {
61 | int action = random(8);
62 | switch (action) {
63 | default:
64 | case 0: username = addNumbers(username);
65 | case 1: username = addYear(username);
66 | case 2: username = addRandomUnderscores(username);
67 | case 3: username = addStrategicalUnderscores(username);
68 | case 4: username = addLazyUnderscore(username);
69 | case 5: username = addPhoneticReplacements(username);
70 | case 6: username = addRandomCapitalization(username);
71 | case 7: username = addLogicalCapitalization(username);
72 | }
73 | }
74 | /** Recursive methods to ensure valid username. */
75 | return verifyUsername(username);
76 | }
77 |
78 | /**
79 | * Recursive methods to ensure username is always valid.
80 | * @param seeds The username to verify,
81 | * @return The verifed username.
82 | */
83 | private String verifyUsername(String username) {
84 | if (username.length() > MAX_USERNAME_LENGTH - 1) {
85 | verifyUsername(username.substring(0, username.length() * (2 / 3)));
86 | } else if (username.length() < this.minNameLength) {
87 | verifyUsername(randomLetter() + username);
88 | } else if (!Pattern.compile(USERNAME_REGEX, Pattern.CASE_INSENSITIVE).matcher(username).matches()) {
89 | StringBuilder builder = new StringBuilder();
90 | for (String character : toChars(username)) {
91 | if (character.matches(LETTER_REGEX)) {
92 | builder.append(character);
93 | }
94 | }
95 | verifyUsername(builder.toString());
96 | } else if (doesAlreadyExist(username)) {
97 | verifyUsername(randomLetter() + username.substring(1, username.length()));
98 | }
99 | return username;
100 | }
101 |
102 | /**
103 | * Generate a collection of usernames based on the seed strings provided.
104 | * @param seeds The bases for generating the collection of usernames.
105 | * @return The new usernames.
106 | */
107 | public Collection bulkGenerate(Collection seeds) {
108 | Collection usernames = new ArrayList();
109 | for (String seed : seeds) {
110 | usernames.add(generate(seed));
111 | }
112 | return usernames;
113 | }
114 |
115 | /**
116 | * Scrambles the values of numbers in a string.
117 | * @param string The string to modify.
118 | * @return The new string with scrambled numbers.
119 | */
120 | private String scrambleNumbers(String string) {
121 | StringBuilder builder = new StringBuilder();
122 | for (String character : toChars(string)) {
123 | if (character.matches(NUMBER)) {
124 | character = String.valueOf(random());
125 | }
126 | builder.append(character);
127 | }
128 | return builder.toString();
129 | }
130 |
131 | /**
132 | * Clear all numbers in the string.
133 | * @param string The string to modify.
134 | * @return The string without numbers.
135 | */
136 | private String clearNumbers(String string) {
137 | StringBuilder builder = new StringBuilder();
138 | for (String character : toChars(string)) {
139 | if (!character.matches(NUMBER)) {
140 | builder.append(character);
141 | }
142 | }
143 | return builder.toString();
144 | }
145 |
146 | /**
147 | * Add numbers to the front or back of a string.
148 | * @param string The string to modify.
149 | * @return The new string with numbers.
150 | */
151 | private String addNumbers(String string) {
152 | string = clearNumbers(string);
153 | int length = random(MAX_NUMBERS - 1) + 1;
154 | String numbers = "";
155 | for (int i = 0; i <= length; i++) {
156 | numbers += String.valueOf(random());
157 | }
158 | if (randomBoolean()) {
159 | return numbers += string;
160 | } else {
161 | return string += numbers;
162 | }
163 | }
164 |
165 | /**
166 | * Adds a year (ie. 2015) to the end of the string.
167 | * @param string The string to modify.
168 | * @return The new string with the year.
169 | */
170 | private String addYear(String string) {
171 | string = clearNumbers(string);
172 | StringBuilder builder = new StringBuilder();
173 | final Calendar now = Calendar.getInstance();
174 | final int year = now.get(Calendar.YEAR);
175 | int range = year - MAX_YEAR_RANGE;
176 | for (String character : toChars(string)) {
177 | if (!character.matches(NUMBER)) {
178 | builder.append(character);
179 | }
180 | }
181 | return builder.toString() + randomInRange(range, year);
182 | }
183 |
184 | /**
185 | * Clear any underscores from the string.
186 | * @param string The string to modify.
187 | * @return The string without any underscores.
188 | */
189 | private String clearUnderscores(String string) {
190 | StringBuilder builder = new StringBuilder();
191 | for (String character : toChars(string)) {
192 | if (!character.matches(UNDERSCORE)) {
193 | builder.append(character);
194 | }
195 | }
196 | return builder.toString();
197 | }
198 |
199 | /**
200 | * Reduce the amount of underscores in the string.
201 | * @param string The string to modify.
202 | * @return The new string.
203 | */
204 | private String reduceUnderscores(String string) {
205 | int count = 0;
206 | for (String character : toChars(string)) {
207 | if (character.matches(UNDERSCORE)) {
208 | count++;
209 | }
210 | }
211 | if (count > MAX_UNDERSCORES) {
212 | return addStrategicalUnderscores(clearUnderscores(string));
213 | }
214 | return string;
215 | }
216 |
217 | /**
218 | * Add underscores to the string at random indexes.
219 | * @param string The string to modify.
220 | * @return The new string with random indexed underscores.
221 | */
222 | private String addRandomUnderscores(String string) {
223 | string = clearUnderscores(string);
224 | for (int c = 1; c <= random(MAX_UNDERSCORES - 1) + 1; c++) {
225 | StringBuilder builder = new StringBuilder();
226 | String[] characters = toChars(string);
227 | int index = randomIndex(string);
228 | for (int i = 0; i < string.length(); i++) {
229 | if (i == index) {
230 | builder = randomBoolean() ? builder.append(characters[i] + UNDERSCORE) : builder.append(UNDERSCORE + characters[i]);
231 | } else {
232 | builder.append(characters[i]);
233 | }
234 | }
235 | string = builder.toString();
236 | }
237 | return reduceUnderscores(string);
238 | }
239 |
240 | /**
241 | * Add underscores at stragical locations. (ie. before/after words)
242 | * @param string The string to modify.
243 | * @return The new string with strategic underscores.
244 | */
245 | private String addStrategicalUnderscores(String string) {
246 | string = clearUnderscores(string);
247 | StringBuilder builder = new StringBuilder();
248 | if (countChars(string, UPPERCASE_LETTER) >= 2) {
249 | /** Arbitrary assumption that each word starts with an uppercase letter. */
250 | for (String word : string.split("(?=\\p{Upper})")) {
251 | if (randomBoolean()) {
252 | builder.append(word + UNDERSCORE);
253 | } else {
254 | builder.append(word);
255 | }
256 | }
257 | return reduceUnderscores(builder.toString());
258 | } else {
259 | /** Failsafe if no capital letters. */
260 | return addRandomUnderscores(string);
261 | }
262 | }
263 |
264 | /**
265 | * Add a underscore either directly in the front, or in the back of a string.
266 | * @param string The string to modify.
267 | * @return The new string with the lazy underscore.
268 | */
269 | private String addLazyUnderscore(String string) {
270 | string = clearUnderscores(string);
271 | if (randomBoolean()) {
272 | return reduceUnderscores(string + UNDERSCORE);
273 | } else {
274 | return reduceUnderscores(UNDERSCORE + string);
275 | }
276 | }
277 |
278 | /**
279 | * Add common phoenetic replacements to the string.
280 | * @param string The string to modify.
281 | * @return The new string with phoenetic replacements.
282 | */
283 | private String addPhoneticReplacements(String string) {
284 | Map map = new HashMap() {
285 | private static final long serialVersionUID = 3061300641616454089L;
286 | {
287 | put("0","O"); put("S","Z"); put("1","I"); put("3","E");
288 | }};
289 | int count = 0;
290 | StringBuilder builder = new StringBuilder();
291 | for (String character : toChars(string)) {
292 | boolean upperCase = randomBoolean();
293 | if (map.containsKey(character)) {
294 | if (count <= MAX_PHOENETIC_REPLACEMENTS) {
295 | if (upperCase) {
296 | builder.append(map.get(character).toUpperCase());
297 | } else {
298 | builder.append(map.get(character).toLowerCase());
299 | }
300 | count++;
301 | }
302 | } else if (map.containsValue(character)) {
303 | for (Map.Entry entry : map.entrySet()) {
304 | if (entry.getValue().equals(character)) {
305 | if (count <= MAX_PHOENETIC_REPLACEMENTS) {
306 | if (upperCase) {
307 | builder.append(entry.getKey().toUpperCase());
308 | } else {
309 | builder.append(entry.getKey().toLowerCase());
310 | }
311 | count++;
312 | }
313 | }
314 | }
315 | } else {
316 | builder.append(character);
317 | }
318 | }
319 | return builder.toString();
320 | }
321 |
322 | /**
323 | * Reduce the amount of capitalization in the string.
324 | * @param string The string to modify.
325 | * @return The new string.
326 | */
327 | private String reduceCapitalization(String string) {
328 | int count = 0;
329 | for (String character : toChars(string)) {
330 | if (character.matches(UPPERCASE_LETTER)) {
331 | count++;
332 | }
333 | }
334 | if (count > MAX_CAPITALIZED) {
335 | return addLogicalCapitalization(string.toLowerCase());
336 | }
337 | return string;
338 | }
339 |
340 | /**
341 | * Add random indexed capitalization to the string.
342 | * @param string The string to modify.
343 | * @return The new string.
344 | */
345 | private String addRandomCapitalization(String string) {
346 | int amount = random(MAX_CAPITALIZED - 1) + 1;
347 | StringBuilder builder = new StringBuilder();
348 | String[] characters = toChars(string);
349 | for (int i = 1; i <= amount; i++) {
350 | int index = random(string.length() - 1);
351 | characters[index] = characters[index].toUpperCase();
352 | }
353 | for (String character : characters) {
354 | builder.append(character);
355 | }
356 | return reduceCapitalization(builder.toString());
357 | }
358 |
359 | /**
360 | * Add semi-random capitalization to the string.
361 | * @param string The string to modify.
362 | * @return The new string.
363 | */
364 | private String addLogicalCapitalization(String string) {
365 | StringBuilder builder = new StringBuilder();
366 | String[] characters = toChars(string);
367 | boolean addThird = randomBoolean();
368 | int firstIndex = 0;
369 | int secondIndex = randomIndex(string);
370 | int thirdIndex = randomInRange(secondIndex, string.length() - 1);
371 | for (int i = 0; i < string.length(); i++) {
372 | if (i == firstIndex || i == secondIndex) {
373 | builder.append(characters[i].toUpperCase());
374 | } else if (addThird && i == thirdIndex) {
375 | builder.append(characters[i].toUpperCase());
376 | } else {
377 | builder.append(characters[i]);
378 | }
379 | }
380 | return reduceCapitalization(builder.toString());
381 | }
382 |
383 | /**
384 | * Verify that a username is not registered in Mojang's database.
385 | * @param name The username to verify.
386 | * @return If the username is unique and not taken.
387 | */
388 | private boolean doesAlreadyExist(String name) {
389 | try {
390 | BufferedReader in = new BufferedReader(new InputStreamReader(new URL(MOJANG_URL + name).openStream()));
391 | String data = in.readLine();
392 | in.close();
393 | return data == null ? false : true;
394 | } catch (MalformedURLException e) {
395 | e.printStackTrace();
396 | return true;
397 | } catch (IOException e) {
398 | e.printStackTrace();
399 | return true;
400 | }
401 | }
402 |
403 | /**
404 | * Return a random integer from 0-9.
405 | * @return The random integer.
406 | */
407 | private int random() {
408 | return new Random().nextInt(10);
409 | }
410 |
411 |
412 | /**
413 | * Return a random integer given a range starting from 0.
414 | * @param range The range of the random query.
415 | * @return The random integer.
416 | */
417 | private int random(int range) {
418 | if (range != 0) {
419 | return new Random().nextInt(range);
420 | }
421 | else {
422 | return 0;
423 | }
424 | }
425 |
426 | /**
427 | * Return a random boolean.
428 | * @return The random boolean.
429 | */
430 | private boolean randomBoolean() {
431 | return new Random().nextBoolean();
432 | }
433 |
434 | /**
435 | * Get a random index given a string.
436 | * @param string The string to get the indexes from.
437 | * @return An integer index.
438 | */
439 | private int randomIndex(String string) {
440 | return random(string.length());
441 | }
442 |
443 | /**
444 | * Get a random number within a range.
445 | * @param start The start of the range.
446 | * @param end The end of the range.
447 | * @return An integer index.
448 | */
449 | private int randomInRange(int start, int end) {
450 | return new Random().nextInt(end - start) + start;
451 | }
452 |
453 | /**
454 | * Break down a string into its characters.
455 | * @param string The string to break up.
456 | * @return An array of characters.
457 | */
458 | private String[] toChars(String string) {
459 | return string.split("");
460 | }
461 |
462 | /**
463 | * Count the number of characters in a string that match a regex.
464 | * @param string The string to query.
465 | * @param regex The regex to match.
466 | * @return The amount of matches.
467 | */
468 | private int countChars(String string, String regex) {
469 | int count = 0;
470 | for (String character : toChars(string)) {
471 | if (character.matches(regex)) {
472 | count++;
473 | }
474 | }
475 | return count;
476 | }
477 |
478 | /**
479 | * Get a random letter from the alphabet.
480 | * @return A random character from the alphabet.
481 | */
482 | public char randomLetter() {
483 | String alphabet = "abcdefghijklmnopqrstuvwxyz";
484 | int index = randomIndex(alphabet);
485 | return alphabet.charAt(index);
486 | }
487 |
488 | }
489 |
--------------------------------------------------------------------------------
/src/main/java/me/electroid/nicknamer/NicknamePlugin.java:
--------------------------------------------------------------------------------
1 | package me.electroid.nicknamer;
2 |
3 | import java.io.IOException;
4 |
5 | import org.bukkit.Bukkit;
6 | import org.bukkit.ChatColor;
7 | import org.bukkit.Skin;
8 | import org.bukkit.command.Command;
9 | import org.bukkit.command.CommandSender;
10 | import org.bukkit.entity.Player;
11 | import org.bukkit.plugin.java.JavaPlugin;
12 | import org.jsoup.Jsoup;
13 | import org.jsoup.nodes.Document;
14 | import java.util.Random;
15 |
16 | /**
17 | * A basic random identity generating plugin.
18 | * @author ElectroidFilms
19 | */
20 | public class NicknamePlugin extends JavaPlugin {
21 |
22 | private static final int MIN_USERNAME_LENGTH = 4;
23 | private static final int[] OCN_PUNISHMENT_RANGE = {1000, 10000};
24 | private static final String OCN_PUNISHMENT_PAGE = "http://oc.tc/punishments?page=";
25 |
26 | @Override
27 | public void onEnable() {}
28 |
29 | @Override
30 | public void onDisable() {
31 | Bukkit.getScheduler().cancelTasks(this);
32 | }
33 |
34 | /**
35 | * A async task to generate and apply the fake skin and username (Never run on main thread).
36 | */
37 | public class NicknameTask implements Runnable {
38 |
39 | private Player player;
40 |
41 | private NicknameTask(Player player) {
42 | this.player = player;
43 | }
44 |
45 | @Override
46 | public void run() {
47 | MinecraftNameGenerator gen = new MinecraftNameGenerator(MIN_USERNAME_LENGTH);
48 | String name = gen.generate(getSeedFromOcn());
49 | Skin fakeSkin = getRandomSkin();
50 | for (Player p : Bukkit.getOnlinePlayers()) {
51 | if (!p.equals(player) && !p.hasPermission("nickname.see") && !p.isOp()) {
52 | player.setFakeNameAndSkin(p, name, fakeSkin);
53 | }
54 | }
55 | player.sendMessage(ChatColor.GREEN + "Changed nickname to.. " + ChatColor.WHITE + ChatColor.ITALIC + name);
56 | }
57 | }
58 |
59 | public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
60 | if (cmd.getName().equalsIgnoreCase("nick")) {
61 | if (sender.hasPermission("nickname.use")) {
62 | if (args.length == 1) {
63 | sender.sendMessage("Attempting to generate random nickname and skin..");
64 | Bukkit.getScheduler().runTaskAsynchronously(this, new NicknameTask((Player) sender));
65 | } else if (args.length == 2) {
66 | Player player = Bukkit.getPlayerExact(args[1], sender);
67 | if (player != null) {
68 | sender.sendMessage("Attempting to generate random nickname and skin for " + player.getDisplayName(sender) + "..");
69 | Bukkit.getScheduler().runTaskAsynchronously(this, new NicknameTask(player));
70 | } else {
71 | sender.sendMessage(ChatColor.RED + "Could not find the specified player to nick");
72 | }
73 | } else {
74 | sender.sendMessage(ChatColor.RED + "Invalid formatting. /nick (player)");
75 | }
76 | } else {
77 | sender.sendMessage(ChatColor.RED + "You do not have permission to use /nick");
78 | }
79 | } else if (cmd.getName().equalsIgnoreCase("clearnick")) {
80 | if (args.length == 1) {
81 | ((Player) sender).clearFakeNamesAndSkins();
82 | sender.sendMessage(ChatColor.GREEN + "Your nickname and fake skin have been cleared.");
83 | } else if (args.length == 2) {
84 | if (sender.hasPermission("nickname.clear.others")) {
85 | Player player = Bukkit.getPlayerExact(args[1], sender);
86 | if (player != null) {
87 | player.clearFakeNamesAndSkins();
88 | sender.sendMessage(ChatColor.GREEN + player.getDisplayName(sender) + "'s nickname and fake skin have been cleared.");
89 | } else {
90 | sender.sendMessage(ChatColor.RED + "Could not find the specified player to clear their nick");
91 | }
92 | } else {
93 | sender.sendMessage(ChatColor.RED + "You do not have permission to use /clearnick");
94 | }
95 | } else {
96 | sender.sendMessage(ChatColor.RED + "Invalid formatting. /clearnick (player)");
97 | }
98 | }
99 | return true;
100 | }
101 |
102 | /**
103 | * Get a banned user from Overcast Network's punishments page.
104 | * @return The banned username.
105 | */
106 | private String getSeedFromOcn() {
107 | /** Backup username in the event of any errors. */
108 | String seed = "_creeperNoob";
109 | try {
110 | Document doc = Jsoup.connect(OCN_PUNISHMENT_PAGE + randomWithinRange(OCN_PUNISHMENT_RANGE[0], OCN_PUNISHMENT_RANGE[1])).get();
111 | seed = doc.select("tbody").first().select("td").get(1).select("a").attr("href");
112 | } catch (IOException e) {
113 | e.printStackTrace();
114 | }
115 | return seed.substring(1, seed.length());
116 | }
117 |
118 | /**
119 | * Get a random skin from any players online.
120 | * @return The random skin.
121 | */
122 | private Skin getRandomSkin() {
123 | Skin skin = Skin.EMPTY;
124 | int index = random(Bukkit.getOnlinePlayers().size());
125 | int count = 0;
126 | for (Player p : Bukkit.getOnlinePlayers()) {
127 | if (index == count) {
128 | skin = p.getRealSkin();
129 | }
130 | count++;
131 | }
132 | return skin;
133 | }
134 |
135 | private int random(int range) {
136 | if (range != 0)
137 | return new Random().nextInt(range);
138 | return 0;
139 | }
140 |
141 | private int randomWithinRange(int start, int end) {
142 | return new Random().nextInt(end - start) + start;
143 | }
144 |
145 | }
146 |
--------------------------------------------------------------------------------
/src/main/resources/plugin.yml:
--------------------------------------------------------------------------------
1 | name: Nicknamer
2 | version: 0.2
3 | main: me.electroid.nicknamer.NicknamePlugin
4 | author: ElectroidFilms
5 | description: A plugin to test the functionality of randomly generating nicknames.
6 | commands:
7 | nick:
8 | description: Give a player a random nickname and skin.
9 | usage: /nick (player)
10 | clearnick:
11 | description: Clear a player's random nickname and skin.
12 | usage: /clearnick (player)
--------------------------------------------------------------------------------