Skip to content

Commit

Permalink
Add import restriction to match pgm
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher White <[email protected]>
  • Loading branch information
cswhite2000 committed Nov 22, 2024
1 parent dd90576 commit 118c9a8
Show file tree
Hide file tree
Showing 41 changed files with 527 additions and 591 deletions.
72 changes: 32 additions & 40 deletions core/src/main/java/dev/pgm/community/CommunityCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -69,11 +69,10 @@ public Set<Player> getPlayers() {
}

public Component getText() {
List<Component> names =
players.stream()
.map(p -> player(p, NameStyle.FANCY))
.limit(Math.min(players.size(), 10))
.collect(Collectors.toList());
List<Component> 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()) {
Expand Down Expand Up @@ -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("=");

Expand All @@ -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) {
Expand All @@ -145,21 +141,19 @@ 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) {
throw TextException.exception(teamName + " is not a valid team name");
}
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");
Expand All @@ -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
Expand Down Expand Up @@ -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<UUID> cachedId =
service.getId(
target); // If user is online or was online recently, we will have their UUID.
Optional<UUID> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@
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;
import net.kyori.adventure.text.format.NamedTextColor;
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;
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/dev/pgm/community/database/Query.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down
Loading

0 comments on commit 118c9a8

Please sign in to comment.