Skip to content

Commit 8b8d36a

Browse files
committed
misc: Improved ChatRegulator Expansion registration
1 parent ea2aff5 commit 8b8d36a

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

plugin/src/main/java/io/github/_4drian3d/chatregulator/plugin/placeholders/RegulatorExpansion.java

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,33 @@
11
package io.github._4drian3d.chatregulator.plugin.placeholders;
22

33
import com.velocitypowered.api.proxy.Player;
4+
import io.github._4drian3d.chatregulator.api.InfractionPlayer;
5+
import io.github._4drian3d.chatregulator.api.PlayerManager;
46
import io.github._4drian3d.chatregulator.api.enums.InfractionType;
5-
import io.github._4drian3d.chatregulator.plugin.impl.InfractionPlayerImpl;
6-
import io.github._4drian3d.chatregulator.plugin.impl.PlayerManagerImpl;
77
import io.github.miniplaceholders.api.Expansion;
8-
import net.kyori.adventure.text.Component;
8+
import net.kyori.adventure.identity.Identity;
99
import net.kyori.adventure.text.minimessage.tag.Tag;
1010

1111
import java.util.Locale;
12+
import java.util.UUID;
1213

1314
public final class RegulatorExpansion {
1415
private RegulatorExpansion(){}
15-
public static Expansion getExpansion(PlayerManagerImpl manager){
16+
public static Expansion getExpansion(PlayerManager manager) {
1617
return Expansion.builder("chatregulator")
1718
.filter(Player.class)
1819
.audiencePlaceholder("infractions_count", (aud, queue, ctx) -> {
19-
InfractionPlayerImpl player = manager.getPlayer((Player)aud);
20-
String type = queue.popOr(() -> "you need to introduce the infraction type").value();
21-
return Tag.selfClosingInserting(
22-
Component.text(
23-
player.getInfractions().getCount(
24-
switch(type.toLowerCase(Locale.ROOT)){
25-
case "flood" -> InfractionType.FLOOD;
26-
case "spam" -> InfractionType.SPAM;
27-
case "regular" -> InfractionType.REGEX;
28-
case "command" -> InfractionType.BLOCKED_COMMAND;
29-
case "unicode" -> InfractionType.UNICODE;
30-
case "syntax" -> InfractionType.SYNTAX;
31-
case "global" -> InfractionType.GLOBAL;
32-
default -> throw ctx.newException("Invalid Infraction Type");
33-
}
34-
)
35-
)
36-
);
20+
final UUID uuid = aud.get(Identity.UUID).orElse(null);
21+
if (uuid == null) {
22+
return null;
23+
}
24+
25+
final InfractionPlayer player = manager.getPlayer(uuid);
26+
final String type = queue.popOr("you need to introduce the infraction type")
27+
.value().toUpperCase(Locale.ROOT);
28+
final InfractionType infractionType = InfractionType.INDEX.valueOrThrow(type);
29+
30+
return Tag.preProcessParsed(Integer.toString(player.getInfractions().getCount(infractionType)));
3731
})
3832
.build();
3933
}

0 commit comments

Comments
 (0)