Skip to content
This repository was archived by the owner on Mar 8, 2024. It is now read-only.

Commit c49201b

Browse files
authored
Add files via upload
1 parent 09b6245 commit c49201b

12 files changed

+614
-0
lines changed

src/tax/cute/mcinfoplugin/ApiUrl.java

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package tax.cute.mcinfoplugin;
2+
3+
public class ApiUrl {
4+
public static final String MC_HEAD_SKIN = "https://crafatar.com/renders/head/";
5+
public static final String MC_BODY_SKIN = "https://crafatar.com/renders/body/";
6+
}

src/tax/cute/mcinfoplugin/MCInfo.java

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package tax.cute.mcinfoplugin;
2+
3+
import net.mamoe.mirai.contact.Group;
4+
import net.mamoe.mirai.message.data.ForwardMessageBuilder;
5+
import net.mamoe.mirai.message.data.Image;
6+
import net.mamoe.mirai.message.data.PlainText;
7+
import net.mamoe.mirai.message.data.SingleMessage;
8+
import net.mamoe.mirai.utils.ExternalResource;
9+
import tax.cute.minecraftinfoapi.PlayerInfo;
10+
import tax.cute.minecraftinfoapi.UUID;
11+
import top.mrxiaom.miraiutils.CommandModel;
12+
import top.mrxiaom.miraiutils.CommandSender;
13+
import top.mrxiaom.miraiutils.CommandSenderGroup;
14+
15+
import java.io.IOException;
16+
17+
public class MCInfo extends CommandModel {
18+
public MCInfo() {
19+
super("mcinfo");
20+
}
21+
22+
@Override
23+
public void onCommand(CommandSender sender, SingleMessage[] args) {
24+
if (sender instanceof CommandSenderGroup) {
25+
CommandSenderGroup senderGroup = (CommandSenderGroup) sender;
26+
Group group = senderGroup.getGroup();
27+
28+
if (args[0].contentToString().equalsIgnoreCase("/mcInfo")) {
29+
group.sendMessage("用法:/mcinfo [名称/UUID]");
30+
return;
31+
}
32+
33+
if (args[0].contentToString().isEmpty()) {
34+
group.sendMessage("请输入有效用户名");
35+
return;
36+
}
37+
try {
38+
sendMcInfo(group, args[0].contentToString());
39+
} catch (Exception e) {
40+
group.sendMessage("获取失败,请稍后重试");
41+
e.printStackTrace();
42+
}
43+
}
44+
}
45+
46+
private void sendMcInfo(Group group, String name) throws IOException {
47+
String id;
48+
if (name.replace("-", "").length() == 32) {
49+
id = name;
50+
} else {
51+
UUID uuid = UUID.getId(name);
52+
if (uuid == null) {
53+
group.sendMessage("无法找到这个用户");
54+
return;
55+
}
56+
id = uuid.getId();
57+
}
58+
59+
PlayerInfo info = PlayerInfo.getPlayerInfo(id);
60+
if (info == null) {
61+
group.sendMessage("查询失败");
62+
return;
63+
}
64+
String text =
65+
"==MC档案查询==" +
66+
"\n[ 用户名 ] " + info.getNowName() +
67+
"\n[ UUID ] " + id;
68+
69+
byte[] avatar_bytes = Util.getWebBytes(ApiUrl.MC_HEAD_SKIN + id);
70+
if (avatar_bytes == null) {
71+
group.sendMessage("查询失败");
72+
return;
73+
}
74+
75+
Image avatar = group.uploadImage(ExternalResource.create(avatar_bytes));
76+
group.sendMessage(avatar.plus(text));
77+
78+
ForwardMessageBuilder builder = new ForwardMessageBuilder(group);
79+
builder.add(group.getBot().getId(), group.getBot().getNick(), new PlainText("曾用名"));
80+
81+
for (int i = 0; i < info.getData().size(); i++) {
82+
String time;
83+
if (info.getData().get(i).getTimestamp() == -1) {
84+
time = "初始用户名";
85+
} else {
86+
time = info.getData().get(i).getTime();
87+
}
88+
builder.add(group.getBot().getId(), group.getBot().getNick(), new PlainText(
89+
"名称:" + info.getData().get(i).getName() +
90+
"\n修改时间:" + time
91+
));
92+
}
93+
94+
group.sendMessage(builder.build());
95+
}
96+
}

