Skip to content

Commit 3c35dfc

Browse files
committed
make default value null
it is overridden by libmod anyway
1 parent cbd2c69 commit 3c35dfc

1 file changed

Lines changed: 54 additions & 91 deletions

File tree

  • src/api/main/java/com/ampznetwork/banmod/api

src/api/main/java/com/ampznetwork/banmod/api/BanMod.java

Lines changed: 54 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import java.util.UUID;
3333
import java.util.function.BiConsumer;
3434
import java.util.stream.Collector;
35+
import java.util.stream.Collectors;
36+
import java.util.stream.Stream;
3537

3638
import static net.kyori.adventure.text.Component.*;
3739
import static net.kyori.adventure.text.event.ClickEvent.*;
@@ -49,7 +51,8 @@ default Class<?> getModuleType() {
4951

5052
@Override
5153
default Set<Class<? extends DbObject>> getEntityTypes() {
52-
return Set.of(Infraction.class, PunishmentCategory.class);
54+
return Stream.concat(getLib().getEntityTypes().stream(), Stream.of(Infraction.class, PunishmentCategory.class))
55+
.collect(Collectors.toUnmodifiableSet());
5356
}
5457

5558
@Override
@@ -62,20 +65,16 @@ default TextColor getThemeColor() {
6265
.by(PunishmentCategory::getName)
6366
.getOrCreate("default")
6467
.setUpdateOriginal(original -> {
65-
original.getPunishmentThresholds().putAll(Map.of(
66-
0, Punishment.Kick,
67-
2, Punishment.Mute,
68-
5, Punishment.Ban
69-
));
68+
original.getPunishmentThresholds()
69+
.putAll(Map.of(0, Punishment.Kick, 2, Punishment.Mute, 5, Punishment.Ban));
7070
return original;
7171
})
7272
.complete(cat -> cat.punishmentThreshold(0, Punishment.Kick)
7373
.punishmentThreshold(2, Punishment.Mute)
7474
.punishmentThreshold(5, Punishment.Ban));
7575
}
7676

77-
@Nullable
78-
String getBanAppealUrl();
77+
@Nullable String getBanAppealUrl();
7978

8079
Logger log();
8180

@@ -93,8 +92,7 @@ default void realize(Infraction infraction) {
9392
}
9493

9594
default PlayerResult queuePlayer(UUID playerId) {
96-
var player = getLib().getPlayerAdapter()
97-
.getPlayer(playerId).orElseThrow();
95+
var player = getLib().getPlayerAdapter().getPlayer(playerId).orElseThrow();
9896
return getEntityService().getAccessor(Infraction.TYPE)
9997
.querySelect("select i.* from banmod_punishments i where i.player_id = :playerId",
10098
Map.of("playerId", playerId.toString()))
@@ -146,15 +144,11 @@ final class Resources {
146144
public static final int ENTRIES_PER_PAGE = 8;
147145

148146
public static void notify(
149-
BanMod mod,
150-
UUID playerId,
151-
@Nullable Punishment punishment,
152-
PlayerResult result,
147+
BanMod mod, UUID playerId, @Nullable Punishment punishment, PlayerResult result,
153148
BiConsumer<UUID, Component> forwarder
154149
) {
155150
var playerAdapter = mod.getLib().getPlayerAdapter();
156-
if (!playerAdapter.isOnline(playerId) && mod.allowUnsafeConnections())
157-
return;
151+
if (!playerAdapter.isOnline(playerId) && mod.allowUnsafeConnections()) return;
158152
var name = playerAdapter.getName(playerId);
159153
TextComponent msgUser, msgNotify;
160154
Permission permission = banmod.notify.error;
@@ -194,18 +188,20 @@ public static void notify(
194188

195189
forwarder.accept(playerId, msgUser);
196190
playerAdapter.broadcast(permission.toString(), msgNotify);
197-
if (punishment != null)
198-
mod.log()
199-
.info("User %s is %#s (%s)".formatted(name, punishment,
200-
Displays.formatTimestamp(result.expires())));
191+
if (punishment != null) mod.log()
192+
.info("User %s is %#s (%s)".formatted(name,
193+
punishment,
194+
Displays.formatTimestamp(result.expires())));
201195
}
202196

203197
public static void printExceptionWithIssueReportUrl(BanMod mod, String message, Throwable t) {
204198
printExceptionWithIssueReportUrl(mod.log(), message, t);
205199
}
206200

207201
public static void printExceptionWithIssueReportUrl(Logger log, String message, Throwable t) {
208-
log.error(message, new RuntimeException("An unexpected internal error occurred. Please open a bugreport at " + Strings.IssuesUrl, t));
202+
log.error(message,
203+
new RuntimeException("An unexpected internal error occurred. Please open a bugreport at " + Strings.IssuesUrl,
204+
t));
209205
}
210206

211207
public static Command.@NotNull Error couldNotSaveError() {
@@ -217,55 +213,45 @@ public static void printExceptionWithIssueReportUrl(Logger log, String message,
217213
final class Displays {
218214
@NotNull
219215
public static String formatDuration(Duration duration) {
220-
if (duration == null)
221-
return "permanent";
216+
if (duration == null) return "permanent";
222217
return Polyfill.durationString(duration);
223218
}
224219

225220
@NotNull
226221
public Component infractionList(BanMod mod, int page, Punishment punishment) {
227-
final var infractions = mod.getLib().getEntityService()
222+
final var infractions = mod.getLib()
223+
.getEntityService()
228224
.getAccessor(Infraction.TYPE)
229225
.all()
230226
.filter(Infraction.IS_IN_EFFECT)
231227
.filter(i -> i.getPunishment() == punishment)
232228
.sorted(Infraction.BY_NEWEST)
233-
.distinct().toList();
229+
.distinct()
230+
.toList();
234231
final var pageCount = Math.ceil(1d * infractions.size() / Resources.ENTRIES_PER_PAGE);
235232
return infractions.stream()
236-
.sorted(Infraction.BY_SHORTEST.thenComparing(i -> i.getPlayer()
237-
.getLastKnownName()
238-
.orElse("")))
233+
.sorted(Infraction.BY_SHORTEST.thenComparing(i -> i.getPlayer().getLastKnownName().orElse("")))
239234
.skip(Math.max(0, (page - 1L) * Resources.ENTRIES_PER_PAGE))
240235
.limit(Resources.ENTRIES_PER_PAGE)
241-
.map(infraction -> text("\n- ")
242-
.append(textPunishmentFull(mod, infraction)))
243-
.collect(Streams.atLeastOneOrElseGet(() -> text("\n- ")
244-
.append(text("(none)").color(GRAY))))
245-
.collect(Collector.of(() -> text()
246-
.append(text(punishment.name() + "list (Page %d of %d)"
247-
.formatted((Integer) (pageCount == 0 ? 0 : Math.max(1, page)), (Integer) (int) pageCount))),
248-
ComponentBuilder::append,
249-
(l, r) -> {
250-
l.append(r);
251-
return l;
252-
},
253-
ComponentBuilder::build));
236+
.map(infraction -> text("\n- ").append(textPunishmentFull(mod, infraction)))
237+
.collect(Streams.atLeastOneOrElseGet(() -> text("\n- ").append(text("(none)").color(GRAY))))
238+
.collect(Collector.of(() -> text().append(text(punishment.name() + "list (Page %d of %d)".formatted(
239+
(Integer) (pageCount == 0 ? 0 : Math.max(1, page)),
240+
(Integer) (int) pageCount))), ComponentBuilder::append, (l, r) -> {
241+
l.append(r);
242+
return l;
243+
}, ComponentBuilder::build));
254244
}
255245

256246
@NotNull
257247
public Component textPunishmentFull(BanMod mod, Infraction infraction) {
258248
var username = mod.getLib().getPlayerAdapter().getName(infraction.getPlayer().getId());
259-
var text = text("User ")
260-
.append(text(username).color(AQUA))
249+
var text = text("User ").append(text(username).color(AQUA))
261250
.append(text(" has been "))
262-
.append(infraction.getPunishment()
263-
.toComponent(true));
251+
.append(infraction.getPunishment().toComponent(true));
264252

265253
var reason = infraction.getReason();
266-
if (reason != null)
267-
text = text.append(text(": "))
268-
.append(text(reason).color(LIGHT_PURPLE));
254+
if (reason != null) text = text.append(text(": ")).append(text(reason).color(LIGHT_PURPLE));
269255

270256
return text.append(textExpiry(infraction.getExpires()));
271257
}
@@ -274,55 +260,39 @@ public Component textPunishmentFull(BanMod mod, Infraction infraction) {
274260
public static TextComponent textExpiry(Instant expiry) {
275261
var text = text();
276262
if (expiry != null && !expiry.isBefore(Infraction.TOO_EARLY)) {
277-
text.append(text(" (until "))
278-
.append(text(formatTimestamp(expiry)).color(YELLOW))
279-
.append(text(")"));
280-
} else text.append(text(" ("))
281-
.append(text("permanently").color(RED))
282-
.append(text(")"));
263+
text.append(text(" (until ")).append(text(formatTimestamp(expiry)).color(YELLOW)).append(text(")"));
264+
} else text.append(text(" (")).append(text("permanently").color(RED)).append(text(")"));
283265
return text.build();
284266
}
285267

286268
@NotNull
287269
public static TextComponent bannedTextUser(BanMod mod, PlayerResult result) {
288-
var text = text()
289-
.append(text("You are banned from this Server")
290-
.color(RED)
291-
.decorate(BOLD, UNDERLINED))
270+
var text = text().append(text("You are banned from this Server").color(RED).decorate(BOLD, UNDERLINED))
292271
.append(text("\n\n"));
293-
if (result.reason() != null)
294-
text.append(text("Reason:\n\n")
295-
.color(AQUA)
296-
.decorate(UNDERLINED))
297-
.append(text(result.reason()).color(YELLOW))
298-
.append(text("\n\n\n"));
272+
if (result.reason() != null) text.append(text("Reason:\n\n").color(AQUA).decorate(UNDERLINED))
273+
.append(text(result.reason()).color(YELLOW))
274+
.append(text("\n\n\n"));
299275

300276
text.append(text("This punishment ").color(RED));
301277
if (result.expires() == null || result.expires()
302-
.isBefore(Infraction.TOO_EARLY))
303-
text.append(text("is ").color(RED))
304-
.append(text("permanent")
305-
.color(DARK_RED)
306-
.decorate(BOLD))
307-
.append(text(".").color(RED));
278+
.isBefore(Infraction.TOO_EARLY)) text.append(text("is ").color(RED))
279+
.append(text("permanent").color(DARK_RED).decorate(BOLD))
280+
.append(text(".").color(RED));
308281
else text.append(text("ends at ").color(RED))
309-
.append(text(formatTimestamp(result.expires()))
310-
.color(YELLOW))
282+
.append(text(formatTimestamp(result.expires())).color(YELLOW))
311283
.append(text(".").color(RED));
312284

313285
var appealUrl = mod.getBanAppealUrl();
314-
if (appealUrl != null)
315-
text.append(text("\nYou may appeal to get unbanned at\n").color(GRAY))
316-
.append(text(appealUrl).color(AQUA)
317-
.hoverEvent(showText(text("Open Link")))
318-
.clickEvent(clickEvent(ClickEvent.Action.OPEN_URL, appealUrl)));
286+
if (appealUrl != null) text.append(text("\nYou may appeal to get unbanned at\n").color(GRAY))
287+
.append(text(appealUrl).color(AQUA)
288+
.hoverEvent(showText(text("Open Link")))
289+
.clickEvent(clickEvent(ClickEvent.Action.OPEN_URL, appealUrl)));
319290
return text.build();
320291
}
321292

322293
@NotNull
323294
public static String formatTimestamp(Instant expiry) {
324-
if (expiry == null)
325-
return "permanent";
295+
if (expiry == null) return "permanent";
326296
var dateTime = LocalDateTime.ofInstant(expiry, ZoneId.systemDefault());
327297
var formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
328298
return dateTime.format(formatter);
@@ -331,17 +301,14 @@ public static String formatTimestamp(Instant expiry) {
331301
@NotNull
332302
public static TextComponent mutedTextUser(PlayerResult result) {
333303
var text = text().append(text("You are muted!").color(RED));
334-
if (result.reason() != null)
335-
text.append(text(" Reason: "))
336-
.append(text(result.reason()).color(YELLOW));
304+
if (result.reason() != null) text.append(text(" Reason: ")).append(text(result.reason()).color(YELLOW));
337305
text.append(textExpiry(result.expires()));
338306
return text.build();
339307
}
340308

341309
@NotNull
342310
public static TextComponent mutedTextNotify(String name) {
343-
return text("")
344-
.append(text("Player "))
311+
return text("").append(text("Player "))
345312
.append(text(name).color(RED))
346313
.append(text(" tried to write in chat, but they are "))
347314
.append(text("muted").color(YELLOW))
@@ -351,24 +318,20 @@ public static TextComponent mutedTextNotify(String name) {
351318
@NotNull
352319
public static TextComponent kickedTextUser(PlayerResult result) {
353320
var text = text().append(text("You were kicked from the server").color(RED));
354-
if (result.reason() != null)
355-
text.append(text("\nReason: "))
356-
.append(text(result.reason()).color(YELLOW));
321+
if (result.reason() != null) text.append(text("\nReason: ")).append(text(result.reason()).color(YELLOW));
357322
return text.build();
358323
}
359324

360325
@NotNull
361326
public static TextComponent kickedTextNotify(String name) {
362-
return text("")
363-
.append(text("Player "))
327+
return text("").append(text("Player "))
364328
.append(text(name).color(RED))
365329
.append(text(" was kicked from the server."));
366330
}
367331

368332
@NotNull
369333
public static TextComponent bannedTextNotify(String name) {
370-
return text("")
371-
.append(text("Player "))
334+
return text("").append(text("Player "))
372335
.append(text(name).color(RED))
373336
.append(text(" tried to join the game, but they are "))
374337
.append(text("banned").color(DARK_RED))

0 commit comments

Comments
 (0)