Skip to content

Commit e350d4f

Browse files
fix(punishment): fix commands, add /unmute, async Velocity login check
- BanCommand: transferToLimbo moved into success callback, valueOf try/catch - MuteCommand: valueOf try/catch for invalid reason input - UnBanCommand/UnMuteCommand: pass punishment type in unpunish request - All commands use HypixelPlayer directly (no console path) - SkyBlockVelocity: login punishment check is now async via EventTask - SkyBlockVelocity: checks BAN and MUTE in parallel - ActionPlayerMute: passes MUTE type to service query - ListenerPlayerPunished: parses tags from pub/sub JSON, uses getReasonString()
1 parent c48e755 commit e350d4f

7 files changed

Lines changed: 181 additions & 79 deletions

File tree

type.generic/src/main/java/net/swofty/type/generic/command/commands/BanCommand.java

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package net.swofty.type.generic.command.commands;
22

33
import net.kyori.adventure.text.Component;
4-
import net.minestom.server.command.CommandSender;
54
import net.minestom.server.command.builder.arguments.*;
6-
import net.minestom.server.entity.Player;
7-
import net.minestom.server.utils.mojang.MojangUtils;
85
import net.minestom.server.command.builder.suggestion.SuggestionEntry;
96
import net.swofty.commons.ServiceType;
107
import net.swofty.commons.StringUtility;
@@ -17,6 +14,7 @@
1714
import net.swofty.proxyapi.ProxyService;
1815
import net.swofty.type.generic.command.CommandParameters;
1916
import net.swofty.type.generic.command.HypixelCommand;
17+
import net.swofty.type.generic.user.HypixelPlayer;
2018
import net.swofty.type.generic.user.categories.Rank;
2119
import org.jetbrains.annotations.Nullable;
2220

@@ -32,7 +30,7 @@
3230
permission = Rank.STAFF,
3331
description = "Ban a player from the server.",
3432
usage = "/ban <player> [duration] <reason>",
35-
allowsConsole = true
33+
allowsConsole = false
3634
)
3735
public class BanCommand extends HypixelCommand {
3836

@@ -52,47 +50,72 @@ public void registerUsage(MinestomCommand command) {
5250
});
5351

5452
command.addSyntax((sender, context) -> {
53+
HypixelPlayer player = (HypixelPlayer) sender;
5554
String playerName = context.get(playerArg);
5655
String duration = context.get(durationArg);
57-
BanType type = BanType.valueOf(context.get(reasonArg));
56+
57+
BanType type;
58+
try {
59+
type = BanType.valueOf(context.get(reasonArg));
60+
} catch (IllegalArgumentException e) {
61+
player.sendMessage("§cInvalid ban reason. Use tab-completion to see valid options.");
62+
return;
63+
}
5864

5965
CompletableFuture.runAsync(() -> {
6066
try {
61-
UUID targetUuid = MojangUtils.getUUID(playerName);
67+
UUID targetUuid = net.minestom.server.utils.mojang.MojangUtils.getUUID(playerName);
6268
long actualTime = StringUtility.parseDuration(duration);
6369
long expiryTime = System.currentTimeMillis() + actualTime;
64-
banPlayer(sender, targetUuid, type, (sender instanceof Player p ? p.getUuid() : new UUID(0, 0)), actualTime, expiryTime, playerName, null);
70+
banPlayer(player, targetUuid, type, player.getUuid(), actualTime, expiryTime, playerName, null);
6571
} catch (IOException e) {
66-
sender.sendMessage("§cCould not find player: " + playerName);
72+
player.sendMessage("§cCould not find player: " + playerName);
6773
}
6874
});
6975
}, playerArg, durationArg, reasonArg);
7076