src/tax/cute/mcinfoplugin/MCSkin.java

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package tax.cute.mcinfoplugin;
2+
3+
import net.mamoe.mirai.contact.Group;
4+
import net.mamoe.mirai.message.data.Image;
5+
import net.mamoe.mirai.message.data.SingleMessage;
6+
import net.mamoe.mirai.utils.ExternalResource;
7+
import tax.cute.minecraftinfoapi.UUID;
8+
import top.mrxiaom.miraiutils.CommandModel;
9+
import top.mrxiaom.miraiutils.CommandSender;
10+
import top.mrxiaom.miraiutils.CommandSenderGroup;
11+
12+
import java.io.IOException;
13+
14+
public class MCSkin extends CommandModel {
15+
public MCSkin() {
16+
super("mcskin");
17+
}
18+
19+
@Override
20+
public void onCommand(CommandSender sender, SingleMessage[] args) {
21+
if (sender instanceof CommandSenderGroup) {
22+
CommandSenderGroup senderGroup = (CommandSenderGroup)sender;
23+
Group group = senderGroup.getGroup();
24+
25+
if (args[0].contentToString().equalsIgnoreCase("/mcskin")) {
26+
group.sendMessage("用法:/mcskin [名称/UUID]");
27+
return;
28+
}
29+
30+
if (args[0].contentToString().isEmpty()) {
31+
group.sendMessage("请输入有效用户名");
32+
return;
33+
}
34+
35+
try {
36+
send(group, args[0].contentToString());
37+
} catch (Exception e) {
38+
group.sendMessage("获取失败,请稍后重试");
39+
e.printStackTrace();
40+
}
41+
}
42+
}
43+
44+
private void send(Group group,String name) throws IOException {
45+
String id;
46+
if (name.replace("-", "").length() == 32) {
47+
id = name;
48+
} else {
49+
UUID uuid = UUID.getId(name);
50+
if (uuid == null) {
51+
group.sendMessage("无法找到这个用户");
52+
return;
53+
}
54+
id = uuid.getId();
55+
}
56+
57+
byte[] skin_bytes = Util.getWebBytes(ApiUrl.MC_BODY_SKIN + id);
58+
if (skin_bytes == null) {
59+
group.sendMessage("查询失败");
60+
return;
61+
}
62+
Image image = group.uploadImage(ExternalResource.create(skin_bytes));
63+
group.sendMessage(image);
64+
}
65+
}
+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package tax.cute.mcinfoplugin;
2+
3+
import net.mamoe.mirai.contact.Group;
4+
import net.mamoe.mirai.message.data.Image;
5+
import net.mamoe.mirai.message.data.SingleMessage;
6+
import net.mamoe.mirai.utils.ExternalResource;
7+
import tax.cute.minecraftinfoapi.Skin;
8+
import tax.cute.minecraftinfoapi.UUID;
9+
import top.mrxiaom.miraiutils.CommandModel;
10+
import top.mrxiaom.miraiutils.CommandSender;
11+
import top.mrxiaom.miraiutils.CommandSenderGroup;
12+
13+
import java.io.IOException;
14+
15+
public class MCSkinFile extends CommandModel {
16+
public MCSkinFile() {
17+
super("mcSkinFile");
18+
}
19+
20+
@Override
21+
public void onCommand(CommandSender sender, SingleMessage[] args) {
22+
if (args[0].contentToString().equalsIgnoreCase("/mcSkinFile")) return;
23+
if (sender instanceof CommandSenderGroup) {
24+
CommandSenderGroup senderGroup = (CommandSenderGroup) sender;
25+
Group group = senderGroup.getGroup();
26+
27+
if (args[0].contentToString().equalsIgnoreCase("/mcInfo")) {
28+
group.sendMessage("用法:/mcinfo [名称/UUID]");
29+
return;
30+
}
31+
32+
if (args[0].contentToString().isEmpty()) {
33+
group.sendMessage("请输入有效用户名");
34+
return;
35+
}
36+
37+
try {
38+
sendSkinFile(group, args[0].contentToString());
39+
} catch (Exception e) {
40+
group.sendMessage("获取失败,请稍后重试");
41+
}
42+
}
43+
}
44+
45+
private void sendSkinFile(Group group, String name) throws IOException {
46+
String id;
47+
if (name.replace("-", "").length() == 32) {
48+
id = name;
49+
} else {
50+
UUID uuid = UUID.getId(name);
51+
if (uuid == null) {
52+
group.sendMessage("无法找到这个用户");
53+
return;
54+
}
55+
id = uuid.getId();
56+
}
57+
if (id == null) {
58+
group.sendMessage("无法找到这个用户");
59+
return;
60+
}
61+
62+
byte[] bytes = Skin.getSkin(id).getSkinBytes();
63+
Image image = group.uploadImage(ExternalResource.create(bytes));
64+
group.sendMessage(image);
65+
}
66+
}

