|
1 | 1 | package io.github._4drian3d.chatregulator.plugin.placeholders; |
2 | 2 |
|
3 | 3 | import com.velocitypowered.api.proxy.Player; |
| 4 | +import io.github._4drian3d.chatregulator.api.InfractionPlayer; |
| 5 | +import io.github._4drian3d.chatregulator.api.PlayerManager; |
4 | 6 | 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; |
7 | 7 | import io.github.miniplaceholders.api.Expansion; |
8 | | -import net.kyori.adventure.text.Component; |
| 8 | +import net.kyori.adventure.identity.Identity; |
9 | 9 | import net.kyori.adventure.text.minimessage.tag.Tag; |
10 | 10 |
|
11 | 11 | import java.util.Locale; |
| 12 | +import java.util.UUID; |
12 | 13 |
|
13 | 14 | public final class RegulatorExpansion { |
14 | 15 | private RegulatorExpansion(){} |
15 | | - public static Expansion getExpansion(PlayerManagerImpl manager){ |
| 16 | + public static Expansion getExpansion(PlayerManager manager) { |
16 | 17 | return Expansion.builder("chatregulator") |
17 | 18 | .filter(Player.class) |
18 | 19 | .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))); |
37 | 31 | }) |
38 | 32 | .build(); |
39 | 33 | } |
|
0 commit comments