blob: b38469b427858c496e352ee5906d5010561e6d76 (
plain)
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
|
package com.redstoner.bungeeBans.commands;
import com.mojang.api.profiles.Profile;
import com.redstoner.bungeeBans.BanManager;
import com.redstoner.bungeeBans.Util;
import com.redstoner.bungeeBans.json.PlayerBan;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.plugin.Command;
import java.io.IOException;
public class UnbanCommand extends Command {
private BanManager<PlayerBan> bm;
public UnbanCommand(BanManager<PlayerBan> bm) {
super("unban", "bungeebans.unban", "pardon");
this.bm = bm;
}
@Override
public void execute(CommandSender sender, String[] args) {
if (args.length != 1) {
sender.sendMessage(
new ComponentBuilder(ChatColor.RED + "Usage: ")
.append(ChatColor.AQUA + "/unban ")
.append(ChatColor.GOLD + "<username/uuid> ")
.create()
);
return;
}
String uuid;
String name;
if (Util.validateUUID(args[0])) {
uuid = args[0];
try {
Util.NameChange[] nameChanges = Util.findNameChangesByUUID(uuid);
if (nameChanges.length == 0) {
sender.sendMessage(new TextComponent(ChatColor.RED + "Invalid UUID!"));
return;
}
name = nameChanges[nameChanges.length - 1].name;
} catch (Util.MojangException e) {
sender.sendMessage(new TextComponent(ChatColor.RED + e.getMessage()));
return;
}
} else {
Profile[] profiles = Util.findProfilesByNames(args[0]);
if (profiles.length != 1) {
sender.sendMessage(new TextComponent(ChatColor.RED + "Invalid name!"));
return;
}
uuid = Util.dashUUID(profiles[0].getId());
name = profiles[0].getName();
}
PlayerBan ban = bm.getBan(uuid);
if (ban == null) {
sender.sendMessage(new TextComponent(ChatColor.RED + "That player is not banned!"));
return;
}
bm.removeBan(ban);
try {
bm.saveBans();
} catch (IOException e) {
sender.sendMessage(new TextComponent(ChatColor.RED + "Failed to save player bans to file! (nothing was changed)"));
e.printStackTrace();
bm.addBan(ban);
return;
}
sender.sendMessage(
new ComponentBuilder(ChatColor.GREEN + "Unbanned player ")
.append(ChatColor.AQUA + name)
.append(ChatColor.GREEN + " with uuid ")
.append(ChatColor.AQUA + uuid)
.create()
);
}
}
|