Skip to content

Commit 1e69773

Browse files
ArikSquadSwofty-Developments
authored andcommitted
feat: start tags
1 parent f9036e3 commit 1e69773

6 files changed

Lines changed: 91 additions & 26 deletions

File tree

commons/src/main/java/net/swofty/commons/protocol/objects/punishment/PunishPlayerProtocolObject.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
import net.swofty.commons.protocol.ProtocolObject;
55
import net.swofty.commons.protocol.Serializer;
66
import net.swofty.commons.punishment.PunishmentReason;
7+
import net.swofty.commons.punishment.PunishmentTag;
78
import org.jetbrains.annotations.NotNull;
89
import org.jetbrains.annotations.Nullable;
910
import org.json.JSONObject;
1011

12+
import java.util.List;
1113
import java.util.UUID;
1214

1315
public class PunishPlayerProtocolObject
@@ -25,6 +27,7 @@ public String serialize(PunishPlayerMessage value) {
2527
json.put("type", value.type());
2628
json.put("reason", new Gson().toJson(value.reason()));
2729
json.put("expiresAt", value.expiresAt());
30+
json.put("tags", new Gson().toJson(value.tags()));
2831
json.put("staff", value.staff().toString());
2932
return json.toString();
3033
}
@@ -38,6 +41,7 @@ public PunishPlayerMessage deserialize(String json) {
3841
obj.getString("type"),
3942
new Gson().fromJson(obj.getString("reason"), PunishmentReason.class),
4043
UUID.fromString(obj.getString("staff")),
44+
List.of(new Gson().fromJson(obj.getString("tags"), PunishmentTag[].class)),
4145
obj.getLong("expiresAt")
4246
);
4347
}
@@ -91,6 +95,7 @@ public record PunishPlayerMessage(
9195
PunishmentReason reason,
9296
@NotNull
9397
UUID staff,
98+
List<PunishmentTag> tags,
9499
long expiresAt
95100
) {
96101
}

commons/src/main/java/net/swofty/commons/punishment/PunishmentReason.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
@Getter
1111
public class PunishmentReason {
12-
@Nullable
13-
private String custom;
1412
@Nullable
1513
private BanType banType;
1614
@Nullable
@@ -24,17 +22,13 @@ public PunishmentReason(@NonNull MuteType muteType) {
2422
this.muteType = muteType;
2523
}
2624

27-
public PunishmentReason(@NonNull String custom) {
28-
this.custom = custom;
29-
}
30-
3125
public String getReasonString() {
3226
if (banType != null) {
3327
return banType.getReason();
3428
} else if (muteType != null) {
3529
return muteType.getReason();
3630
} else {
37-
return custom;
31+
return "Could not resolve reason.";
3832
}
3933
}
4034
}

commons/src/main/java/net/swofty/commons/punishment/PunishmentTag.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,23 @@
44

