From 118c9a844f4d93ca30a0bc4e1fe9efce08417591 Mon Sep 17 00:00:00 2001 From: Christopher White <18whitechristop@gmail.com> Date: Thu, 21 Nov 2024 18:46:56 -0800 Subject: [PATCH] Add import restriction to match pgm Signed-off-by: Christopher White <18whitechristop@gmail.com> --- .../dev/pgm/community/CommunityCommand.java | 72 +++-- .../feature/AssistanceFeatureBase.java | 2 +- .../dev/pgm/community/database/Query.java | 8 +- .../feature/FriendshipFeatureBase.java | 29 +-- .../moderation/feature/ModerationFeature.java | 2 +- .../feature/ModerationFeatureBase.java | 2 +- .../feature/types/SQLModerationFeature.java | 245 ++++++++---------- .../moderation/punishments/Punishment.java | 66 +++-- .../punishments/types/BanPunishment.java | 2 +- .../types/ExpirablePunishment.java | 2 +- .../punishments/types/KickPunishment.java | 2 +- .../punishments/types/MutePunishment.java | 61 ++--- .../punishments/types/TempBanPunishment.java | 2 +- .../types/UsernameBanPunishment.java | 2 +- .../punishments/types/WarnPunishment.java | 2 +- .../services/SQLModerationService.java | 2 +- .../pgm/community/mutations/MutationBase.java | 2 +- .../types/items/FireworkMutation.java | 28 +- .../types/mechanics/MobMutation.java | 21 +- .../community/nick/commands/NickCommands.java | 2 +- .../nick/feature/NickFeatureBase.java | 2 +- .../dev/pgm/community/party/MapParty.java | 2 +- .../pgm/community/party/MapPartyMessages.java | 38 ++- .../dev/pgm/community/polls/PollBuilder.java | 17 +- .../polls/ending/types/NullEndAction.java | 7 +- .../requests/commands/RequestCommands.java | 126 ++++----- .../requests/feature/RequestFeature.java | 2 +- .../requests/feature/RequestFeatureBase.java | 2 +- .../requests/services/SQLRequestService.java | 2 +- .../sessions/services/SQLSessionService.java | 4 +- .../community/teleports/TeleportFeature.java | 24 +- .../community/users/feature/UsersFeature.java | 20 +- .../users/feature/UsersFeatureBase.java | 2 +- .../pgm/community/utils/BroadcastUtils.java | 91 +++---- .../pgm/community/utils/CommandAudience.java | 2 +- .../dev/pgm/community/utils/ImportUtils.java | 2 +- .../dev/pgm/community/utils/NetworkUtils.java | 14 +- .../dev/pgm/community/utils/PGMUtils.java | 2 +- .../dev/pgm/community/utils/WebUtils.java | 150 +++++------ .../pgm/community/utils/ranks/RankUtils.java | 2 +- pom.xml | 53 ++++ 41 files changed, 527 insertions(+), 591 deletions(-) diff --git a/core/src/main/java/dev/pgm/community/CommunityCommand.java b/core/src/main/java/dev/pgm/community/CommunityCommand.java index 180c213a..8acc194a 100644 --- a/core/src/main/java/dev/pgm/community/CommunityCommand.java +++ b/core/src/main/java/dev/pgm/community/CommunityCommand.java @@ -16,7 +16,6 @@ import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; -import javax.annotation.Nullable; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.HoverEvent; @@ -25,6 +24,7 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import org.jetbrains.annotations.Nullable; import tc.oc.pgm.api.match.Match; import tc.oc.pgm.api.player.MatchPlayer; import tc.oc.pgm.teams.Team; @@ -69,11 +69,10 @@ public Set getPlayers() { } public Component getText() { - List names = - players.stream() - .map(p -> player(p, NameStyle.FANCY)) - .limit(Math.min(players.size(), 10)) - .collect(Collectors.toList()); + List names = players.stream() + .map(p -> player(p, NameStyle.FANCY)) + .limit(Math.min(players.size(), 10)) + .collect(Collectors.toList()); Component hover = TextFormatter.list(names, NamedTextColor.GRAY); if (getPlayers().size() > names.size()) { @@ -101,10 +100,9 @@ protected PlayerSelection getPlayers(CommandAudience viewer, String input) { input.equalsIgnoreCase("*") && viewer.hasPermission(CommunityPermissions.ALL_SELECTOR); boolean isRandom = input.startsWith("?") && viewer.hasPermission(CommunityPermissions.RANDOM_SELECTOR); - boolean isTeam = - input.startsWith("team=") - && PGMUtils.isPGMEnabled() - && viewer.hasPermission(CommunityPermissions.TEAM_SELECTOR); + boolean isTeam = input.startsWith("team=") + && PGMUtils.isPGMEnabled() + && viewer.hasPermission(CommunityPermissions.TEAM_SELECTOR); String[] parts = input.split("="); @@ -114,25 +112,23 @@ protected PlayerSelection getPlayers(CommandAudience viewer, String input) { Component text; if (isAll) { targets.addAll(allOnline); - text = - text() - .append(text("everyone ")) - .append(text("(")) - .append(text(targets.size(), NamedTextColor.GREEN)) - .append(text(")")) - .color(NamedTextColor.GRAY) - .build(); + text = text() + .append(text("everyone ")) + .append(text("(")) + .append(text(targets.size(), NamedTextColor.GREEN)) + .append(text(")")) + .color(NamedTextColor.GRAY) + .build(); } else if (isRandom) { int randomCount = parts.length == 2 ? parseInputInt(input, 1) : 1; for (int i = 0; i < randomCount; i++) { targets.add(allOnline.get(Community.get().getRandom().nextInt(allOnline.size()))); } String rdTxt = " randomly chosen player" + (targets.size() != 1 ? "s" : ""); - text = - text() - .append(text(targets.size(), NamedTextColor.GREEN)) - .append(text(rdTxt, NamedTextColor.GRAY)) - .build(); + text = text() + .append(text(targets.size(), NamedTextColor.GREEN)) + .append(text(rdTxt, NamedTextColor.GRAY)) + .build(); } else if (isTeam) { Match match = PGMUtils.getMatch(); if (match.getModule(TeamMatchModule.class) != null) { @@ -145,10 +141,9 @@ protected PlayerSelection getPlayers(CommandAudience viewer, String input) { // Allow Observers to be selected if (teamName.toLowerCase().startsWith("obs")) { text = text("Observers", NamedTextColor.AQUA); - targets.addAll( - match.getObservers().stream() - .map(MatchPlayer::getBukkit) - .collect(Collectors.toList())); + targets.addAll(match.getObservers().stream() + .map(MatchPlayer::getBukkit) + .collect(Collectors.toList())); } else { Team team = teams.bestFuzzyMatch(teamName); if (team == null) { @@ -156,10 +151,9 @@ protected PlayerSelection getPlayers(CommandAudience viewer, String input) { } targets.addAll( team.getPlayers().stream().map(MatchPlayer::getBukkit).collect(Collectors.toList())); - text = - text() - .append(text(team.getNameLegacy(), TextFormatter.convert(team.getColor()))) - .build(); + text = text() + .append(text(team.getNameLegacy(), TextFormatter.convert(team.getColor()))) + .build(); } } else { throw TextException.exception("There are no teams in this match to select"); @@ -172,12 +166,11 @@ protected PlayerSelection getPlayers(CommandAudience viewer, String input) { targets.add(player); } } - text = - text() - .append(text(targets.size(), NamedTextColor.GREEN)) - .append(text(" player" + (targets.size() != 1 ? "s" : ""))) - .color(NamedTextColor.GRAY) - .build(); + text = text() + .append(text(targets.size(), NamedTextColor.GREEN)) + .append(text(" player" + (targets.size() != 1 ? "s" : ""))) + .color(NamedTextColor.GRAY) + .build(); if (targets.size() > 1 && !viewer.hasPermission(CommunityPermissions.SELECTOR)) { // If no permission for multiple, get a random single entry @@ -239,9 +232,8 @@ protected UUID getOnlineTarget(String target, UsersFeature service) { if (id == null) { // TODO: Maybe use getStoredID and listen, that way we can account for EVERYONE. But not a // priority now - Optional cachedId = - service.getId( - target); // If user is online or was online recently, we will have their UUID. + Optional cachedId = service.getId( + target); // If user is online or was online recently, we will have their UUID. if (!cachedId.isPresent()) { throw TextException.exception(formatNotFoundMsg(target)); } else { diff --git a/core/src/main/java/dev/pgm/community/assistance/feature/AssistanceFeatureBase.java b/core/src/main/java/dev/pgm/community/assistance/feature/AssistanceFeatureBase.java index 456124f1..f287a14c 100644 --- a/core/src/main/java/dev/pgm/community/assistance/feature/AssistanceFeatureBase.java +++ b/core/src/main/java/dev/pgm/community/assistance/feature/AssistanceFeatureBase.java @@ -35,7 +35,6 @@ import java.util.concurrent.TimeUnit; import java.util.logging.Logger; import java.util.stream.Collectors; -import javax.annotation.Nullable; import net.kyori.adventure.sound.Sound; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.event.HoverEvent; @@ -43,6 +42,7 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.jetbrains.annotations.Nullable; import tc.oc.pgm.util.Audience; import tc.oc.pgm.util.bukkit.BukkitUtils; import tc.oc.pgm.util.named.NameStyle; diff --git a/core/src/main/java/dev/pgm/community/database/Query.java b/core/src/main/java/dev/pgm/community/database/Query.java index a7165773..83566a73 100644 --- a/core/src/main/java/dev/pgm/community/database/Query.java +++ b/core/src/main/java/dev/pgm/community/database/Query.java @@ -1,18 +1,18 @@ package dev.pgm.community.database; -import static com.google.common.base.Preconditions.checkNotNull; +import static tc.oc.pgm.util.Assert.assertNotNull; public class Query { public static String createTable(String tableName, String fields) { - checkNotNull(tableName); - checkNotNull(fields); + assertNotNull(tableName); + assertNotNull(fields); return String.format("CREATE TABLE IF NOT EXISTS %s %s", tableName, fields); } public static String countTable(String tableName) { - checkNotNull(tableName); + assertNotNull(tableName); return String.format("SELECT count(*) from %s", tableName); } } diff --git a/core/src/main/java/dev/pgm/community/friends/feature/FriendshipFeatureBase.java b/core/src/main/java/dev/pgm/community/friends/feature/FriendshipFeatureBase.java index 4dcfaddd..b7e7b960 100644 --- a/core/src/main/java/dev/pgm/community/friends/feature/FriendshipFeatureBase.java +++ b/core/src/main/java/dev/pgm/community/friends/feature/FriendshipFeatureBase.java @@ -9,7 +9,6 @@ import dev.pgm.community.utils.PGMUtils; import dev.pgm.community.utils.Sounds; import java.util.logging.Logger; -import javax.annotation.Nullable; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.HoverEvent; @@ -21,11 +20,13 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.player.AsyncPlayerPreLoginEvent; import org.bukkit.event.player.PlayerJoinEvent; +import org.jetbrains.annotations.Nullable; import tc.oc.pgm.util.Audience; public abstract class FriendshipFeatureBase extends FeatureBase implements FriendshipFeature { - @Nullable protected PGMFriendIntegration integration; + @Nullable + protected PGMFriendIntegration integration; public FriendshipFeatureBase(Configuration config, Logger logger, String featureName) { super(new FriendshipConfig(config), logger, featureName); @@ -48,19 +49,17 @@ public void enable() { } public void sendFriendRequestLoginMessage(Player player, int requestCount) { - Component requestsMessage = - text() - .append(BroadcastUtils.RIGHT_DIV.color(NamedTextColor.GOLD)) - .append(text(" You have ")) - .append(text(requestCount, NamedTextColor.DARK_AQUA, TextDecoration.BOLD)) - .append(text(" pending friend request" + (requestCount != 1 ? "s " : " "))) - .append(BroadcastUtils.LEFT_DIV.color(NamedTextColor.GOLD)) - .color(NamedTextColor.DARK_GREEN) - .hoverEvent( - HoverEvent.showText( - text("Click to view pending friend requests", NamedTextColor.GRAY))) - .clickEvent(ClickEvent.runCommand("/friend requests")) - .build(); + Component requestsMessage = text() + .append(BroadcastUtils.RIGHT_DIV.color(NamedTextColor.GOLD)) + .append(text(" You have ")) + .append(text(requestCount, NamedTextColor.DARK_AQUA, TextDecoration.BOLD)) + .append(text(" pending friend request" + (requestCount != 1 ? "s " : " "))) + .append(BroadcastUtils.LEFT_DIV.color(NamedTextColor.GOLD)) + .color(NamedTextColor.DARK_GREEN) + .hoverEvent( + HoverEvent.showText(text("Click to view pending friend requests", NamedTextColor.GRAY))) + .clickEvent(ClickEvent.runCommand("/friend requests")) + .build(); Audience.get(player).sendMessage(requestsMessage); Audience.get(player).playSound(Sounds.FRIEND_REQUEST_LOGIN); diff --git a/core/src/main/java/dev/pgm/community/moderation/feature/ModerationFeature.java b/core/src/main/java/dev/pgm/community/moderation/feature/ModerationFeature.java index 18a044a8..cf64df74 100644 --- a/core/src/main/java/dev/pgm/community/moderation/feature/ModerationFeature.java +++ b/core/src/main/java/dev/pgm/community/moderation/feature/ModerationFeature.java @@ -13,9 +13,9 @@ import java.util.Set; import java.util.UUID; import java.util.concurrent.CompletableFuture; -import javax.annotation.Nullable; import org.bukkit.entity.Player; import org.bukkit.event.player.AsyncPlayerPreLoginEvent; +import org.jetbrains.annotations.Nullable; /** A feature that can handles moderation * */ public interface ModerationFeature extends Feature { diff --git a/core/src/main/java/dev/pgm/community/moderation/feature/ModerationFeatureBase.java b/core/src/main/java/dev/pgm/community/moderation/feature/ModerationFeatureBase.java index 524349db..78a3a6af 100644 --- a/core/src/main/java/dev/pgm/community/moderation/feature/ModerationFeatureBase.java +++ b/core/src/main/java/dev/pgm/community/moderation/feature/ModerationFeatureBase.java @@ -37,7 +37,6 @@ import java.util.concurrent.TimeUnit; import java.util.logging.Logger; import java.util.stream.Collectors; -import javax.annotation.Nullable; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.HoverEvent; @@ -53,6 +52,7 @@ import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerPreLoginEvent; import org.bukkit.event.player.PlayerJoinEvent; +import org.jetbrains.annotations.Nullable; import tc.oc.pgm.util.Audience; import tc.oc.pgm.util.named.NameStyle; diff --git a/core/src/main/java/dev/pgm/community/moderation/feature/types/SQLModerationFeature.java b/core/src/main/java/dev/pgm/community/moderation/feature/types/SQLModerationFeature.java index b25645e1..ce1048d2 100644 --- a/core/src/main/java/dev/pgm/community/moderation/feature/types/SQLModerationFeature.java +++ b/core/src/main/java/dev/pgm/community/moderation/feature/types/SQLModerationFeature.java @@ -22,13 +22,13 @@ import java.util.concurrent.TimeoutException; import java.util.logging.Logger; import java.util.stream.Collectors; -import javax.annotation.Nullable; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.configuration.Configuration; import org.bukkit.entity.Player; import org.bukkit.event.player.AsyncPlayerPreLoginEvent; import org.bukkit.event.player.AsyncPlayerPreLoginEvent.Result; +import org.jetbrains.annotations.Nullable; import tc.oc.pgm.util.named.NameStyle; public class SQLModerationFeature extends ModerationFeatureBase { @@ -49,30 +49,26 @@ public void save(Punishment punishment) { switch (punishment.getType()) { case TEMP_BAN: case BAN: - isBanned(punishment.getTargetId().toString()) - .thenAcceptAsync( - banned -> { - if (banned) { - service - .pardon(punishment.getTargetId(), punishment.getIssuerId()) - .thenAcceptAsync(x -> service.save(punishment)); - } else { - service.save(punishment); - } - }); + isBanned(punishment.getTargetId().toString()).thenAcceptAsync(banned -> { + if (banned) { + service + .pardon(punishment.getTargetId(), punishment.getIssuerId()) + .thenAcceptAsync(x -> service.save(punishment)); + } else { + service.save(punishment); + } + }); break; case MUTE: - isMuted(punishment.getTargetId()) - .thenAcceptAsync( - mute -> { - if (mute.isPresent()) { - service - .unmute(punishment.getTargetId(), punishment.getIssuerId()) - .thenAcceptAsync(x -> service.save(punishment)); - } else { - service.save(punishment); - } - }); + isMuted(punishment.getTargetId()).thenAcceptAsync(mute -> { + if (mute.isPresent()) { + service + .unmute(punishment.getTargetId(), punishment.getIssuerId()) + .thenAcceptAsync(x -> service.save(punishment)); + } else { + service.save(punishment); + } + }); break; default: service.save(punishment); @@ -87,50 +83,44 @@ public CompletableFuture> query(String target) { // CONVERT TO UUID if username return getUsers() .getStoredId(target) - .thenApplyAsync( - uuid -> - uuid != null && uuid.isPresent() - ? service.queryList(uuid.get().toString()).join() - : Lists.newArrayList()); + .thenApplyAsync(uuid -> uuid != null && uuid.isPresent() + ? service.queryList(uuid.get().toString()).join() + : Lists.newArrayList()); } return service.queryList(target); } @Override public CompletableFuture pardon(String target, @Nullable UUID issuer) { - CompletableFuture> playerId = - NameUtils.isMinecraftName(target) - ? getUsers().getStoredId(target) - : CompletableFuture.completedFuture(Optional.of(UUID.fromString(target))); - return playerId.thenApplyAsync( - uuid -> { - if (uuid.isPresent()) { - if (service.pardon(uuid.get(), issuer).join()) { - sendRefresh(uuid.get()); - removeCachedBan(uuid.get()); - return true; - } - } - return false; - }); + CompletableFuture> playerId = NameUtils.isMinecraftName(target) + ? getUsers().getStoredId(target) + : CompletableFuture.completedFuture(Optional.of(UUID.fromString(target))); + return playerId.thenApplyAsync(uuid -> { + if (uuid.isPresent()) { + if (service.pardon(uuid.get(), issuer).join()) { + sendRefresh(uuid.get()); + removeCachedBan(uuid.get()); + return true; + } + } + return false; + }); } @Override public CompletableFuture deactivate(String target, PunishmentType punishmentType) { - CompletableFuture> playerId = - NameUtils.isMinecraftName(target) - ? getUsers().getStoredId(target) - : CompletableFuture.completedFuture(Optional.of(UUID.fromString(target))); - return playerId.thenApplyAsync( - uuid -> { - if (uuid.isPresent()) { - if (service.deactivate(uuid.get(), punishmentType).join()) { - sendRefresh(uuid.get()); - return true; - } - } - return false; - }); + CompletableFuture> playerId = NameUtils.isMinecraftName(target) + ? getUsers().getStoredId(target) + : CompletableFuture.completedFuture(Optional.of(UUID.fromString(target))); + return playerId.thenApplyAsync(uuid -> { + if (uuid.isPresent()) { + if (service.deactivate(uuid.get(), punishmentType).join()) { + sendRefresh(uuid.get()); + return true; + } + } + return false; + }); } @Override @@ -149,11 +139,9 @@ public CompletableFuture> getActiveBan(String target) { if (NameUtils.isMinecraftName(target)) { return getUsers() .getStoredId(target) - .thenApplyAsync( - uuid -> - uuid.isPresent() - ? service.getActiveBan(uuid.get().toString()).join() - : Optional.empty()); + .thenApplyAsync(uuid -> uuid.isPresent() + ? service.getActiveBan(uuid.get().toString()).join() + : Optional.empty()); } return service.getActiveBan(target); } @@ -162,19 +150,17 @@ public CompletableFuture> getActiveBan(String target) { public void onPreLogin(AsyncPlayerPreLoginEvent event) { List punishments; try { - punishments = - service - .queryList(event.getUniqueId().toString()) - .get(getModerationConfig().getLoginTimeout(), TimeUnit.SECONDS); + punishments = service + .queryList(event.getUniqueId().toString()) + .get(getModerationConfig().getLoginTimeout(), TimeUnit.SECONDS); Optional ban = hasActiveBan(punishments); if (ban.isPresent()) { Punishment punishment = ban.get(); - event.setKickMessage( - punishment.formatPunishmentScreen( - getModerationConfig(), - getUsers().renderUsername(punishment.getIssuerId(), NameStyle.FANCY).join(), - false)); + event.setKickMessage(punishment.formatPunishmentScreen( + getModerationConfig(), + getUsers().renderUsername(punishment.getIssuerId(), NameStyle.FANCY).join(), + false)); event.setLoginResult(Result.KICK_BANNED); if (punishment.getType() == PunishmentType.NAME_BAN) { @@ -182,10 +168,9 @@ public void onPreLogin(AsyncPlayerPreLoginEvent event) { if (!event.getName().equalsIgnoreCase(bannedName)) { pardon(punishment.getTargetId().toString(), null); event.setLoginResult(Result.ALLOWED); - logger.info( - String.format( - "Name change detected for (%s) | %s -> %s | Account unbanned", - punishment.getTargetId().toString(), punishment.getReason(), event.getName())); + logger.info(String.format( + "Name change detected for (%s) | %s -> %s | Account unbanned", + punishment.getTargetId().toString(), punishment.getReason(), event.getName())); } } } @@ -211,10 +196,9 @@ public void onPreLogin(AsyncPlayerPreLoginEvent event) { 20 * 5); } - logger.info( - punishments.size() - + " Punishments have been fetched for " - + event.getUniqueId().toString()); + logger.info(punishments.size() + + " Punishments have been fetched for " + + event.getUniqueId().toString()); } catch (InterruptedException | ExecutionException e) { event.setLoginResult(Result.KICK_OTHER); event.setKickMessage( @@ -229,74 +213,60 @@ private void scheduleDelayedCheck(UUID playerId) { Community.get() .getServer() .getScheduler() - .scheduleSyncDelayedTask( - Community.get(), - new Runnable() { - @Override - public void run() { - Player player = Bukkit.getPlayer(playerId); - if (player != null) { - service - .queryList(playerId.toString()) - .thenAcceptAsync( - punishments -> { - Optional ban = hasActiveBan(punishments); - if (ban.isPresent()) { - Punishment punishment = ban.get(); - - player.kickPlayer( - punishment.formatPunishmentScreen( - getModerationConfig(), - getUsers() - .renderUsername(punishment.getIssuerId(), NameStyle.FANCY) - .join(), - false)); - } + .scheduleSyncDelayedTask(Community.get(), new Runnable() { + @Override + public void run() { + Player player = Bukkit.getPlayer(playerId); + if (player != null) { + service.queryList(playerId.toString()).thenAcceptAsync(punishments -> { + Optional ban = hasActiveBan(punishments); + if (ban.isPresent()) { + Punishment punishment = ban.get(); - Optional mute = hasActiveMute(punishments); - if (mute.isPresent()) { - addMute(playerId, mute.get()); - } + player.kickPlayer(punishment.formatPunishmentScreen( + getModerationConfig(), + getUsers() + .renderUsername(punishment.getIssuerId(), NameStyle.FANCY) + .join(), + false)); + } - logger.info( - "[Delayed]: " - + punishments.size() - + " Punishments have been fetched for " - + playerId.toString()); - }); + Optional mute = hasActiveMute(punishments); + if (mute.isPresent()) { + addMute(playerId, mute.get()); } - } - }); + + logger.info("[Delayed]: " + + punishments.size() + + " Punishments have been fetched for " + + playerId.toString()); + }); + } + } + }); } private Optional hasActiveMute(List punishments) { return punishments.stream() - .filter( - p -> - p.isActive() - && p.getType().equals(PunishmentType.MUTE) - && p.getService().equalsIgnoreCase(getModerationConfig().getService())) + .filter(p -> p.isActive() + && p.getType().equals(PunishmentType.MUTE) + && p.getService().equalsIgnoreCase(getModerationConfig().getService())) .map(MutePunishment.class::cast) .findAny(); } private Optional hasActiveBan(List punishments) { return punishments.stream() - .filter( - p -> - p.isActive() - && p.getType().isLoginPrevented() - && p.getService().equalsIgnoreCase(getModerationConfig().getService())) + .filter(p -> p.isActive() + && p.getType().isLoginPrevented() + && p.getService().equalsIgnoreCase(getModerationConfig().getService())) .findAny(); } private Set getDeferredPunishments(List punishments) { return punishments.stream() - .filter( - p -> - p.isActive() - && (PunishmentType.WARN.equals(p.getType()) - || PunishmentType.KICK.equals(p.getType()))) + .filter(p -> p.isActive() + && (PunishmentType.WARN.equals(p.getType()) || PunishmentType.KICK.equals(p.getType()))) .collect(Collectors.toSet()); } @@ -307,16 +277,13 @@ public CompletableFuture> isMuted(UUID target) { @Override public CompletableFuture unmute(UUID id, @Nullable UUID issuer) { - return service - .unmute(id, issuer) - .thenApplyAsync( - success -> { - if (success) { - removeMute(id); - sendRefresh(id); // Successful unmute will update other servers - } - return success; - }); + return service.unmute(id, issuer).thenApplyAsync(success -> { + if (success) { + removeMute(id); + sendRefresh(id); // Successful unmute will update other servers + } + return success; + }); } @Override diff --git a/core/src/main/java/dev/pgm/community/moderation/punishments/Punishment.java b/core/src/main/java/dev/pgm/community/moderation/punishments/Punishment.java index 629c769a..439827fa 100644 --- a/core/src/main/java/dev/pgm/community/moderation/punishments/Punishment.java +++ b/core/src/main/java/dev/pgm/community/moderation/punishments/Punishment.java @@ -27,7 +27,6 @@ import java.util.Map; import java.util.Optional; import java.util.UUID; -import javax.annotation.Nullable; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.format.NamedTextColor; @@ -36,6 +35,7 @@ import net.kyori.adventure.util.Ticks; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.jetbrains.annotations.Nullable; import tc.oc.pgm.util.Audience; import tc.oc.pgm.util.UsernameFormatUtils; import tc.oc.pgm.util.named.NameStyle; @@ -171,13 +171,12 @@ public boolean kick(boolean silent) { player .get() .getPlayer() - .kickPlayer( - formatPunishmentScreen( - getConfig(), - isConsole() - ? UsernameFormatUtils.CONSOLE_NAME - : PlayerComponent.player(getIssuerId(), NameStyle.FANCY), - silent)); + .kickPlayer(formatPunishmentScreen( + getConfig(), + isConsole() + ? UsernameFormatUtils.CONSOLE_NAME + : PlayerComponent.player(getIssuerId(), NameStyle.FANCY), + silent)); return true; } return false; @@ -190,24 +189,22 @@ public boolean kick(boolean silent) { */ public void sendWarning(Audience target, String reason) { Component titleWord = translatable("misc.warning", NamedTextColor.DARK_RED); - Component title = text().append(WARN_SYMBOL).append(titleWord).append(WARN_SYMBOL).build(); + Component title = + text().append(WARN_SYMBOL).append(titleWord).append(WARN_SYMBOL).build(); Component subtitle; if (Duration.between(getTimeIssued(), Instant.now()).getSeconds() >= 60) { - subtitle = - text() - .append( - TemporalComponent.relativePastApproximate(getTimeIssued()) - .color(NamedTextColor.YELLOW) - .append(text(": ", NamedTextColor.YELLOW))) - .append(text(reason, NamedTextColor.GOLD)) - .build(); + subtitle = text() + .append(TemporalComponent.relativePastApproximate(getTimeIssued()) + .color(NamedTextColor.YELLOW) + .append(text(": ", NamedTextColor.YELLOW))) + .append(text(reason, NamedTextColor.GOLD)) + .build(); } else { subtitle = text(reason, NamedTextColor.GOLD); } - target.showTitle( - title( - title, subtitle, Times.of(Ticks.duration(5), Ticks.duration(200), Ticks.duration(10)))); + target.showTitle(title( + title, subtitle, Times.of(Ticks.duration(5), Ticks.duration(200), Ticks.duration(10)))); target.playSound(Sounds.WARN_SOUND); } @@ -267,18 +264,16 @@ public String formatPunishmentScreen( List lines = Lists.newArrayList(); lines.add(empty()); - lines.add( - getType() - .getScreenComponent( - Duration.between(getTimeIssued(), Instant.now()).getSeconds() >= 60 - ? text() - .append( - TemporalComponent.relativePastApproximate(getTimeIssued()) - .color(NamedTextColor.YELLOW) - .append(text(": ", NamedTextColor.YELLOW))) - .append(text(reason, NamedTextColor.RED)) - .build() - : text(reason, NamedTextColor.RED))); + lines.add(getType() + .getScreenComponent( + Duration.between(getTimeIssued(), Instant.now()).getSeconds() >= 60 + ? text() + .append(TemporalComponent.relativePastApproximate(getTimeIssued()) + .color(NamedTextColor.YELLOW) + .append(text(": ", NamedTextColor.YELLOW))) + .append(text(reason, NamedTextColor.RED)) + .build() + : text(reason, NamedTextColor.RED))); // If punishment expires, display when if (this instanceof ExpirablePunishment) { @@ -295,10 +290,9 @@ public String formatPunishmentScreen( // Alert match banned players they won't be able to participate if (getType() == PunishmentType.KICK && config.getMatchBanDuration() != null) { lines.add(empty()); - lines.add( - text("You may rejoin, but will be unable to participate for ") - .append(duration(config.getMatchBanDuration(), NamedTextColor.YELLOW)) - .color(NamedTextColor.GRAY)); + lines.add(text("You may rejoin, but will be unable to participate for ") + .append(duration(config.getMatchBanDuration(), NamedTextColor.YELLOW)) + .color(NamedTextColor.GRAY)); } // Alert name banned players when their ban will be lifted diff --git a/core/src/main/java/dev/pgm/community/moderation/punishments/types/BanPunishment.java b/core/src/main/java/dev/pgm/community/moderation/punishments/types/BanPunishment.java index f7459a8f..9df2dede 100644 --- a/core/src/main/java/dev/pgm/community/moderation/punishments/types/BanPunishment.java +++ b/core/src/main/java/dev/pgm/community/moderation/punishments/types/BanPunishment.java @@ -3,7 +3,7 @@ import dev.pgm.community.moderation.punishments.Punishment; import dev.pgm.community.moderation.punishments.PunishmentType; import java.util.UUID; -import javax.annotation.Nullable; +import org.jetbrains.annotations.Nullable; public class BanPunishment extends Punishment { diff --git a/core/src/main/java/dev/pgm/community/moderation/punishments/types/ExpirablePunishment.java b/core/src/main/java/dev/pgm/community/moderation/punishments/types/ExpirablePunishment.java index 70064a40..8ca4218c 100644 --- a/core/src/main/java/dev/pgm/community/moderation/punishments/types/ExpirablePunishment.java +++ b/core/src/main/java/dev/pgm/community/moderation/punishments/types/ExpirablePunishment.java @@ -5,7 +5,7 @@ import java.time.Duration; import java.time.Instant; import java.util.UUID; -import javax.annotation.Nullable; +import org.jetbrains.annotations.Nullable; /** A punishment that can expire * */ public abstract class ExpirablePunishment extends Punishment { diff --git a/core/src/main/java/dev/pgm/community/moderation/punishments/types/KickPunishment.java b/core/src/main/java/dev/pgm/community/moderation/punishments/types/KickPunishment.java index 809ab1d4..a5c2c784 100644 --- a/core/src/main/java/dev/pgm/community/moderation/punishments/types/KickPunishment.java +++ b/core/src/main/java/dev/pgm/community/moderation/punishments/types/KickPunishment.java @@ -3,7 +3,7 @@ import dev.pgm.community.moderation.punishments.Punishment; import dev.pgm.community.moderation.punishments.PunishmentType; import java.util.UUID; -import javax.annotation.Nullable; +import org.jetbrains.annotations.Nullable; public class KickPunishment extends Punishment { diff --git a/core/src/main/java/dev/pgm/community/moderation/punishments/types/MutePunishment.java b/core/src/main/java/dev/pgm/community/moderation/punishments/types/MutePunishment.java index e5fa31f7..b9023731 100644 --- a/core/src/main/java/dev/pgm/community/moderation/punishments/types/MutePunishment.java +++ b/core/src/main/java/dev/pgm/community/moderation/punishments/types/MutePunishment.java @@ -8,9 +8,9 @@ import java.time.Duration; import java.time.Instant; import java.util.UUID; -import javax.annotation.Nullable; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; +import org.jetbrains.annotations.Nullable; import tc.oc.pgm.util.Audience; public class MutePunishment extends ExpirablePunishment { @@ -42,47 +42,43 @@ public MutePunishment( // When muted player attempts to chat public Component getChatMuteMessage() { - Component chat = - text("You are muted. Expires in ") - .append(getExpireTimeComponent()) - .append(text(": ")) - .append(text(getReason(), NamedTextColor.RED)) - .color(NamedTextColor.GRAY); + Component chat = text("You are muted. Expires in ") + .append(getExpireTimeComponent()) + .append(text(": ")) + .append(text(getReason(), NamedTextColor.RED)) + .color(NamedTextColor.GRAY); return formatWithHover(chat); } // When muted player attempts to place sign public Component getSignMuteMessage() { - Component sign = - text("You are unable to write on signs while muted: ") - .append(text(getReason(), NamedTextColor.RED)) - .color(NamedTextColor.GRAY); + Component sign = text("You are unable to write on signs while muted: ") + .append(text(getReason(), NamedTextColor.RED)) + .color(NamedTextColor.GRAY); return formatWithHover(sign); } // When player is muted public Component getMutedMessage() { - Component muted = - text("You have been muted for ") - .append(text(getReason(), NamedTextColor.RED)) - .color(NamedTextColor.GRAY); + Component muted = text("You have been muted for ") + .append(text(getReason(), NamedTextColor.RED)) + .color(NamedTextColor.GRAY); return formatWithHover(muted); } // Include expire time on hover private Component formatWithHover(Component message) { - Component hover = - text() - .append(text("Issued: ")) - .append(text(this.getTimeIssued().toString(), NamedTextColor.YELLOW)) - .append(newline()) - .append(text("Total duration: ")) - .append(duration(this.getDuration(), NamedTextColor.YELLOW)) - .append(newline()) - .append(text("Expires: ")) - .append(getExpireTimeComponent()) - .color(NamedTextColor.GRAY) - .build(); + Component hover = text() + .append(text("Issued: ")) + .append(text(this.getTimeIssued().toString(), NamedTextColor.YELLOW)) + .append(newline()) + .append(text("Total duration: ")) + .append(duration(this.getDuration(), NamedTextColor.YELLOW)) + .append(newline()) + .append(text("Expires: ")) + .append(getExpireTimeComponent()) + .color(NamedTextColor.GRAY) + .build(); return text().append(message).hoverEvent(hover).build(); } @@ -93,13 +89,10 @@ private Component getExpireTimeComponent() { @Override public boolean punish(boolean silent) { - getTargetPlayer() - .map(Audience::get) - .ifPresent( - player -> { - this.sendWarning(player, getReason()); - player.sendWarning(getMutedMessage()); - }); + getTargetPlayer().map(Audience::get).ifPresent(player -> { + this.sendWarning(player, getReason()); + player.sendWarning(getMutedMessage()); + }); return getTargetPlayer().isPresent(); } } diff --git a/core/src/main/java/dev/pgm/community/moderation/punishments/types/TempBanPunishment.java b/core/src/main/java/dev/pgm/community/moderation/punishments/types/TempBanPunishment.java index 70bfd19a..9af95f89 100644 --- a/core/src/main/java/dev/pgm/community/moderation/punishments/types/TempBanPunishment.java +++ b/core/src/main/java/dev/pgm/community/moderation/punishments/types/TempBanPunishment.java @@ -3,7 +3,7 @@ import dev.pgm.community.moderation.punishments.PunishmentType; import java.time.Duration; import java.util.UUID; -import javax.annotation.Nullable; +import org.jetbrains.annotations.Nullable; public class TempBanPunishment extends ExpirablePunishment { diff --git a/core/src/main/java/dev/pgm/community/moderation/punishments/types/UsernameBanPunishment.java b/core/src/main/java/dev/pgm/community/moderation/punishments/types/UsernameBanPunishment.java index 8bbbddb2..c12ea0a2 100644 --- a/core/src/main/java/dev/pgm/community/moderation/punishments/types/UsernameBanPunishment.java +++ b/core/src/main/java/dev/pgm/community/moderation/punishments/types/UsernameBanPunishment.java @@ -3,7 +3,7 @@ import dev.pgm.community.moderation.punishments.Punishment; import dev.pgm.community.moderation.punishments.PunishmentType; import java.util.UUID; -import javax.annotation.Nullable; +import org.jetbrains.annotations.Nullable; public class UsernameBanPunishment extends Punishment { diff --git a/core/src/main/java/dev/pgm/community/moderation/punishments/types/WarnPunishment.java b/core/src/main/java/dev/pgm/community/moderation/punishments/types/WarnPunishment.java index c7808199..f18e138b 100644 --- a/core/src/main/java/dev/pgm/community/moderation/punishments/types/WarnPunishment.java +++ b/core/src/main/java/dev/pgm/community/moderation/punishments/types/WarnPunishment.java @@ -4,8 +4,8 @@ import dev.pgm.community.moderation.punishments.PunishmentType; import java.util.Optional; import java.util.UUID; -import javax.annotation.Nullable; import org.bukkit.entity.Player; +import org.jetbrains.annotations.Nullable; import tc.oc.pgm.util.Audience; public class WarnPunishment extends Punishment { diff --git a/core/src/main/java/dev/pgm/community/moderation/services/SQLModerationService.java b/core/src/main/java/dev/pgm/community/moderation/services/SQLModerationService.java index ba500ae8..ebe17141 100644 --- a/core/src/main/java/dev/pgm/community/moderation/services/SQLModerationService.java +++ b/core/src/main/java/dev/pgm/community/moderation/services/SQLModerationService.java @@ -18,7 +18,7 @@ import java.util.Optional; import java.util.UUID; import java.util.concurrent.CompletableFuture; -import javax.annotation.Nullable; +import org.jetbrains.annotations.Nullable; public class SQLModerationService extends SQLFeatureBase implements ModerationQuery { diff --git a/core/src/main/java/dev/pgm/community/mutations/MutationBase.java b/core/src/main/java/dev/pgm/community/mutations/MutationBase.java index 00194184..54bbd2f1 100644 --- a/core/src/main/java/dev/pgm/community/mutations/MutationBase.java +++ b/core/src/main/java/dev/pgm/community/mutations/MutationBase.java @@ -4,10 +4,10 @@ import dev.pgm.community.Community; import dev.pgm.community.mutations.options.MutationOption; import java.util.Collection; -import javax.annotation.Nullable; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; +import org.jetbrains.annotations.Nullable; import tc.oc.pgm.api.match.Match; /** MutationBase - Foundation of all mutations */ diff --git a/core/src/main/java/dev/pgm/community/mutations/types/items/FireworkMutation.java b/core/src/main/java/dev/pgm/community/mutations/types/items/FireworkMutation.java index 6b16bd0c..fa9bfc26 100644 --- a/core/src/main/java/dev/pgm/community/mutations/types/items/FireworkMutation.java +++ b/core/src/main/java/dev/pgm/community/mutations/types/items/FireworkMutation.java @@ -16,7 +16,6 @@ import java.util.UUID; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; -import javax.annotation.Nullable; import org.bukkit.ChatColor; import org.bukkit.Color; import org.bukkit.FireworkEffect; @@ -35,6 +34,7 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.util.Vector; +import org.jetbrains.annotations.Nullable; import tc.oc.pgm.api.match.Match; import tc.oc.pgm.api.match.MatchScope; import tc.oc.pgm.api.player.MatchPlayer; @@ -66,10 +66,9 @@ public FireworkMutation(Match match) { @Override public void enable() { super.enable(); - task = - match - .getExecutor(MatchScope.RUNNING) - .scheduleAtFixedRate(this::task, 0, 250, TimeUnit.MILLISECONDS); + task = match + .getExecutor(MatchScope.RUNNING) + .scheduleAtFixedRate(this::task, 0, 250, TimeUnit.MILLISECONDS); } @Override @@ -156,16 +155,15 @@ private static ItemStack getFirework(@Nullable Color color, Type type, int power Random random = Community.get().getRandom(); ItemStack firework = new ItemStack(Material.FIREWORK); FireworkMeta meta = (FireworkMeta) firework.getItemMeta(); - meta.addEffect( - FireworkEffect.builder() - .withColor( - color != null - ? color - : Color.fromBGR(random.nextInt(255), random.nextInt(255), random.nextInt(255))) - .flicker(false) - .trail(false) - .with(type) - .build()); + meta.addEffect(FireworkEffect.builder() + .withColor( + color != null + ? color + : Color.fromBGR(random.nextInt(255), random.nextInt(255), random.nextInt(255))) + .flicker(false) + .trail(false) + .with(type) + .build()); meta.setDisplayName(ChatColor.GREEN + "Mutation Firework"); meta.setLore(Lists.newArrayList(ChatColor.GRAY + "Launch to make a quick getaway")); meta.addItemFlags(ItemFlag.values()); diff --git a/core/src/main/java/dev/pgm/community/mutations/types/mechanics/MobMutation.java b/core/src/main/java/dev/pgm/community/mutations/types/mechanics/MobMutation.java index 34b5cdd9..933f85b2 100644 --- a/core/src/main/java/dev/pgm/community/mutations/types/mechanics/MobMutation.java +++ b/core/src/main/java/dev/pgm/community/mutations/types/mechanics/MobMutation.java @@ -13,7 +13,6 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; -import javax.annotation.Nullable; import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.entity.Entity; @@ -23,6 +22,7 @@ import org.bukkit.entity.Skeleton.SkeletonType; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.util.Vector; +import org.jetbrains.annotations.Nullable; import tc.oc.pgm.api.match.Match; import tc.oc.pgm.api.party.Party; import tc.oc.pgm.api.player.MatchPlayer; @@ -39,13 +39,12 @@ public class MobMutation extends ScheduledMutationBase { private static final int RANDOM_DISTANCE = 45; private static final String MOB_METADATA = "mob-mutation"; - private static MutationListOption TOTAL_MOBS = - new MutationListOption( - "Total Mobs", - "Total number of mobs spawned", - MutationType.MOBS.getMaterial(), - false, - Lists.newArrayList(25, 50, 100, 125, 200, 250, 300)); + private static MutationListOption TOTAL_MOBS = new MutationListOption( + "Total Mobs", + "Total number of mobs spawned", + MutationType.MOBS.getMaterial(), + false, + Lists.newArrayList(25, 50, 100, 125, 200, 250, 300)); public MobMutation(Match match) { super(match, MutationType.MOBS, UPDATE_DELAY); @@ -93,10 +92,8 @@ private RandomPointProvider getPointProvider() { } if (loc1 != null && loc2 != null) { - return new RandomPointProvider( - Collections.singleton( - new RegionPointProvider( - new CuboidRegion(loc1, loc2), new PointProviderAttributes()))); + return new RandomPointProvider(Collections.singleton( + new RegionPointProvider(new CuboidRegion(loc1, loc2), new PointProviderAttributes()))); } return null; diff --git a/core/src/main/java/dev/pgm/community/nick/commands/NickCommands.java b/core/src/main/java/dev/pgm/community/nick/commands/NickCommands.java index d64c71dc..75284c72 100644 --- a/core/src/main/java/dev/pgm/community/nick/commands/NickCommands.java +++ b/core/src/main/java/dev/pgm/community/nick/commands/NickCommands.java @@ -17,7 +17,6 @@ import java.util.List; import java.util.UUID; import java.util.stream.Collectors; -import javax.annotation.Nullable; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.event.ClickEvent; @@ -26,6 +25,7 @@ import net.kyori.adventure.text.format.TextDecoration; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.jetbrains.annotations.Nullable; import tc.oc.pgm.api.integration.Integration; import tc.oc.pgm.lib.org.incendo.cloud.annotations.Argument; import tc.oc.pgm.lib.org.incendo.cloud.annotations.Command; diff --git a/core/src/main/java/dev/pgm/community/nick/feature/NickFeatureBase.java b/core/src/main/java/dev/pgm/community/nick/feature/NickFeatureBase.java index d2954604..552d16e9 100644 --- a/core/src/main/java/dev/pgm/community/nick/feature/NickFeatureBase.java +++ b/core/src/main/java/dev/pgm/community/nick/feature/NickFeatureBase.java @@ -24,7 +24,6 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; import java.util.logging.Logger; -import javax.annotation.Nullable; import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.format.NamedTextColor; @@ -38,6 +37,7 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerQuitEvent; +import org.jetbrains.annotations.Nullable; import tc.oc.pgm.util.Audience; import tc.oc.pgm.util.text.TextFormatter; diff --git a/core/src/main/java/dev/pgm/community/party/MapParty.java b/core/src/main/java/dev/pgm/community/party/MapParty.java index be71cabe..6531e6fa 100644 --- a/core/src/main/java/dev/pgm/community/party/MapParty.java +++ b/core/src/main/java/dev/pgm/community/party/MapParty.java @@ -6,11 +6,11 @@ import java.time.Duration; import java.time.Instant; import java.util.List; -import javax.annotation.Nullable; import net.kyori.adventure.text.Component; import org.bukkit.command.CommandSender; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; +import org.jetbrains.annotations.Nullable; import tc.oc.pgm.api.map.MapInfo; public interface MapParty { diff --git a/core/src/main/java/dev/pgm/community/party/MapPartyMessages.java b/core/src/main/java/dev/pgm/community/party/MapPartyMessages.java index c6c9443a..21d3cbae 100644 --- a/core/src/main/java/dev/pgm/community/party/MapPartyMessages.java +++ b/core/src/main/java/dev/pgm/community/party/MapPartyMessages.java @@ -13,7 +13,6 @@ import java.time.Duration; import java.time.Instant; import java.util.List; -import javax.annotation.Nullable; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent.Builder; import net.kyori.adventure.text.event.ClickEvent; @@ -21,6 +20,7 @@ import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.ChatColor; import org.bukkit.entity.Player; +import org.jetbrains.annotations.Nullable; import tc.oc.pgm.util.named.NameStyle; import tc.oc.pgm.util.text.TextFormatter; import tc.oc.pgm.util.text.TextTranslations; @@ -51,26 +51,22 @@ public class MapPartyMessages { public static final Component REQUIRE_ONE_MAP_ERROR = text("At least one map is required for the map party to function", NamedTextColor.RED); - public static final Component SET_DESCRIPTION_REMINDER = - text() - .append(text("Don't forget to set a map party description. Click ")) - .append(text("[")) - .append(text("here", NamedTextColor.AQUA)) - .append(text("]")) - .color(NamedTextColor.GRAY) - .clickEvent(ClickEvent.suggestCommand("/event setdesc")) - .hoverEvent( - HoverEvent.showText(text("Click to set event description", NamedTextColor.GRAY))) - .build(); - - public static final Component CREATE_PARTY_BROADCAST = - text() - .append(text("created a new map party")) - .hoverEvent( - HoverEvent.showText(text("Click to view map party info", NamedTextColor.GRAY))) - .clickEvent(ClickEvent.runCommand("/event")) - .color(NamedTextColor.GRAY) - .build(); + public static final Component SET_DESCRIPTION_REMINDER = text() + .append(text("Don't forget to set a map party description. Click ")) + .append(text("[")) + .append(text("here", NamedTextColor.AQUA)) + .append(text("]")) + .color(NamedTextColor.GRAY) + .clickEvent(ClickEvent.suggestCommand("/event setdesc")) + .hoverEvent(HoverEvent.showText(text("Click to set event description", NamedTextColor.GRAY))) + .build(); + + public static final Component CREATE_PARTY_BROADCAST = text() + .append(text("created a new map party")) + .hoverEvent(HoverEvent.showText(text("Click to view map party info", NamedTextColor.GRAY))) + .clickEvent(ClickEvent.runCommand("/event")) + .color(NamedTextColor.GRAY) + .build(); public static Component getAddHostError(Player player) { return text() diff --git a/core/src/main/java/dev/pgm/community/polls/PollBuilder.java b/core/src/main/java/dev/pgm/community/polls/PollBuilder.java index a28febf8..ed4a4552 100644 --- a/core/src/main/java/dev/pgm/community/polls/PollBuilder.java +++ b/core/src/main/java/dev/pgm/community/polls/PollBuilder.java @@ -20,9 +20,9 @@ import java.util.List; import java.util.Set; import java.util.UUID; -import javax.annotation.Nullable; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; +import org.jetbrains.annotations.Nullable; import tc.oc.pgm.api.map.MapInfo; public class PollBuilder { @@ -129,12 +129,11 @@ public boolean remove(CommandAudience sender, String option) { EndAction action = getAction(option); if (action == null) { - sender.sendWarning( - text() - .append(text("No option called '")) - .append(text(option, NamedTextColor.AQUA)) - .append(text("' found.")) - .build()); + sender.sendWarning(text() + .append(text("No option called '")) + .append(text(option, NamedTextColor.AQUA)) + .append(text("' found.")) + .build()); return false; } @@ -162,8 +161,8 @@ public Poll build() { } if (actions.size() == 1) { - poll = - new SingleChoicePoll(question, creator, threshold, duration, actions.iterator().next()); + poll = new SingleChoicePoll( + question, creator, threshold, duration, actions.iterator().next()); } else if (endActions.size() > 1) { threshold = PollThreshold.SIMPLE; poll = new MultiChoicePoll(question, creator, threshold, duration, actions); diff --git a/core/src/main/java/dev/pgm/community/polls/ending/types/NullEndAction.java b/core/src/main/java/dev/pgm/community/polls/ending/types/NullEndAction.java index 9dacf019..edba881d 100644 --- a/core/src/main/java/dev/pgm/community/polls/ending/types/NullEndAction.java +++ b/core/src/main/java/dev/pgm/community/polls/ending/types/NullEndAction.java @@ -4,11 +4,11 @@ import dev.pgm.community.polls.ending.EndAction; import java.util.Objects; -import javax.annotation.Nullable; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.entity.Player; +import org.jetbrains.annotations.Nullable; public class NullEndAction implements EndAction { @@ -63,9 +63,8 @@ public Component getButtonValue(boolean mixed) { public Component getDefaultQuestion() { return text() .append(text("No question defined!", NamedTextColor.RED)) - .hoverEvent( - HoverEvent.showText( - text("Change the end action or define a custom question", NamedTextColor.GRAY))) + .hoverEvent(HoverEvent.showText( + text("Change the end action or define a custom question", NamedTextColor.GRAY))) .build(); } diff --git a/core/src/main/java/dev/pgm/community/requests/commands/RequestCommands.java b/core/src/main/java/dev/pgm/community/requests/commands/RequestCommands.java index 0b174294..35f11e7c 100644 --- a/core/src/main/java/dev/pgm/community/requests/commands/RequestCommands.java +++ b/core/src/main/java/dev/pgm/community/requests/commands/RequestCommands.java @@ -17,7 +17,6 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; -import javax.annotation.Syntax; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.HoverEvent; @@ -45,7 +44,6 @@ public RequestCommands() { @Command("request|req ") @CommandDescription("Request a map") - @Syntax("[map] - Name of map to request") @Permission(CommunityPermissions.REQUEST) public void request( CommandAudience audience, Player sender, @Argument("map") @Greedy MapInfo map) { @@ -59,54 +57,40 @@ public void viewCooldowns( CommandAudience audience, Player sender, @Argument("page") @Default("1") int page) { Map cooldowns = requests.getMapCooldowns(); - List maps = - cooldowns.entrySet().stream() - .filter(e -> !e.getValue().hasExpired()) - .map(e -> e.getKey()) - .collect(Collectors.toList()); + List maps = cooldowns.entrySet().stream() + .filter(e -> !e.getValue().hasExpired()) + .map(e -> e.getKey()) + .collect(Collectors.toList()); - Comparator compare = - (m1, m2) -> { - MapCooldown m1C = cooldowns.get(m1); - MapCooldown m2C = cooldowns.get(m2); - Instant m1D = m1C.getEndTime(); - Instant m2D = m2C.getEndTime(); + Comparator compare = (m1, m2) -> { + MapCooldown m1C = cooldowns.get(m1); + MapCooldown m2C = cooldowns.get(m2); + Instant m1D = m1C.getEndTime(); + Instant m2D = m2C.getEndTime(); - return m2D.compareTo(m1D); - }; + return m2D.compareTo(m1D); + }; maps.sort(compare); int resultsPerPage = 10; int pages = (maps.size() + resultsPerPage - 1) / resultsPerPage; - Component paginated = - TextFormatter.paginate( - text("Active Cooldowns"), - page, - pages, - NamedTextColor.DARK_AQUA, - NamedTextColor.AQUA, - true); + Component paginated = TextFormatter.paginate( + text("Active Cooldowns"), page, pages, NamedTextColor.DARK_AQUA, NamedTextColor.AQUA, true); - Component formattedTitle = - TextFormatter.horizontalLineHeading( - audience.getSender(), paginated, NamedTextColor.DARK_PURPLE, 250); + Component formattedTitle = TextFormatter.horizontalLineHeading( + audience.getSender(), paginated, NamedTextColor.DARK_PURPLE, 250); new PaginatedComponentResults(formattedTitle, resultsPerPage) { @Override public Component format(MapInfo map, int index) { MapCooldown cooldown = cooldowns.get(map); - Component mapName = - map.getStyledName(MapNameStyle.COLOR_WITH_AUTHORS) - .clickEvent(ClickEvent.runCommand("/map " + map.getName())) - .hoverEvent( - HoverEvent.showText( - translatable( - "command.maps.hover", - NamedTextColor.GRAY, - map.getStyledName(MapNameStyle.COLOR)))); + Component mapName = map.getStyledName(MapNameStyle.COLOR_WITH_AUTHORS) + .clickEvent(ClickEvent.runCommand("/map " + map.getName())) + .hoverEvent(HoverEvent.showText(translatable( + "command.maps.hover", NamedTextColor.GRAY, map.getStyledName(MapNameStyle.COLOR)))); return text() .append(mapName) @@ -133,45 +117,35 @@ public void listRequests(CommandAudience audience, @Argument("page") @Default("1 int resultsPerPage = 8; int pages = (requestCounts.size() + resultsPerPage - 1) / resultsPerPage; - Component paginated = - TextFormatter.paginate( - text("Map Requests"), page, pages, NamedTextColor.DARK_AQUA, NamedTextColor.AQUA, true); + Component paginated = TextFormatter.paginate( + text("Map Requests"), page, pages, NamedTextColor.DARK_AQUA, NamedTextColor.AQUA, true); - Component formattedTitle = - TextFormatter.horizontalLineHeading( - audience.getSender(), paginated, NamedTextColor.DARK_PURPLE, 250); + Component formattedTitle = TextFormatter.horizontalLineHeading( + audience.getSender(), paginated, NamedTextColor.DARK_PURPLE, 250); new PaginatedComponentResults(formattedTitle, resultsPerPage) { @Override public Component format(MapInfo map, int index) { - Component mapName = - map.getStyledName(MapNameStyle.COLOR) - .clickEvent(ClickEvent.runCommand("/map " + map.getName())) - .hoverEvent( - HoverEvent.showText( - translatable( - "command.maps.hover", - NamedTextColor.GRAY, - map.getStyledName(MapNameStyle.COLOR)))); + Component mapName = map.getStyledName(MapNameStyle.COLOR) + .clickEvent(ClickEvent.runCommand("/map " + map.getName())) + .hoverEvent(HoverEvent.showText(translatable( + "command.maps.hover", NamedTextColor.GRAY, map.getStyledName(MapNameStyle.COLOR)))); int requestCount = requestCounts.get(map); Component count = text(requestCount, NamedTextColor.DARK_AQUA, TextDecoration.BOLD); - Component setButton = - getRequestsButton( - "Set", "Click to setnext", NamedTextColor.GREEN, "/sn " + map.getName()); - Component voteButton = - getRequestsButton( - "Vote", - "Click to add to the next vote", - NamedTextColor.LIGHT_PURPLE, - "/vote add " + map.getName()); - Component removeButton = - getRequestsButton( - "\u2715", - "Click to remove all requests", - NamedTextColor.RED, - "/reqs clear " + map.getName()); + Component setButton = getRequestsButton( + "Set", "Click to setnext", NamedTextColor.GREEN, "/sn " + map.getName()); + Component voteButton = getRequestsButton( + "Vote", + "Click to add to the next vote", + NamedTextColor.LIGHT_PURPLE, + "/vote add " + map.getName()); + Component removeButton = getRequestsButton( + "\u2715", + "Click to remove all requests", + NamedTextColor.RED, + "/reqs clear " + map.getName()); return text() .append(text((index + 1) + ". ")) @@ -201,13 +175,12 @@ public Component formatEmpty() { public void clearRequests(CommandAudience audience, @Argument("map") @Greedy MapInfo map) { if (map != null) { int removalCount = requests.clearRequests(map); - Component removed = - text() - .append(text(" (")) - .append(text(removalCount, NamedTextColor.RED)) - .append(text(")")) - .color(NamedTextColor.GRAY) - .build(); + Component removed = text() + .append(text(" (")) + .append(text(removalCount, NamedTextColor.RED)) + .append(text(")")) + .color(NamedTextColor.GRAY) + .build(); BroadcastUtils.sendAdminChatMessage( text() .append(audience.getStyledName()) @@ -237,11 +210,10 @@ public void toggleRequests(CommandAudience audience) { text() .append(audience.getStyledName()) .append(text(" has ", NamedTextColor.GRAY)) - .append( - text( - requests.isAccepting() ? "enabled" : "disabled", - requests.isAccepting() ? NamedTextColor.GREEN : NamedTextColor.RED, - TextDecoration.BOLD)) + .append(text( + requests.isAccepting() ? "enabled" : "disabled", + requests.isAccepting() ? NamedTextColor.GREEN : NamedTextColor.RED, + TextDecoration.BOLD)) .append(text(" map requests", NamedTextColor.GRAY)) .build(), CommunityPermissions.REQUEST_STAFF); diff --git a/core/src/main/java/dev/pgm/community/requests/feature/RequestFeature.java b/core/src/main/java/dev/pgm/community/requests/feature/RequestFeature.java index 755a5630..16d8411d 100644 --- a/core/src/main/java/dev/pgm/community/requests/feature/RequestFeature.java +++ b/core/src/main/java/dev/pgm/community/requests/feature/RequestFeature.java @@ -14,12 +14,12 @@ import java.util.Set; import java.util.UUID; import java.util.concurrent.CompletableFuture; -import javax.annotation.Nullable; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextDecoration; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerJoinEvent; +import org.jetbrains.annotations.Nullable; import tc.oc.pgm.api.map.MapInfo; public interface RequestFeature extends Feature { diff --git a/core/src/main/java/dev/pgm/community/requests/feature/RequestFeatureBase.java b/core/src/main/java/dev/pgm/community/requests/feature/RequestFeatureBase.java index f2e9f525..5ec70082 100644 --- a/core/src/main/java/dev/pgm/community/requests/feature/RequestFeatureBase.java +++ b/core/src/main/java/dev/pgm/community/requests/feature/RequestFeatureBase.java @@ -45,7 +45,6 @@ import java.util.concurrent.TimeUnit; import java.util.logging.Logger; import java.util.stream.Collectors; -import javax.annotation.Nullable; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.event.ClickEvent; @@ -58,6 +57,7 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerJoinEvent; +import org.jetbrains.annotations.Nullable; import tc.oc.pgm.api.PGM; import tc.oc.pgm.api.map.MapInfo; import tc.oc.pgm.api.map.MapOrder; diff --git a/core/src/main/java/dev/pgm/community/requests/services/SQLRequestService.java b/core/src/main/java/dev/pgm/community/requests/services/SQLRequestService.java index 097c1f69..c3597d60 100644 --- a/core/src/main/java/dev/pgm/community/requests/services/SQLRequestService.java +++ b/core/src/main/java/dev/pgm/community/requests/services/SQLRequestService.java @@ -12,7 +12,7 @@ import java.util.List; import java.util.UUID; import java.util.concurrent.CompletableFuture; -import javax.annotation.Nullable; +import org.jetbrains.annotations.Nullable; public class SQLRequestService extends SQLFeatureBase implements RequestQuery { diff --git a/core/src/main/java/dev/pgm/community/sessions/services/SQLSessionService.java b/core/src/main/java/dev/pgm/community/sessions/services/SQLSessionService.java index 860bb78c..146c1cfe 100644 --- a/core/src/main/java/dev/pgm/community/sessions/services/SQLSessionService.java +++ b/core/src/main/java/dev/pgm/community/sessions/services/SQLSessionService.java @@ -13,7 +13,7 @@ import java.util.List; import java.util.UUID; import java.util.concurrent.CompletableFuture; -import javax.annotation.Nonnull; +import org.jetbrains.annotations.NotNull; public class SQLSessionService extends SQLFeatureBase implements SessionDataQuery { @@ -25,7 +25,7 @@ public SQLSessionService() { this.sessionCache = CacheBuilder.newBuilder() .build(new CacheLoader() { @Override - public SessionData load(@Nonnull SessionQuery key) { + public SessionData load(@NotNull SessionQuery key) { return new SessionData(key.getPlayerId(), key.ignoreDisguised()); } }); diff --git a/core/src/main/java/dev/pgm/community/teleports/TeleportFeature.java b/core/src/main/java/dev/pgm/community/teleports/TeleportFeature.java index 75a6dc7d..a892c3b0 100644 --- a/core/src/main/java/dev/pgm/community/teleports/TeleportFeature.java +++ b/core/src/main/java/dev/pgm/community/teleports/TeleportFeature.java @@ -6,11 +6,11 @@ import dev.pgm.community.feature.Feature; import dev.pgm.community.utils.CommandAudience; import java.util.Set; -import javax.annotation.Nullable; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.Location; import org.bukkit.entity.Player; +import org.jetbrains.annotations.Nullable; import tc.oc.pgm.util.named.NameStyle; /** TeleportFeature - Teleport players to other locations * */ @@ -19,12 +19,11 @@ public interface TeleportFeature extends Feature { default void teleport( CommandAudience sender, Set targets, Player target, @Nullable Component type) { targets.forEach(player -> teleport(sender, player, target)); - sender.sendMessage( - text("Teleported ") - .append(type != null ? type : text(targets.size())) - .append(text(" to ")) - .append(player(target, NameStyle.FANCY)) - .color(NamedTextColor.GRAY)); + sender.sendMessage(text("Teleported ") + .append(type != null ? type : text(targets.size())) + .append(text(" to ")) + .append(player(target, NameStyle.FANCY)) + .color(NamedTextColor.GRAY)); } default void teleport(CommandAudience sender, Player teleporter, Player target) { @@ -42,12 +41,11 @@ default void teleport(CommandAudience sender, Player teleporter, Location target default void teleport( CommandAudience sender, Set targets, Location target, @Nullable Component type) { targets.forEach(player -> teleport(sender, player, target)); - sender.sendMessage( - text("Teleported ") - .append(type != null ? type : text(targets.size())) - .append(text(" to ")) - .append(formatLocation(target)) - .color(NamedTextColor.GRAY)); + sender.sendMessage(text("Teleported ") + .append(type != null ? type : text(targets.size())) + .append(text(" to ")) + .append(formatLocation(target)) + .color(NamedTextColor.GRAY)); } void teleport( diff --git a/core/src/main/java/dev/pgm/community/users/feature/UsersFeature.java b/core/src/main/java/dev/pgm/community/users/feature/UsersFeature.java index 649e9eb6..20ea5d2c 100644 --- a/core/src/main/java/dev/pgm/community/users/feature/UsersFeature.java +++ b/core/src/main/java/dev/pgm/community/users/feature/UsersFeature.java @@ -11,10 +11,10 @@ import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; -import javax.annotation.Nullable; import net.kyori.adventure.text.Component; import org.bukkit.Bukkit; import org.bukkit.event.player.PlayerJoinEvent; +import org.jetbrains.annotations.Nullable; import tc.oc.pgm.util.named.NameStyle; import tc.oc.pgm.util.player.PlayerComponent; @@ -154,12 +154,11 @@ default void findUserWithSession( String target, boolean ignoreDisguised, UserProfileWithSessionCallback callback) { CompletableFuture profileFuture = getStoredProfile(target); profileFuture.thenAcceptBothAsync( - profileFuture.thenApplyAsync( - profile -> { - if (profile == null) return null; + profileFuture.thenApplyAsync(profile -> { + if (profile == null) return null; - return profile.getLatestSession(ignoreDisguised).join(); - }), + return profile.getLatestSession(ignoreDisguised).join(); + }), (profile, session) -> callback.run(profile, session)); } @@ -175,12 +174,11 @@ default void findUserWithSession( UUID id, boolean ignoreDisguised, UserProfileWithSessionCallback callback) { CompletableFuture profileFuture = getStoredProfile(id); profileFuture.thenAcceptBothAsync( - profileFuture.thenApplyAsync( - profile -> { - if (profile == null) return null; + profileFuture.thenApplyAsync(profile -> { + if (profile == null) return null; - return profile.getLatestSession(ignoreDisguised).join(); - }), + return profile.getLatestSession(ignoreDisguised).join(); + }), (profile, session) -> callback.run(profile, session)); } } diff --git a/core/src/main/java/dev/pgm/community/users/feature/UsersFeatureBase.java b/core/src/main/java/dev/pgm/community/users/feature/UsersFeatureBase.java index 4c7b9b27..ee55ca9c 100644 --- a/core/src/main/java/dev/pgm/community/users/feature/UsersFeatureBase.java +++ b/core/src/main/java/dev/pgm/community/users/feature/UsersFeatureBase.java @@ -10,7 +10,7 @@ import java.util.Optional; import java.util.UUID; import java.util.logging.Logger; -import javax.annotation.Nullable; +import org.jetbrains.annotations.Nullable; public abstract class UsersFeatureBase extends FeatureBase implements UsersFeature { diff --git a/core/src/main/java/dev/pgm/community/utils/BroadcastUtils.java b/core/src/main/java/dev/pgm/community/utils/BroadcastUtils.java index 54ff8173..d663431a 100644 --- a/core/src/main/java/dev/pgm/community/utils/BroadcastUtils.java +++ b/core/src/main/java/dev/pgm/community/utils/BroadcastUtils.java @@ -9,7 +9,6 @@ import dev.pgm.community.CommunityPermissions; import java.util.List; import java.util.function.Predicate; -import javax.annotation.Nullable; import net.kyori.adventure.sound.Sound; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; @@ -19,6 +18,7 @@ import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.jetbrains.annotations.Nullable; import tc.oc.pgm.util.Audience; import tc.oc.pgm.util.bukkit.ViaUtils; @@ -30,12 +30,11 @@ public class BroadcastUtils { public static final Component BROADCAST_DIV = text().append(space()).append(RIGHT_DIV).append(space()).build(); - private static final Component ADMIN_CHAT_PREFIX = - text() - .append(text("[", NamedTextColor.WHITE)) - .append(text("A", NamedTextColor.GOLD)) - .append(text("]", NamedTextColor.WHITE)) - .build(); + private static final Component ADMIN_CHAT_PREFIX = text() + .append(text("[", NamedTextColor.WHITE)) + .append(text("A", NamedTextColor.GOLD)) + .append(text("]", NamedTextColor.WHITE)) + .build(); private static boolean isLocal(String server) { return Community.get().getServerId().equalsIgnoreCase(server); @@ -73,23 +72,21 @@ public static void sendAdminChatMessage( @Nullable String permission) { Component formatted = formatPrefix(server, message); Bukkit.getOnlinePlayers().stream() - .filter( - player -> { - boolean isStaff = player.hasPermission(CommunityPermissions.STAFF); - if (permission != null) { - return isStaff || player.hasPermission(permission); - } - - return isStaff; - }) + .filter(player -> { + boolean isStaff = player.hasPermission(CommunityPermissions.STAFF); + if (permission != null) { + return isStaff || player.hasPermission(permission); + } + + return isStaff; + }) .map(Audience::get) - .forEach( - viewer -> { - viewer.sendMessage(formatted); - if (sound != null) { - viewer.playSound(sound); - } - }); + .forEach(viewer -> { + viewer.sendMessage(formatted); + if (sound != null) { + viewer.playSound(sound); + } + }); Audience.console().sendMessage(formatted); } @@ -107,15 +104,12 @@ public static void sendGlobalMessage(Component message) { } public static void sendGlobalMessage(Component message, @Nullable Sound sound) { - Bukkit.getOnlinePlayers().stream() - .map(Audience::get) - .forEach( - p -> { - p.sendMessage(message); - if (sound != null) { - p.playSound(sound); - } - }); + Bukkit.getOnlinePlayers().stream().map(Audience::get).forEach(p -> { + p.sendMessage(message); + if (sound != null) { + p.playSound(sound); + } + }); Audience.get(Bukkit.getConsoleSender()).sendMessage(message); } @@ -131,24 +125,21 @@ public static void sendGlobalTitle( public static void sendGlobalTitle( @Nullable Component title, @Nullable Component subTitle, int stay, @Nullable Sound sound) { - Bukkit.getOnlinePlayers().stream() - .forEach( - p -> { - Audience viewer = Audience.get(p); - // Support legacy players - if (ViaUtils.getProtocolVersion(p) <= ViaUtils.VERSION_1_7) { - viewer.sendMessage(text().append(title).append(subTitle)); - } - viewer.showTitle( - title( - title == null ? empty() : title, - subTitle == null ? empty() : subTitle, - Times.of(Ticks.duration(5), Ticks.duration(20 * stay), Ticks.duration(15)))); - - if (sound != null) { - viewer.playSound(sound); - } - }); + Bukkit.getOnlinePlayers().stream().forEach(p -> { + Audience viewer = Audience.get(p); + // Support legacy players + if (ViaUtils.getProtocolVersion(p) <= ViaUtils.VERSION_1_7) { + viewer.sendMessage(text().append(title).append(subTitle)); + } + viewer.showTitle(title( + title == null ? empty() : title, + subTitle == null ? empty() : subTitle, + Times.of(Ticks.duration(5), Ticks.duration(20 * stay), Ticks.duration(15)))); + + if (sound != null) { + viewer.playSound(sound); + } + }); } public static void playSelectSound(Sound sound, Predicate filter) { diff --git a/core/src/main/java/dev/pgm/community/utils/CommandAudience.java b/core/src/main/java/dev/pgm/community/utils/CommandAudience.java index 3fa59329..83a3efde 100644 --- a/core/src/main/java/dev/pgm/community/utils/CommandAudience.java +++ b/core/src/main/java/dev/pgm/community/utils/CommandAudience.java @@ -2,11 +2,11 @@ import java.util.Optional; import java.util.UUID; -import javax.annotation.Nullable; import net.kyori.adventure.text.Component; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.jetbrains.annotations.Nullable; import tc.oc.pgm.util.Audience; import tc.oc.pgm.util.named.NameStyle; import tc.oc.pgm.util.player.PlayerComponent; diff --git a/core/src/main/java/dev/pgm/community/utils/ImportUtils.java b/core/src/main/java/dev/pgm/community/utils/ImportUtils.java index c961a04e..03bb6871 100644 --- a/core/src/main/java/dev/pgm/community/utils/ImportUtils.java +++ b/core/src/main/java/dev/pgm/community/utils/ImportUtils.java @@ -20,7 +20,7 @@ import java.util.Date; import java.util.List; import java.util.UUID; -import javax.annotation.Nullable; +import org.jetbrains.annotations.Nullable; import tc.oc.pgm.util.text.TextException; public class ImportUtils { diff --git a/core/src/main/java/dev/pgm/community/utils/NetworkUtils.java b/core/src/main/java/dev/pgm/community/utils/NetworkUtils.java index e8eefea4..055fd6f9 100644 --- a/core/src/main/java/dev/pgm/community/utils/NetworkUtils.java +++ b/core/src/main/java/dev/pgm/community/utils/NetworkUtils.java @@ -4,11 +4,11 @@ import static net.kyori.adventure.text.Component.text; import dev.pgm.community.Community; -import javax.annotation.Nullable; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.format.NamedTextColor; +import org.jetbrains.annotations.Nullable; public class NetworkUtils { @@ -19,13 +19,11 @@ public static String getServer() { public static Component formatServer(String server) { return text() .append(text(server, NamedTextColor.GREEN)) - .hoverEvent( - HoverEvent.showText( - text() - .append(text("Click to join ")) - .append(text(server, NamedTextColor.AQUA)) - .color(NamedTextColor.GRAY) - .build())) + .hoverEvent(HoverEvent.showText(text() + .append(text("Click to join ")) + .append(text(server, NamedTextColor.AQUA)) + .color(NamedTextColor.GRAY) + .build())) .clickEvent(ClickEvent.runCommand("/server " + server)) .build(); } diff --git a/core/src/main/java/dev/pgm/community/utils/PGMUtils.java b/core/src/main/java/dev/pgm/community/utils/PGMUtils.java index 50bdc7aa..220e09af 100644 --- a/core/src/main/java/dev/pgm/community/utils/PGMUtils.java +++ b/core/src/main/java/dev/pgm/community/utils/PGMUtils.java @@ -5,11 +5,11 @@ import java.util.List; import java.util.Optional; import java.util.stream.Collectors; -import javax.annotation.Nullable; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.Nullable; import tc.oc.pgm.api.PGM; import tc.oc.pgm.api.map.MapInfo; import tc.oc.pgm.api.match.Match; diff --git a/core/src/main/java/dev/pgm/community/utils/WebUtils.java b/core/src/main/java/dev/pgm/community/utils/WebUtils.java index 5f972b07..41d55ee5 100644 --- a/core/src/main/java/dev/pgm/community/utils/WebUtils.java +++ b/core/src/main/java/dev/pgm/community/utils/WebUtils.java @@ -1,6 +1,6 @@ package dev.pgm.community.utils; -import static com.google.common.base.Preconditions.checkNotNull; +import static tc.oc.pgm.util.Assert.assertNotNull; import com.google.common.collect.Lists; import com.google.gson.Gson; @@ -17,8 +17,8 @@ import java.util.List; import java.util.UUID; import java.util.concurrent.CompletableFuture; -import javax.annotation.Nullable; import org.bukkit.Skin; +import org.jetbrains.annotations.Nullable; public class WebUtils { @@ -28,56 +28,51 @@ public class WebUtils { /** Fetch a list of random minecraft usernames */ public static CompletableFuture> getRandomNameList(int size) { - return CompletableFuture.supplyAsync( - () -> { - List names = Lists.newArrayList(); - for (int i = 0; i < size; i++) { - names.add(getRandomName().join()); - } - return names; - }); + return CompletableFuture.supplyAsync(() -> { + List names = Lists.newArrayList(); + for (int i = 0; i < size; i++) { + names.add(getRandomName().join()); + } + return names; + }); } /** Fetch a random minecraft username */ public static CompletableFuture getRandomName() { - return CompletableFuture.supplyAsync( - () -> { - String response = "ERROR_404"; - HttpURLConnection url; - try { - url = (HttpURLConnection) new URL(RANDOM_NAME_API).openConnection(); - - url.setRequestMethod("GET"); - url.setRequestProperty("User-Agent", "Community"); - url.setInstanceFollowRedirects(true); - url.setConnectTimeout(10000); - url.setReadTimeout(10000); - - try (final BufferedReader br = - new BufferedReader( - new InputStreamReader(url.getInputStream(), StandardCharsets.UTF_8))) { - response = br.readLine().trim(); - } - } catch (IOException e) { - e.printStackTrace(); - } - - return response; - }); + return CompletableFuture.supplyAsync(() -> { + String response = "ERROR_404"; + HttpURLConnection url; + try { + url = (HttpURLConnection) new URL(RANDOM_NAME_API).openConnection(); + + url.setRequestMethod("GET"); + url.setRequestProperty("User-Agent", "Community"); + url.setInstanceFollowRedirects(true); + url.setConnectTimeout(10000); + url.setReadTimeout(10000); + + try (final BufferedReader br = new BufferedReader( + new InputStreamReader(url.getInputStream(), StandardCharsets.UTF_8))) { + response = br.readLine().trim(); + } + } catch (IOException e) { + e.printStackTrace(); + } + + return response; + }); } public static CompletableFuture getSkin(String input) { - return getProfile(input) - .thenApplyAsync( - profile -> { - if (profile == null || !profile.get("textures").isJsonObject()) { - return null; - } - JsonObject texture = profile.get("textures").getAsJsonObject(); - String data = texture.get("raw").getAsJsonObject().get("value").getAsString(); - String sign = texture.get("raw").getAsJsonObject().get("signature").getAsString(); - return new Skin(data, sign); - }); + return getProfile(input).thenApplyAsync(profile -> { + if (profile == null || !profile.get("textures").isJsonObject()) { + return null; + } + JsonObject texture = profile.get("textures").getAsJsonObject(); + String data = texture.get("raw").getAsJsonObject().get("value").getAsString(); + String sign = texture.get("raw").getAsJsonObject().get("signature").getAsString(); + return new Skin(data, sign); + }); } public static CompletableFuture getUsernameHistory(String input) { @@ -95,12 +90,11 @@ public static UsernameHistory of(JsonObject profile) { List history = Lists.newArrayList(); JsonArray names = profile.get("username_history").getAsJsonArray(); - names.forEach( - name -> { - if (name.isJsonObject() && name.getAsJsonObject().entrySet().size() > 1) { - history.add(new NameEntry(name.getAsJsonObject())); - } - }); + names.forEach(name -> { + if (name.isJsonObject() && name.getAsJsonObject().entrySet().size() > 1) { + history.add(new NameEntry(name.getAsJsonObject())); + } + }); return new UsernameHistory(current, UUID.fromString(uuid), history); } @@ -150,34 +144,32 @@ public Instant getDateChanged() { /** Get profile data of provided username/uuid * */ private static CompletableFuture getProfile(String input) { - return CompletableFuture.supplyAsync( - () -> { - JsonObject obj = null; - HttpURLConnection url; - try { - url = (HttpURLConnection) new URL(USERNAME_API + checkNotNull(input)).openConnection(); - - url.setRequestMethod("GET"); - url.setRequestProperty("User-Agent", "Community"); - url.setRequestProperty("Accept", "application/json"); - url.setInstanceFollowRedirects(true); - url.setConnectTimeout(10000); - url.setReadTimeout(10000); - - StringBuilder data = new StringBuilder(); - try (final BufferedReader br = - new BufferedReader( - new InputStreamReader(url.getInputStream(), StandardCharsets.UTF_8))) { - String line; - while ((line = br.readLine()) != null) { - data.append(line.trim()); - } - obj = new Gson().fromJson(data.toString(), JsonObject.class); - } - } catch (IOException e) { - Community.log("%s", e.getMessage()); + return CompletableFuture.supplyAsync(() -> { + JsonObject obj = null; + HttpURLConnection url; + try { + url = (HttpURLConnection) new URL(USERNAME_API + assertNotNull(input)).openConnection(); + + url.setRequestMethod("GET"); + url.setRequestProperty("User-Agent", "Community"); + url.setRequestProperty("Accept", "application/json"); + url.setInstanceFollowRedirects(true); + url.setConnectTimeout(10000); + url.setReadTimeout(10000); + + StringBuilder data = new StringBuilder(); + try (final BufferedReader br = new BufferedReader( + new InputStreamReader(url.getInputStream(), StandardCharsets.UTF_8))) { + String line; + while ((line = br.readLine()) != null) { + data.append(line.trim()); } - return obj; - }); + obj = new Gson().fromJson(data.toString(), JsonObject.class); + } + } catch (IOException e) { + Community.log("%s", e.getMessage()); + } + return obj; + }); } } diff --git a/core/src/main/java/dev/pgm/community/utils/ranks/RankUtils.java b/core/src/main/java/dev/pgm/community/utils/ranks/RankUtils.java index 710c52f3..784e6273 100644 --- a/core/src/main/java/dev/pgm/community/utils/ranks/RankUtils.java +++ b/core/src/main/java/dev/pgm/community/utils/ranks/RankUtils.java @@ -2,8 +2,8 @@ import dev.pgm.community.Community; import java.util.List; -import javax.annotation.Nullable; import org.bukkit.entity.Player; +import org.jetbrains.annotations.Nullable; public class RankUtils { diff --git a/pom.xml b/pom.xml index 916f1074..68650f1b 100644 --- a/pom.xml +++ b/pom.xml @@ -165,6 +165,59 @@ + + org.apache.maven.plugins + maven-enforcer-plugin + 3.2.1 + + + de.skuzzle.enforcer + restrict-imports-enforcer-rule + 2.1.0 + + + + + + enforce-jdk + + enforce + + + + + + [${maven.compiler.target},) + + + + + + + enforce-imports + process-sources + + enforce + + + + + Use org.jetbrains.annotations to add annotations + javax.annotation.** + + + Use tc.oc.pgm.util.Assert to add assertions + + com.google.common.base.Preconditions.** + java.util.Objects.requireNonNull + + + + + + + + org.apache.maven.plugins