Skip to content

Commit e60e2e2

Browse files
style(punishment): replace var with explicit types, rename single-char variables
1 parent e350d4f commit e60e2e2

5 files changed

Lines changed: 39 additions & 30 deletions

File tree

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static void saveActivePunishment(UUID playerId, String type, String id,
6868
if (!isInitialized()) throw new IllegalStateException("PunishmentRedis not initialized");
6969

7070
try (Jedis jedis = jedisPool.getResource()) {
71-
String k = key(playerId, type);
71+
String redisKey = key(playerId, type);
7272

7373
HashMap<String, String> data = new HashMap<>(Map.of(
7474
"type", type,
@@ -80,14 +80,14 @@ public static void saveActivePunishment(UUID playerId, String type, String id,
8080
data.put("tags", GSON.toJson(tags));
8181
}
8282

83-
jedis.hset(k, data);
83+
jedis.hset(redisKey, data);
8484
if (expiresAt > 0) {
8585
long ttlSeconds = (expiresAt - System.currentTimeMillis()) / 1000;
8686
if (ttlSeconds > 0) {
87-
jedis.expire(k, (int) ttlSeconds);
87+
jedis.expire(redisKey, (int) ttlSeconds);
8888
}
8989
} else {
90-
jedis.persist(k);
90+
jedis.persist(redisKey);
9191
}
9292
}
9393
}
@@ -96,16 +96,16 @@ public static Optional<ActivePunishment> getActive(UUID playerId, String type) {
9696
if (!isInitialized()) return Optional.empty();
9797

9898
try (Jedis jedis = jedisPool.getResource()) {
99-
String k = key(playerId, type);
100-
Map<String, String> data = jedis.hgetAll(k);
99+
String redisKey = key(playerId, type);
100+
Map<String, String> data = jedis.hgetAll(redisKey);
101101

102102
if (data.isEmpty()) return Optional.empty();
103103

104104
String banId = data.get("banId");
105105
long expiresAt = Long.parseLong(data.getOrDefault("expiresAt", "-1"));
106106

107107
if (expiresAt > 0 && System.currentTimeMillis() > expiresAt) {
108-
jedis.del(k);
108+
jedis.del(redisKey);
109109
return Optional.empty();
110110
}
111111

@@ -125,8 +125,8 @@ public static List<ActivePunishment> getAllActive(UUID playerId) {
125125
if (!isInitialized()) return List.of();
126126

127127
List<ActivePunishment> result = new ArrayList<>();
128-
for (PunishmentType pt : PunishmentType.values()) {
129-
getActive(playerId, pt.name()).ifPresent(result::add);
128+
for (PunishmentType punishmentType : PunishmentType.values()) {
129+
getActive(playerId, punishmentType.name()).ifPresent(result::add);
130130
}
131131
return result;
132132
}

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
import net.swofty.type.generic.user.HypixelPlayer;
1212
import net.swofty.type.generic.user.categories.Rank;
1313

14+
import net.minestom.server.command.builder.arguments.Argument;
15+
1416
import java.io.IOException;
17+
import java.util.UUID;
1518
import java.util.concurrent.CompletableFuture;
1619
import java.util.concurrent.TimeUnit;
1720

@@ -26,17 +29,17 @@ public class UnBanCommand extends HypixelCommand {
2629

2730
@Override
2831
public void registerUsage(MinestomCommand command) {
29-
var argument = ArgumentType.String("player");
32+
Argument<String> playerArg = ArgumentType.String("player");
3033

3134
command.addSyntax((sender, context) -> {
3235
HypixelPlayer player = (HypixelPlayer) sender;
33-
String playerName = context.get(argument);
36+
String playerName = context.get(playerArg);
3437

3538
CompletableFuture.runAsync(() -> {
3639
try {
37-
var targetUuid = MojangUtils.getUUID(playerName);
40+
UUID targetUuid = MojangUtils.getUUID(playerName);
3841
ProxyService punishmentService = new ProxyService(ServiceType.PUNISHMENT);
39-
var message = new UnpunishPlayerProtocolObject.UnpunishPlayerMessage(
42+
UnpunishPlayerProtocolObject.UnpunishPlayerMessage message = new UnpunishPlayerProtocolObject.UnpunishPlayerMessage(
4043
targetUuid, player.getUuid(), PunishmentType.BAN.name()
4144
);
4245

@@ -56,6 +59,6 @@ public void registerUsage(MinestomCommand command) {
5659
player.sendMessage("§cCould not find player: " + playerName);
5760
}
5861
});
59-
}, argument);
62+
}, playerArg);
6063
}
6164
}

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
import net.swofty.type.generic.user.HypixelPlayer;
1212
import net.swofty.type.generic.user.categories.Rank;
1313

14+
import net.minestom.server.command.builder.arguments.Argument;
15+
1416
import java.io.IOException;
17+
import java.util.UUID;
1518
import java.util.concurrent.CompletableFuture;
1619
import java.util.concurrent.TimeUnit;
1720

@@ -26,17 +29,17 @@ public class UnMuteCommand extends HypixelCommand {
2629

2730
@Override
2831
public void registerUsage(MinestomCommand command) {
29-
var argument = ArgumentType.String("player");
32+
Argument<String> playerArg = ArgumentType.String("player");
3033

3134
command.addSyntax((sender, context) -> {
3235
HypixelPlayer player = (HypixelPlayer) sender;
33-
String playerName = context.get(argument);
36+
String playerName = context.get(playerArg);
3437

3538
CompletableFuture.runAsync(() -> {
3639
try {
37-
var targetUuid = MojangUtils.getUUID(playerName);
40+
UUID targetUuid = MojangUtils.getUUID(playerName);
3841
ProxyService punishmentService = new ProxyService(ServiceType.PUNISHMENT);
39-
var message = new UnpunishPlayerProtocolObject.UnpunishPlayerMessage(
42+
UnpunishPlayerProtocolObject.UnpunishPlayerMessage message = new UnpunishPlayerProtocolObject.UnpunishPlayerMessage(
4043
targetUuid, player.getUuid(), PunishmentType.MUTE.name()
4144
);
4245

@@ -56,6 +59,6 @@ public void registerUsage(MinestomCommand command) {
5659
player.sendMessage("§cCould not find player: " + playerName);
5760
}
5861
});
59-
}, argument);
62+
}, playerArg);
6063
}
6164
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@ public class ActionPlayerMute implements HypixelEventClass {
2020
public void onPlayerChat(PlayerChatEvent event) {
2121
Player player = event.getPlayer();
2222
try {
23-
var response = new ProxyService(ServiceType.PUNISHMENT)
23+
Object response = new ProxyService(ServiceType.PUNISHMENT)
2424
.handleRequest(new GetActivePunishmentProtocolObject.GetActivePunishmentMessage(
2525
player.getUuid(), PunishmentType.MUTE.name()))
2626
.orTimeout(2, TimeUnit.SECONDS)
2727
.join();
2828

29-
if (response instanceof GetActivePunishmentProtocolObject.GetActivePunishmentResponse r && r.found()) {
29+
if (response instanceof GetActivePunishmentProtocolObject.GetActivePunishmentResponse muteResponse && muteResponse.found()) {
3030
event.setCancelled(true);
31-
var punishment = new ActivePunishment(r.type(), r.banId(), r.reason(), r.expiresAt(), r.tags());
31+
ActivePunishment punishment = new ActivePunishment(
32+
muteResponse.type(), muteResponse.banId(), muteResponse.reason(), muteResponse.expiresAt(), muteResponse.tags());
3233
player.sendMessage(PunishmentMessages.muteMessage(punishment));
3334
}
3435
} catch (Exception ignored) {

velocity.extension/src/main/java/net/swofty/velocity/SkyBlockVelocity.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,23 +222,25 @@ private boolean checkPunished(Player player) {
222222
try {
223223
ProxyService service = new ProxyService(ServiceType.PUNISHMENT);
224224

225-
var banFuture = service.handleRequest(
225+
CompletableFuture<?> banFuture = service.handleRequest(
226226
new GetActivePunishmentProtocolObject.GetActivePunishmentMessage(player.getUniqueId(), PunishmentType.BAN.name()));
227-
var muteFuture = service.handleRequest(
227+
CompletableFuture<?> muteFuture = service.handleRequest(
228228
new GetActivePunishmentProtocolObject.GetActivePunishmentMessage(player.getUniqueId(), PunishmentType.MUTE.name()));
229229

230230
CompletableFuture.allOf(banFuture, muteFuture).orTimeout(3, TimeUnit.SECONDS).join();
231231

232-
var banResponse = banFuture.join();
233-
if (banResponse instanceof GetActivePunishmentProtocolObject.GetActivePunishmentResponse r && r.found()) {
234-
ActivePunishment punishment = new ActivePunishment(r.type(), r.banId(), r.reason(), r.expiresAt(), r.tags());
232+
Object banResult = banFuture.join();
233+
if (banResult instanceof GetActivePunishmentProtocolObject.GetActivePunishmentResponse banResponse && banResponse.found()) {
234+
ActivePunishment punishment = new ActivePunishment(
235+
banResponse.type(), banResponse.banId(), banResponse.reason(), banResponse.expiresAt(), banResponse.tags());
235236
player.disconnect(PunishmentMessages.banMessage(punishment));
236237
return true;
237238
}
238239

239-
var muteResponse = muteFuture.join();
240-
if (muteResponse instanceof GetActivePunishmentProtocolObject.GetActivePunishmentResponse r && r.found()) {
241-
ActivePunishment punishment = new ActivePunishment(r.type(), r.banId(), r.reason(), r.expiresAt(), r.tags());
240+
Object muteResult = muteFuture.join();
241+
if (muteResult instanceof GetActivePunishmentProtocolObject.GetActivePunishmentResponse muteResponse && muteResponse.found()) {
242+
ActivePunishment punishment = new ActivePunishment(
243+
muteResponse.type(), muteResponse.banId(), muteResponse.reason(), muteResponse.expiresAt(), muteResponse.tags());
242244
player.sendMessage(PunishmentMessages.muteMessage(punishment));
243245
}
244246
return false;

0 commit comments

Comments
 (0)