55
@Getter
66
public enum PunishmentTag {
7-
PERSONAL_PROOF("Personal proof", "P", null),
8-
GOLIATH("Punishment applied via Goliath", "G", null),
9-
PLAYER_REPORT("Player Report", "R", null),
10-
FORUMS("Forums", "F", null),
11-
SLACK("Slack", "S", null),
12-
WELFARE("Punishment applied over Welfare concern", "W", 99),
13-
ACCOUNT_SECURITY_ALERT(null, "ASA", null),
14-
RANKED_TEAM(null, "RT", null),
15-
CHECK_BEFORE_UNBAN("Check with the punisher before unbanning this user", "U", null),
16-
OVERWRITE("This punishment overwrote another punishment", "O", null);
7+
PERSONAL_PROOF("Personal proof", "P"),
8+
GOLIATH("Punishment applied via Goliath", "G"),
9+
PLAYER_REPORT("Player Report", "R"),
10+
FORUMS("Forums", "F"),
11+
SLACK("Slack", "S"),
12+
WELFARE("Punishment applied over Welfare concern", "W"),
13+
ACCOUNT_SECURITY_ALERT(null, "ASA"),
14+
RANKED_TEAM(null, "RT"),
15+
CHECK_BEFORE_UNBAN("Check with the punisher before unbanning this user", "U"),
16+
OVERWRITE("This punishment overwrote another punishment", "O");
1717

1818
private final String description;
1919
private final String shortCode;
20-
private final Integer group;
2120

22-
PunishmentTag(String description, String shortCode, Integer group) {
21+
PunishmentTag(String description, String shortCode) {
2322
this.description = description;
2423
this.shortCode = shortCode;
25-
this.group = group;
2624
}
2725

2826
}

service.punishment/src/main/java/net/swofty/service/punishment/endpoints/PunishPlayerEndpoint.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ public PunishPlayerProtocolObject.PunishPlayerResponse onMessage(ServiceProxyReq
5252
.put("target", messageObject.target())
5353
.put("type", messageObject.type())
5454
.put("id", id.id())
55-
.put("reason_custom", reason.getCustom() != null ? reason.getCustom() : null)
5655
.put("reason_ban", reason.getBanType() != null ? reason.getBanType().name() : null)
5756
.put("reason_mute", reason.getMuteType() != null ? reason.getMuteType().name() : null)
5857
.put("staff", messageObject.staff())

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

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,25 @@
1010
import net.swofty.commons.StringUtility;
1111
import net.swofty.commons.protocol.objects.punishment.PunishPlayerProtocolObject;
1212
import net.swofty.commons.punishment.PunishmentReason;
13+
import net.swofty.commons.punishment.PunishmentRedis;
14+
import net.swofty.commons.punishment.PunishmentTag;
1315
import net.swofty.commons.punishment.PunishmentType;
1416
import net.swofty.commons.punishment.template.BanType;
1517
import net.swofty.proxyapi.ProxyPlayer;
1618
import net.swofty.proxyapi.ProxyService;
1719
import net.swofty.type.generic.command.CommandParameters;
1820
import net.swofty.type.generic.command.HypixelCommand;
1921
import net.swofty.type.generic.user.categories.Rank;
22+
import org.jetbrains.annotations.Nullable;
2023

2124
import java.io.IOException;
25+
import java.util.ArrayList;
26+
import java.util.List;
27+
import java.util.Optional;
2228
import java.util.UUID;
2329
import java.util.concurrent.CompletableFuture;
2430
import java.util.concurrent.TimeUnit;
31+
import java.util.concurrent.atomic.AtomicBoolean;
2532

2633
@CommandParameters(
2734
aliases = "ban tempban banip tempbanip",
@@ -41,6 +48,11 @@ public void registerUsage(MinestomCommand command) {
4148
suggestion.addEntry(new SuggestionEntry(type.name(), Component.text("§c" + type.getReason() + " §7| Wipe: " + type.isWipe())));
4249
}
4350
});
51+
Argument<String[]> extraArg = ArgumentType.StringArray("extra").setSuggestionCallback((sender, context, suggestion) -> {
52+
for (PunishmentTag tag : PunishmentTag.values()) {
53+
suggestion.addEntry(new SuggestionEntry("-" + tag.getShortCode(), Component.text("§e" + tag.getShortCode() + " §7| " + (tag.getDescription() != null ? tag.getDescription() : "No description"))));
54+
}
55+
}); // can be -O -U etc.
4456

4557
command.addSyntax((sender, context) -> {
4658
String playerName = context.get(playerArg);
@@ -68,7 +80,7 @@ public void registerUsage(MinestomCommand command) {
6880
long expiryTime = System.currentTimeMillis() + actualTime;
6981

7082
CompletableFuture.runAsync(() -> {
71-
banPlayer(sender, targetUuid, type, senderUuid, actualTime, expiryTime, playerName);
83+
banPlayer(sender, targetUuid, type, senderUuid, actualTime, expiryTime, playerName, null);
7284
});
7385
}, playerArg, durationArg, reasonArg);
7486

@@ -85,23 +97,78 @@ public void registerUsage(MinestomCommand command) {
8597
sender instanceof Player player ? player.getUuid() : UUID.fromString("00000000-0000-0000-0000-000000000000"),
8698
0,
8799
-1,
88-
playerName);
100+
playerName, null);
89101
} catch (IOException e) {
90102
sender.sendMessage("§cCould not find player: " + playerName);
91103
return;
92104
}
93105
});
94106
}, playerArg, reasonArg);
107+
108+
command.addSyntax((sender, context) -> {
109+
String playerName = context.get(playerArg);
110+
BanType reason = BanType.valueOf(context.get(reasonArg));
111+
List<PunishmentTag> tags = parseTags(List.of(context.get(extraArg)));
112+
113+
CompletableFuture.runAsync(() -> {
114+
try {
115+
banPlayer(sender,
116+
MojangUtils.getUUID(playerName),
117+
reason,
118+
sender instanceof Player player ? player.getUuid() : UUID.fromString("00000000-0000-0000-0000-000000000000"),
119+
0,
120+
-1,
121+
playerName, tags);
122+
} catch (IOException e) {
123+
sender.sendMessage("§cCould not find player: " + playerName);
124+
}
125+
});
126+
}, playerArg, reasonArg, extraArg);
127+
}
128+
129+
private List<PunishmentTag> parseTags(List<String> rawTags) {
130+
List<PunishmentTag> tags = new ArrayList<>();
131+
132+
for (String rawTag : rawTags) {
133+
if (rawTag.startsWith("-")) {
134+
String tagCode = rawTag.substring(1).toUpperCase();
135+
for (PunishmentTag tag : PunishmentTag.values()) {
136+
if (tag.getShortCode().equalsIgnoreCase(tagCode)) {
137+
tags.add(tag);
138+
break;
139+
}
140+
}
141+
}
142+
}
143+
144+
return tags;
95145
}
96146