src/tax/cute/mcinfoplugin/Plugin.java

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package tax.cute.mcinfoplugin;
2+
3+
import net.mamoe.mirai.console.extension.PluginComponentStorage;
4+
import net.mamoe.mirai.console.plugin.jvm.JavaPlugin;
5+
import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescriptionBuilder;
6+
import net.mamoe.mirai.event.GlobalEventChannel;
7+
import top.mrxiaom.miraiutils.CommandListener;
8+
9+
public class Plugin extends JavaPlugin {
10+
MCSkin mcSkin;
11+
MCInfo mcInfo;
12+
MCSkinFile mcSkinFile;
13+
14+
public Plugin() {
15+
super(new JvmPluginDescriptionBuilder(
16+
"tax.cute.mcinfoplugin", // id
17+
"1.0.0" // version
18+
)
19+
.name("MCInfoPlugin")
20+
.author("CuteStar")
21+
// .info("...")
22+
.build()
23+
);
24+
}
25+
26+
@Override
27+
public void onLoad(PluginComponentStorage pcs) {
28+
getLogger().info("MCInfoPluginLoading");
29+
getLogger().info("Author:CuteStar");
30+
getLogger().info("Github: https://github.com/MX233/MCInfoPlugin");
31+
}
32+
33+
private void register() {
34+
mcSkin = new MCSkin();
35+
mcInfo = new MCInfo();
36+
mcSkinFile = new MCSkinFile();
37+
}
38+
39+
@Override
40+
public void onEnable() {
41+
register();
42+
CommandListener listener = new CommandListener("/");
43+
listener.registerCommand(mcSkin);
44+
listener.registerCommand(mcInfo);
45+
listener.registerCommand(mcSkinFile);
46+
47+
GlobalEventChannel.INSTANCE.registerListenerHost(listener);
48+
}
49+
}

src/tax/cute/mcinfoplugin/Util.java

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package tax.cute.mcinfoplugin;
2+
3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
import java.net.HttpURLConnection;
6+
import java.net.URL;
7+
8+
public class Util {
9+
public static byte[] getWebBytes(String url) throws IOException {
10+
URL u = new URL(url);
11+
HttpURLConnection http = (HttpURLConnection)u.openConnection();
12+
if(http.getResponseCode() != 200) return null;
13+
InputStream in = http.getInputStream();
14+
byte[] bytes = in.readAllBytes();
15+
in.close();
16+
return bytes;
17+
}
18+
}

0 commit comments

Comments
 (0)