Skip to content

Commit

Permalink
Add player party system (#71)
Browse files Browse the repository at this point in the history
Signed-off-by: applenick <[email protected]>
  • Loading branch information
applenick authored Aug 2, 2024
1 parent f323929 commit 4c4c177
Show file tree
Hide file tree
Showing 17 changed files with 945 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Community offers an all-in-one solution for managing Minecraft PGM server commun
- Nickname System
- Map Party System
- Match Mutations
- Player Party/Squad System
- Polls
- Cross-Server Chat & Report Functionality
- Utility Commands

Expand Down
9 changes: 9 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@
<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>
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/dev/pgm/community/Community.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dev.pgm.community.database.DatabaseConnection;
import dev.pgm.community.events.CommunityEvent;
import dev.pgm.community.feature.FeatureManager;
import dev.pgm.community.text.TextTranslations;
import dev.pgm.community.utils.PGMUtils;
import fr.minuskube.inv.InventoryManager;
import java.util.Random;
Expand Down Expand Up @@ -77,11 +78,16 @@ private void setupInventory() {
this.inventory.init();
}

private void setupTranslations() {
TextTranslations.load();
}

public void registerListener(Listener listener) {
getServer().getPluginManager().registerEvents(listener, this);
}

private void setupFeatures() {
this.setupTranslations();
this.setupInventory();
this.features = new FeatureManager(getConfig(), getLogger(), database, inventory);
this.setupCommands();
Expand Down Expand Up @@ -126,8 +132,7 @@ public void callEvent(CommunityEvent event) {
// REMOVE WHEN NOT IN DEV
public static void log(String format, Object... objects) {
Bukkit.getConsoleSender()
.sendMessage(
ChatColor.translateAlternateColorCodes(
'&', String.format("&7[&4Community&7]&r " + format, objects)));
.sendMessage(ChatColor.translateAlternateColorCodes(
'&', String.format("&7[&4Community&7]&r " + format, objects)));
}
}
4 changes: 4 additions & 0 deletions src/main/java/dev/pgm/community/CommunityPermissions.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ public interface CommunityPermissions {
// Polls
String POLL = ROOT + ".poll";

// Squads
String SQUAD = ROOT + ".squad"; // Access to squad commands
String SQUAD_CREATE = SQUAD + ".create"; // Can create a squad

// General Commands
String FLIGHT = ROOT + ".fly";
String FLIGHT_SPEED = FLIGHT + ".speed";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@
import dev.pgm.community.requests.commands.sponsor.TokenCommands;
import dev.pgm.community.requests.commands.supervotes.SuperVoteAdminCommands;
import dev.pgm.community.requests.commands.supervotes.SuperVoteCommand;
import dev.pgm.community.squads.SquadCommands;
import dev.pgm.community.teleports.TeleportCommand;
import dev.pgm.community.users.commands.UserInfoCommands;
import dev.pgm.community.utils.CommandAudience;
import org.bukkit.GameMode;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import tc.oc.pgm.api.PGM;
Expand All @@ -55,6 +57,8 @@
import tc.oc.pgm.command.injectors.PlayerProvider;
import tc.oc.pgm.command.parsers.EnumParser;
import tc.oc.pgm.command.parsers.MapInfoParser;
import tc.oc.pgm.command.parsers.MatchPlayerParser;
import tc.oc.pgm.command.parsers.OfflinePlayerParser;
import tc.oc.pgm.command.parsers.PartyParser;
import tc.oc.pgm.command.parsers.PlayerParser;
import tc.oc.pgm.command.util.CommandGraph;
Expand Down Expand Up @@ -92,6 +96,8 @@ protected void setupParsers() {
registerParser(Player.class, new PlayerParser());
registerParser(Party.class, PartyParser::new);
registerParser(GameMode.class, new GameModeParser());
registerParser(OfflinePlayer.class, new OfflinePlayerParser());
registerParser(MatchPlayer.class, new MatchPlayerParser());
}

@Override
Expand Down Expand Up @@ -143,6 +149,9 @@ protected void registerCommands() {
register(new SuperVoteCommand());
register(new SuperVoteAdminCommands());

// Squads
register(new SquadCommands());

// Teleport
register(new TeleportCommand());

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/dev/pgm/community/feature/FeatureManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import dev.pgm.community.requests.feature.types.SQLRequestFeature;
import dev.pgm.community.sessions.feature.SessionFeature;
import dev.pgm.community.sessions.feature.types.SQLSessionFeature;
import dev.pgm.community.squads.SquadFeature;
import dev.pgm.community.teleports.TeleportFeature;
import dev.pgm.community.teleports.TeleportFeatureBase;
import dev.pgm.community.users.feature.UsersFeature;
Expand Down Expand Up @@ -56,6 +57,7 @@ public class FeatureManager {
private final MobFeature mob;
private final MapPartyFeature party;
private final PollFeature polls;
private final SquadFeature squads;

public FeatureManager(
Configuration config,
Expand Down Expand Up @@ -91,6 +93,7 @@ public FeatureManager(
this.mob = new MobFeature(config, logger);
this.party = new MapPartyFeature(config, logger);
this.polls = new PollFeature(config, logger);
this.squads = new SquadFeature(config, logger);
}

public AssistanceFeature getReports() {
Expand Down Expand Up @@ -165,6 +168,10 @@ public PollFeature getPolls() {
return polls;
}

public SquadFeature getSquads() {
return squads;
}

public void reloadConfig(Configuration config) {
// Reload all config values here
getReports().getConfig().reload(config);
Expand All @@ -184,6 +191,7 @@ public void reloadConfig(Configuration config) {
getMobs().getConfig().reload(config);
getParty().getConfig().reload(config);
getPolls().getConfig().reload(config);
getSquads().getConfig().reload(config);
// TODO: Look into maybe unregister commands for features that have been disabled
// commands#unregisterCommand
// Will need to check isEnabled
Expand All @@ -207,5 +215,6 @@ public void disable() {
if (getMobs().isEnabled()) getMobs().disable();
if (getParty().isEnabled()) getParty().disable();
if (getPolls().isEnabled()) getPolls().disable();
if (getSquads().isEnabled()) getSquads().disable();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public CompletableFuture<List<Punishment>> queryList(String target) {
long expires = DatabaseUtils.parseLong(row, "expires");
Duration length =
Duration.between(Instant.ofEpochMilli(time), Instant.ofEpochMilli(expires));
boolean active = row.get("active");
boolean active = DatabaseUtils.parseBoolean(row, "active");
long lastUpdateTime = DatabaseUtils.parseLong(row, "last_updated");
String lastUpdateBy = row.getString("updated_by");
String service = row.getString("service");
Expand Down
85 changes: 85 additions & 0 deletions src/main/java/dev/pgm/community/squads/Squad.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package dev.pgm.community.squads;

import com.google.common.collect.Iterables;
import java.util.*;

public class Squad {
private UUID leader;
private final Set<UUID> players;
private final Set<UUID> invites;

public Squad(UUID leader) {
this.leader = leader;
this.players = new LinkedHashSet<>();
this.invites = new HashSet<>();
players.add(leader);
}

public UUID getLeader() {
return leader;
}

public Set<UUID> getPlayers() {
// This is READ ONLY. to modify members use the appropriate methods
return Collections.unmodifiableSet(players);
}

public Set<UUID> getInvites() {
return Collections.unmodifiableSet(invites);
}

public Iterable<UUID> getAllPlayers() {
// This is READ ONLY. to modify members use the appropriate methods
return Iterables.concat(getPlayers(), getInvites());
}

public boolean removePlayer(UUID player) {
boolean result = players.remove(player);
if (result && Objects.equals(leader, player) && !players.isEmpty()) {
leader = players.iterator().next();
}
return result;
}

public boolean addPlayer(UUID player) {
if (leader == null) leader = player;
return players.add(player);
}

public boolean containsPlayer(UUID player) {
return players.contains(player);
}

public boolean containsInvite(UUID player) {
return invites.contains(player);
}

public boolean addInvite(UUID player) {
return !players.contains(player) && invites.add(player);
}

public boolean acceptInvite(UUID player) {
return invites.remove(player) && addPlayer(player);
}

public boolean expireInvite(UUID player) {
return invites.remove(player);
}

public int size() {
return players.size();
}

public int totalSize() {
return players.size() + invites.size();
}

public boolean isEmpty() {
return players.isEmpty();
}

@Override
public String toString() {
return "Squad{" + "leader=" + leader + ", players=" + players + '}';
}
}
Loading

0 comments on commit 4c4c177

Please sign in to comment.