7177
command.addSyntax((sender, context) -> {
78+
HypixelPlayer player = (HypixelPlayer) sender;
7279
String playerName = context.get(playerArg);
73-
BanType reason = BanType.valueOf(context.get(reasonArg));
80+
81+
BanType reason;
82+
try {
83+
reason = BanType.valueOf(context.get(reasonArg));
84+
} catch (IllegalArgumentException e) {
85+
player.sendMessage("§cInvalid ban reason. Use tab-completion to see valid options.");
86+
return;
87+
}
7488

7589
CompletableFuture.runAsync(() -> {
7690
try {
77-
banPlayer(sender, MojangUtils.getUUID(playerName), reason,
78-
(sender instanceof Player p ? p.getUuid() : new UUID(0, 0)), 0, -1, playerName, null);
91+
banPlayer(player, net.minestom.server.utils.mojang.MojangUtils.getUUID(playerName), reason,
92+
player.getUuid(), 0, -1, playerName, null);
7993
} catch (IOException e) {
80-
sender.sendMessage("§cCould not find player: " + playerName);
94+
player.sendMessage("§cCould not find player: " + playerName);
8195
}
8296
});
8397
}, playerArg, reasonArg);
8498

8599
command.addSyntax((sender, context) -> {
100+
HypixelPlayer player = (HypixelPlayer) sender;
86101
String playerName = context.get(playerArg);
87-
BanType reason = BanType.valueOf(context.get(reasonArg));
102+
103+
BanType reason;
104+
try {
105+
reason = BanType.valueOf(context.get(reasonArg));
106+
} catch (IllegalArgumentException e) {
107+
player.sendMessage("§cInvalid ban reason. Use tab-completion to see valid options.");
108+
return;
109+
}
110+
88111
List<PunishmentTag> tags = parseTags(List.of(context.get(extraArg)));
89112

90113
CompletableFuture.runAsync(() -> {
91114
try {
92-
banPlayer(sender, MojangUtils.getUUID(playerName), reason,
93-
(sender instanceof Player p ? p.getUuid() : new UUID(0, 0)), 0, -1, playerName, tags);
115+
banPlayer(player, net.minestom.server.utils.mojang.MojangUtils.getUUID(playerName), reason,
116+
player.getUuid(), 0, -1, playerName, tags);
94117
} catch (IOException e) {
95-
sender.sendMessage("§cCould not find player: " + playerName);
118+
player.sendMessage("§cCould not find player: " + playerName);
96119
}
97120
});
98121
}, playerArg, reasonArg, extraArg);
@@ -114,7 +137,7 @@ private List<PunishmentTag> parseTags(List<String> rawTags) {
114137
return tags;
115138
}
116139