97-
private void banPlayer(CommandSender sender, UUID targetUuid, BanType type, UUID senderUuid, long actualTime, long expiryTime, String playerName) {
147+
private void banPlayer(CommandSender sender, UUID targetUuid, BanType type, UUID senderUuid, long actualTime, long expiryTime, String playerName, @Nullable List<PunishmentTag> tags) {
148+
if (tags != null && !tags.contains(PunishmentTag.OVERWRITE)) {
149+
Optional<PunishmentRedis.ActivePunishment> activePunishment = PunishmentRedis.getActive(targetUuid);
150+
AtomicBoolean alreadyBanned = new AtomicBoolean(false);
151+
activePunishment.ifPresent(punishment -> {
152+
PunishmentType t = PunishmentType.valueOf(punishment.type());
153+
if (t == PunishmentType.BAN) {
154+
sender.sendMessage("§cThis player is already banned. If you want to replace this ban use the tag -O, Punishment ID: §7" + punishment.banId());
155+
alreadyBanned.set(true);
156+
}
157+
});
158+
if (alreadyBanned.get()) {
159+
return;
160+
}
161+
}
162+
98163
ProxyService punishmentService = new ProxyService(ServiceType.PUNISHMENT);
99164
PunishmentReason reason = new PunishmentReason(type);
165+
ArrayList<PunishmentTag> tagList = (tags != null) ? new ArrayList<>(tags) : new ArrayList<>();
100166
PunishPlayerProtocolObject.PunishPlayerMessage message = new PunishPlayerProtocolObject.PunishPlayerMessage(
101167
targetUuid,
102168
PunishmentType.BAN.name(),
103169
reason,
104170
senderUuid,
171+
tagList,
105172
actualTime > 0 ? expiryTime : -1
106173
);
107174

velocity.extension/src/main/java/net/swofty/velocity/redis/listeners/ListenerPlayerPunished.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.swofty.velocity.redis.listeners;
22

33
import com.velocitypowered.api.proxy.ProxyServer;
4+
import io.sentry.Sentry;
45
import net.kyori.adventure.text.Component;
56
import net.swofty.commons.proxy.ToProxyChannels;
67
import net.swofty.commons.punishment.PunishmentId;
@@ -40,11 +41,12 @@ public JSONObject receivedMessage(JSONObject message, UUID serverUUID) {
4041
} else if (muteString != null) {
4142
reason = new PunishmentReason(MuteType.valueOf(muteString));
4243
} else {
43-
reason = new PunishmentReason(message.getString("reason_custom"));
44+
throw new JSONException("Missing reason ban, mute or reason_mute");
4445
}
4546
} catch (IllegalArgumentException | JSONException e) {
46-
reason = new PunishmentReason("Unknown Reason - Report Error");
4747
Logger.error("Failed to parse punishment reason from message: " + message, e);
48+
Sentry.captureException(e);
49+
return null;
4850
}
4951

5052

0 commit comments

Comments
 (0)