Skip to content

Commit

Permalink
Move Community logic to core mvn module
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher White <[email protected]>
  • Loading branch information
cswhite2000 committed Nov 18, 2024
1 parent 7b3e9ba commit fd58471
Show file tree
Hide file tree
Showing 337 changed files with 3,670 additions and 4,249 deletions.
171 changes: 171 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<relativePath>../pom.xml</relativePath>
<version>0.2-SNAPSHOT</version>
<groupId>dev.pgm</groupId>
<artifactId>Community</artifactId>
</parent>

<name>Core</name>
<artifactId>core</artifactId>
<packaging>jar</packaging>

<dependencies>
<!-- SportBukkit 1.8 -->
<dependency>
<groupId>app.ashcon</groupId>
<artifactId>sportpaper</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

<!-- PGM Utils -->
<dependency>
<groupId>tc.oc.pgm</groupId>
<artifactId>util</artifactId>
<version>0.16-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>tc.oc.pgm</groupId>
<artifactId>core</artifactId>
<version>0.16-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

<!-- Database Operations -->
<dependency>
<groupId>co.aikar</groupId>
<artifactId>idb-core</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>co.aikar</groupId>
<artifactId>idb-bukkit</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>

<!-- Redis -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.5.1</version>
<type>jar</type>
<scope>compile</scope>
</dependency>

<!-- Smart Invs - https://github.com/MinusKube/SmartInvs -->
<dependency>
<groupId>fr.minuskube.inv</groupId>
<artifactId>smart-invs</artifactId>
<version>1.2.7</version>
</dependency>

<!-- Environment -->
<dependency>
<groupId>tc.oc.occ</groupId>
<artifactId>Environment</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>

<!-- AFK Detection -->
<dependency>
<groupId>tc.oc.occ</groupId>
<artifactId>AFK</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

</dependencies>

<build>
<finalName>Community</finalName>
<resources>
<!-- Include the required plugin.yml and config.yml for Bukkit -->
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.incendo</groupId>
<artifactId>cloud-annotations</artifactId>
<version>2.0.0-rc.2</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<minimizeJar>true</minimizeJar>
<artifactSet>
<includes>
<include>net.kyori:*:*</include>
<include>co.aikar:*</include>
<include>tc.oc.pgm:util</include>
<include>redis.clients:jedis</include>
<include>org.apache.commons:commons-pool2</include>
<include>fr.minuskube.inv:smart-invs</include>
<include>com.zaxxer:HikariCP</include>
<include>org.slf4j:*</include>
</includes>
</artifactSet>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/**</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>jar</id>
<phase>package</phase>
<configuration>
<target>
<copy file="${basedir}/target/${project.build.finalName}.jar"
tofile="../target/Community.jar"/>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
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
Loading

0 comments on commit fd58471

Please sign in to comment.