最近和yuuk写了一个匿名插件, 其中写了一个ID生成器

效果出乎意料的好a,于是保存下来,以后可能经常用到

欢迎大家参考a,标明出处就行

Generate.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
package org.encinet.nick.until;

import java.io.File;
import java.io.IOException;
import java.nio.file.CopyOption;
import java.nio.file.Files;
import java.util.List;
import java.util.Scanner;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ThreadLocalRandom;
import org.encinet.nick.Nick;

/**
* ID生成器
*/
public class Generate {
static List<String> worlds = new CopyOnWriteArrayList();
static int worldsLength;

/**
* 初始化 词典加载
* 如果插件文件夹有直接获取插件文件夹中的词典
* 如果没有则从插件中提取放到插件文件夹
*/
public Generate() {
File dataFolder = Nick.plugin.getDataFolder();
File worldsFile = new File(dataFolder, "worlds.txt");
if (!worldsFile.exists()) {
dataFolder.mkdir();
try {
Files.copy(Nick.plugin.getResourceAsStream("worlds.txt"), dataFolder.toPath(), new CopyOption[0]);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
try {
Scanner scanner = new Scanner(worldsFile);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (!line.startsWith("#") && !"".equals(line.trim())) {
worlds.add(line);
}
}
scanner.close();
if (worlds.size() == 0) {
throw new RuntimeException();
}
worldsLength = worlds.size();
} catch (IOException e2) {
throw new RuntimeException(e2);
}
}

/**
* @return 随机生成的ID
*/
public String getName() {
StringBuilder sb = new StringBuilder();
int circulation = ThreadLocalRandom.current().nextInt(1, 4);
for (int i = 0; i < circulation; i++) {
if (i == 0) {
sb.append(randomWord());
} else {
sb.append(ThreadLocalRandom.current().nextBoolean() ? randomWord() : Integer.valueOf(randomNum()));
}
}
return sb.toString();
}

/**
* @return 随机从字典中获取一个词
*/
public String randomWord() {
return worlds.get(ThreadLocalRandom.current().nextInt(worldsLength));
}

/**
* @return 随机从 `0~9` 选择一个数
*/
public int randomNum() {
return ThreadLocalRandom.current().nextInt(10);
}
}
词典文件(参考)
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
# 一行一个
# 建议纯英文
# 建议首字母大写
Forever
Java
Flyer
Script
Night
Vision
Cheat
QwQ
AwA
Soga
Baka
Cxk
IDK
Thx
Plz
Glorious
Soulmate
Shine
Woc
Bili
Vape
Wurst
Loser
Helper
Times
Finish
Pretext
Delete
Cute
Baby
Trauma
Submerge
Shine
Stars
Review
Active
Sandm
Tenderness
Tears
Absurd
Dirge
Conqueror
Coke
Fairy
Britney
Pioneer
Deepsea
Redemption
False
Hermes
Elaborate
Liquor
Deep
Hollow
Leave
Daisy
Naive
God
Poison
Deception
Pass
Monstar
Onlooker
Archive
Aholic
Deceive
Jam
Little
Allure
Starry
ERoslon
Moonlight
Lonely
Freedom
Deserted
Dream
Warm
Luv
Bubble
Koi
Precipitation
Run
Lolita
Pearl
Pamper
Guts
Hanabi
Beginner
Nefertari
Curtain
Hushnow
Midnight
Nature
Promise
Vincent
Cleanliness
Imerance
Destin
Lemon
Forever
Memorial
Authority
Ferry
Emotional
Insane
Despais
Aurora
Figure
Memorial
Miss
Cloud
Lntano
Gentle
Dark
Pure
Bombasti
Liminous
Ash
Lcberg
Unicorn
Krismile
Unicorn
Perpetual
Morning
Noon
Moon
Dinner
Sunny