117-
private void banPlayer(CommandSender sender, UUID targetUuid, BanType type, UUID senderUuid,
140+
private void banPlayer(HypixelPlayer sender, UUID targetUuid, BanType type, UUID senderUuid,
118141
long actualTime, long expiryTime, String playerName, @Nullable List<PunishmentTag> tags) {
119142
ProxyService punishmentService = new ProxyService(ServiceType.PUNISHMENT);
120143
PunishmentReason reason = new PunishmentReason(type);
@@ -128,11 +151,10 @@ private void banPlayer(CommandSender sender, UUID targetUuid, BanType type, UUID
128151
actualTime > 0 ? expiryTime : -1
129152
);
130153

131-
new ProxyPlayer(targetUuid).transferToLimbo();
132-
133154
punishmentService.handleRequest(message).thenAccept(result -> {
134155
if (result instanceof PunishPlayerProtocolObject.PunishPlayerResponse response) {
135156
if (response.success()) {
157+
new ProxyPlayer(targetUuid).transferToLimbo();
136158
sender.sendMessage("§aSuccessfully banned player §e" + playerName + "§a. §8Punishment ID: §7" + response.punishmentId());
137159
} else if (response.errorCode() == PunishPlayerProtocolObject.ErrorCode.ALREADY_PUNISHED) {
138160
sender.sendMessage("§cThis player is already banned. Use the tag -O to overwrite. Punishment ID: §7" + response.errorMessage());

type.generic/src/main/java/net/swofty/type/generic/command/commands/MuteCommand.java

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package net.swofty.type.generic.command.commands;
22

33
import net.kyori.adventure.text.Component;
4-
import net.minestom.server.command.CommandSender;
54
import net.minestom.server.command.builder.arguments.Argument;
6-
import net.minestom.server.entity.Player;
7-
import net.minestom.server.utils.mojang.MojangUtils;
85
import net.minestom.server.command.builder.arguments.ArgumentString;
96
import net.minestom.server.command.builder.arguments.ArgumentType;
107
import net.minestom.server.command.builder.suggestion.SuggestionEntry;
@@ -17,6 +14,7 @@
1714
import net.swofty.proxyapi.ProxyService;
1815
import net.swofty.type.generic.command.CommandParameters;
1916
import net.swofty.type.generic.command.HypixelCommand;
17+
import net.swofty.type.generic.user.HypixelPlayer;
2018
import net.swofty.type.generic.user.categories.Rank;
2119

2220
import java.io.IOException;
@@ -30,7 +28,7 @@
3028
permission = Rank.STAFF,
3129
description = "Mute a player from the server.",
3230
usage = "/mute <player> [duration] <reason>",
33-
allowsConsole = true
31+
allowsConsole = false
3432
)
3533
public class MuteCommand extends HypixelCommand {
3634

@@ -45,38 +43,54 @@ public void registerUsage(MinestomCommand command) {
4543
});
4644

4745
command.addSyntax((sender, context) -> {
46+
HypixelPlayer player = (HypixelPlayer) sender;
4847
String playerName = context.get(playerArg);
4948
String duration = context.get(durationArg);
50-
MuteType type = MuteType.valueOf(context.get(reasonArg));
49+
50+
MuteType type;
51+
try {
52+
type = MuteType.valueOf(context.get(reasonArg));
53+
} catch (IllegalArgumentException e) {
54+
player.sendMessage("§cInvalid mute reason. Use tab-completion to see valid options.");
55+
return;
56+
}
5157

5258
CompletableFuture.runAsync(() -> {
5359
try {
54-
UUID targetUuid = MojangUtils.getUUID(playerName);
60+
UUID targetUuid = net.minestom.server.utils.mojang.MojangUtils.getUUID(playerName);
5561
long actualTime = StringUtility.parseDuration(duration);
5662
long expiryTime = System.currentTimeMillis() + actualTime;
57-
mutePlayer(sender, targetUuid, type, (sender instanceof Player p ? p.getUuid() : new UUID(0, 0)), actualTime, expiryTime, playerName);
63+
mutePlayer(player, targetUuid, type, player.getUuid(), actualTime, expiryTime, playerName);
5864
} catch (IOException e) {
59-
sender.sendMessage("§cCould not find player: " + playerName);
65+
player.sendMessage("§cCould not find player: " + playerName);
6066
}
6167
});
6268
}, playerArg, durationArg, reasonArg);
6369

6470
command.addSyntax((sender, context) -> {
71+
HypixelPlayer player = (HypixelPlayer) sender;
6572
String playerName = context.get(playerArg);
66-
MuteType reason = MuteType.valueOf(context.get(reasonArg));
73+
74+
MuteType reason;
75+
try {
76+
reason = MuteType.valueOf(context.get(reasonArg));
77+
} catch (IllegalArgumentException e) {
78+
player.sendMessage("§cInvalid mute reason. Use tab-completion to see valid options.");
79+
return;
80+
}
6781

6882
CompletableFuture.runAsync(() -> {
6983
try {
70-
mutePlayer(sender, MojangUtils.getUUID(playerName), reason,
71-
(sender instanceof Player p ? p.getUuid() : new UUID(0, 0)), 0, -1, playerName);
84+
mutePlayer(player, net.minestom.server.utils.mojang.MojangUtils.getUUID(playerName), reason,
85+
player.getUuid(), 0, -1, playerName);
7286
} catch (IOException e) {
73-
sender.sendMessage("§cCould not find player: " + playerName);
87+
player.sendMessage("§cCould not find player: " + playerName);
7488
}
7589
});
7690
}, playerArg, reasonArg);
7791
}
7892

79-
private void mutePlayer(CommandSender sender, UUID targetUuid, MuteType type, UUID senderUuid,
93+
private void mutePlayer(HypixelPlayer sender, UUID targetUuid, MuteType type, UUID senderUuid,
8094
long actualTime, long expiryTime, String playerName) {
8195
ProxyService punishmentService = new ProxyService(ServiceType.PUNISHMENT);
8296
PunishmentReason reason = new PunishmentReason(type);
@@ -94,7 +108,7 @@ private void mutePlayer(CommandSender sender, UUID targetUuid, MuteType type, UU
94108
if (response.success()) {
95109
sender.sendMessage("§aSuccessfully muted player §e" + playerName + "§a. §8Punishment ID: §7" + response.punishmentId());
96110
} else if (response.errorCode() == PunishPlayerProtocolObject.ErrorCode.ALREADY_PUNISHED) {
97-
sender.sendMessage("§cThis player already has an active punishment. Punishment ID: §7" + response.errorMessage());
111+
sender.sendMessage("§cThis player already has an active mute. Punishment ID: §7" + response.errorMessage());
98112
} else {
99113
sender.sendMessage("§cFailed to mute player: " + response.errorMessage());
100114
}

type.generic/src/main/java/net/swofty/type/generic/command/commands/UnBanCommand.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package net.swofty.type.generic.command.commands;
22

33
import net.minestom.server.command.builder.arguments.ArgumentType;
4-
import net.minestom.server.entity.Player;
54
import net.minestom.server.utils.mojang.MojangUtils;
65
import net.swofty.commons.ServiceType;
76
import net.swofty.commons.protocol.objects.punishment.UnpunishPlayerProtocolObject;
7+
import net.swofty.commons.punishment.PunishmentType;
88
import net.swofty.proxyapi.ProxyService;
99
import net.swofty.type.generic.command.CommandParameters;
1010
import net.swofty.type.generic.command.HypixelCommand;
11+
import net.swofty.type.generic.user.HypixelPlayer;
1112
import net.swofty.type.generic.user.categories.Rank;
1213

1314
import java.io.IOException;
14-
import java.util.UUID;
1515
import java.util.concurrent.CompletableFuture;
1616
import java.util.concurrent.TimeUnit;
1717

@@ -20,7 +20,7 @@
2020
usage = "/unban <player>",
2121
aliases = "unban pardon unbanip pardonip",
2222
permission = Rank.STAFF,
23-
allowsConsole = true
23+
allowsConsole = false
2424
)
2525
public class UnBanCommand extends HypixelCommand {
2626

@@ -29,30 +29,31 @@ public void registerUsage(MinestomCommand command) {
2929
var argument = ArgumentType.String("player");
3030

3131
command.addSyntax((sender, context) -> {
32+
HypixelPlayer player = (HypixelPlayer) sender;
3233
String playerName = context.get(argument);
3334

3435
CompletableFuture.runAsync(() -> {
3536
try {
3637
var targetUuid = MojangUtils.getUUID(playerName);
3738
ProxyService punishmentService = new ProxyService(ServiceType.PUNISHMENT);
3839
var message = new UnpunishPlayerProtocolObject.UnpunishPlayerMessage(
39-
targetUuid, (sender instanceof Player p ? p.getUuid() : new UUID(0, 0))
40+
targetUuid, player.getUuid(), PunishmentType.BAN.name()
4041
);
4142

4243
punishmentService.handleRequest(message).thenAccept(result -> {
4344
if (result instanceof UnpunishPlayerProtocolObject.UnpunishPlayerResponse response) {
4445
if (response.success()) {
45-
sender.sendMessage("§aSuccessfully unbanned player: " + playerName);
46+
player.sendMessage("§aSuccessfully unbanned player: " + playerName);
4647
} else {
47-
sender.sendMessage("§c" + response.errorMessage());
48+
player.sendMessage("§c" + response.errorMessage());
4849
}
4950
}
5051
}).orTimeout(5, TimeUnit.SECONDS).exceptionally(_ -> {
51-
sender.sendMessage("§cCould not unban this player at this time. The punishment service may be offline.");
52+
player.sendMessage("§cCould not unban this player at this time. The punishment service may be offline.");
5253
return null;
5354
});
5455
} catch (IOException e) {
55-
sender.sendMessage("§cCould not find player: " + playerName);
56+
player.sendMessage("§cCould not find player: " + playerName);
5657
}
5758
});
5859
}, argument);
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package net.swofty.type.generic.command.commands;
2+
3+
import net.minestom.server.command.builder.arguments.ArgumentType;
4+
import net.minestom.server.utils.mojang.MojangUtils;
5+
import net.swofty.commons.ServiceType;
6+
import net.swofty.commons.protocol.objects.punishment.UnpunishPlayerProtocolObject;
7+
import net.swofty.commons.punishment.PunishmentType;
8+
import net.swofty.proxyapi.ProxyService;
9+
import net.swofty.type.generic.command.CommandParameters;
10+
import net.swofty.type.generic.command.HypixelCommand;
11+
import net.swofty.type.generic.user.HypixelPlayer;
12+
import net.swofty.type.generic.user.categories.Rank;
13+
14+
import java.io.IOException;
15+
import java.util.concurrent.CompletableFuture;
16+
import java.util.concurrent.TimeUnit;
17+
18+
@CommandParameters(
19+
description = "Unmute a player on the server.",
20+
usage = "/unmute <player>",
21+
aliases = "unmute",
22+
permission = Rank.STAFF,
23+
allowsConsole = false
24+
)
25+
public class UnMuteCommand extends HypixelCommand {
26+
27+
@Override
28+
public void registerUsage(MinestomCommand command) {
29+
var argument = ArgumentType.String("player");
30+
31+
command.addSyntax((sender, context) -> {
32+
HypixelPlayer player = (HypixelPlayer) sender;
33+
String playerName = context.get(argument);
34+
35+
CompletableFuture.runAsync(() -> {
36+
try {
37+
var targetUuid = MojangUtils.getUUID(playerName);
38+
ProxyService punishmentService = new ProxyService(ServiceType.PUNISHMENT);
39+
var message = new UnpunishPlayerProtocolObject.UnpunishPlayerMessage(
40+
targetUuid, player.getUuid(), PunishmentType.MUTE.name()
41+
);
42+
43+
punishmentService.handleRequest(message).thenAccept(result -> {
44+
if (result instanceof UnpunishPlayerProtocolObject.UnpunishPlayerResponse response) {
45+
if (response.success()) {
46+
player.sendMessage("§aSuccessfully unmuted player: " + playerName);
47+
} else {
48+
player.sendMessage("§c" + response.errorMessage());
49+
}
50+
}
51+
}).orTimeout(5, TimeUnit.SECONDS).exceptionally(_ -> {
52+
player.sendMessage("§cCould not unmute this player at this time. The punishment service may be offline.");
53+
return null;
54+
});
55+
} catch (IOException e) {
56+
player.sendMessage("§cCould not find player: " + playerName);
57+
}
58+
});
59+
}, argument);
60+
}
61+
}

type.generic/src/main/java/net/swofty/type/generic/event/actions/ActionPlayerMute.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ public void onPlayerChat(PlayerChatEvent event) {
2121
Player player = event.getPlayer();
2222
try {
2323
var response = new ProxyService(ServiceType.PUNISHMENT)
24-
.handleRequest(new GetActivePunishmentProtocolObject.GetActivePunishmentMessage(player.getUuid()))
24+
.handleRequest(new GetActivePunishmentProtocolObject.GetActivePunishmentMessage(
25+
player.getUuid(), PunishmentType.MUTE.name()))
2526
.orTimeout(2, TimeUnit.SECONDS)
2627
.join();
2728

28-
if (response instanceof GetActivePunishmentProtocolObject.GetActivePunishmentResponse r
29-
&& r.found() && PunishmentType.valueOf(r.type()) == PunishmentType.MUTE) {
29+
if (response instanceof GetActivePunishmentProtocolObject.GetActivePunishmentResponse r && r.found()) {
3030
event.setCancelled(true);
3131
var punishment = new ActivePunishment(r.type(), r.banId(), r.reason(), r.expiresAt(), r.tags());
3232
player.sendMessage(PunishmentMessages.muteMessage(punishment));

0 commit comments

Comments
 (0)