Skip to content

Commit

Permalink
Added /follow
Browse files Browse the repository at this point in the history
  • Loading branch information
Devlrxxh committed Apr 1, 2024
1 parent d8f117e commit f5965bf
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 17 deletions.
3 changes: 3 additions & 0 deletions src/main/java/me/lrxh/practice/Locale.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public enum Locale {
OPTIONS_SHOW_PLAYERS_ENABLED("OPTIONS.SHOWPLAYERS_ENABLED"),
OPTIONS_SHOW_PLAYERS_DISABLED("OPTIONS.SHOWPLAYERS_DISABLED"),
SILENT_ENABLED("OPTIONS.SILENT_ENABLED"),
FOLLOW_START("FOLLOW.FOLLOW_START"),
FOLLOW_END("FOLLOW.FOLLOW_END"),
FOLLOWED_LEFT("FOLLOW.FOLLOWED_LEFT"),
SILENT_DISABLED("OPTIONS.SILENT_DISABLED");
private final String path;

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/me/lrxh/practice/Practice.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import me.lrxh.practice.arena.Arena;
import me.lrxh.practice.arena.ArenaListener;
import me.lrxh.practice.arena.command.ArenaCommand;
import me.lrxh.practice.commands.admin.general.FollowCommand;
import me.lrxh.practice.commands.admin.general.MainCommand;
import me.lrxh.practice.commands.admin.general.SilentCommand;
import me.lrxh.practice.commands.donater.FlyCommand;
Expand Down Expand Up @@ -213,7 +214,8 @@ private void registerCommands() {
new SpectateCommand(),
new PartyCommand(),
new EloCommand(),
new SilentCommand()
new SilentCommand(),
new FollowCommand()
).forEach(command -> paperCommandManager.registerCommand(command));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package me.lrxh.practice.commands.admin.general;

import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.*;
import me.lrxh.practice.Locale;
import me.lrxh.practice.profile.Profile;
import me.lrxh.practice.util.CC;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

@CommandAlias("follow")
@Description("Follow a player.")
@CommandPermission("practice.admin.follow")
public class FollowCommand extends BaseCommand {


@Default
@Syntax("<name>")
@CommandCompletion("@names")
public void pingOthers(Player player, String otherPlayer) {
if (Bukkit.getPlayer(otherPlayer) == null) {
player.sendMessage(CC.translate("&4ERROR - &cPlayer isn't online!"));
return;
}
if (Bukkit.getPlayer(otherPlayer).equals(player)) {
player.sendMessage(CC.translate("&4ERROR - &cYou can't follow yourself!"));
return;
}
Profile playerProfile = Profile.getProfiles().get(player.getUniqueId());
if (!playerProfile.getFollowing().isEmpty() && !playerProfile.getFollowing().contains(player.getUniqueId())) {
player.sendMessage(CC.translate("&4ERROR - &cYou can't follow multiple players!"));
return;
}

Player otherP = Bukkit.getPlayer(otherPlayer);
Profile profile = Profile.getProfiles().get(otherP.getUniqueId());

if (profile.getFollowers().contains(player.getUniqueId())) {
profile.getFollowers().remove(player.getUniqueId());
playerProfile.getFollowing().remove(otherP.getUniqueId());
player.sendMessage(Locale.FOLLOW_END.format(player, otherP.getName()));
} else {
profile.getFollowers().add(player.getUniqueId());
playerProfile.getFollowing().add(otherP.getUniqueId());
player.sendMessage(Locale.FOLLOW_START.format(player, otherP.getName()));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package me.lrxh.practice.commands.admin.general;

import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.*;
import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.CommandPermission;
import co.aikar.commands.annotation.Default;
import co.aikar.commands.annotation.Description;
import me.lrxh.practice.Locale;
import me.lrxh.practice.Practice;
import me.lrxh.practice.profile.Profile;
import me.lrxh.practice.util.CC;
import me.lrxh.practice.util.LocationUtil;
import org.bukkit.Location;
import org.bukkit.entity.Player;

import java.io.IOException;


@CommandAlias("silent")
@CommandPermission("practice.admin.silent")
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/me/lrxh/practice/commands/user/EloCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ public class EloCommand extends BaseCommand {
@Default
public void elo(Player player) {
Profile profile = Profile.getProfiles().get(player.getUniqueId());
player.sendMessage(CC.translate("&f&m---------------------------"));
player.sendMessage(" ");
player.sendMessage(CC.translate("&f&m---------------------"));
player.sendMessage(CC.translate("&eYour elo!"));
for (Queue queue : Practice.getInstance().getCache().getQueues()) {
if (queue.isRanked()) {
player.sendMessage(CC.translate("&c• &e" + queue.getKit().getName() + "&7: &f" + profile.getKitData().get(queue.getKit()).getElo()));
}
}
player.sendMessage(CC.translate("&f&m---------------------------"));

player.sendMessage(CC.translate("&f&m---------------------"));
player.sendMessage(" ");
}

@Default
Expand All @@ -37,13 +38,15 @@ public void pingOthers(Player player, String otherPlayer) {
}
Player otherP = Bukkit.getPlayer(otherPlayer);
Profile profile = Profile.getProfiles().get(otherP.getUniqueId());
player.sendMessage(CC.translate("&f&m---------------------------"));
player.sendMessage(" ");
player.sendMessage(CC.translate("&f&m---------------------"));
player.sendMessage(CC.translate("&e" + otherPlayer + "'s elo!"));
for (Queue queue : Practice.getInstance().getCache().getQueues()) {
if (queue.isRanked()) {
player.sendMessage(CC.translate("&c• &e" + queue.getKit().getName() + "&7: &f" + profile.getKitData().get(queue.getKit()).getElo()));
}
}
player.sendMessage(CC.translate("&f&m---------------------------"));
player.sendMessage(CC.translate("&f&m---------------------"));
player.sendMessage(" ");
}
}
16 changes: 14 additions & 2 deletions src/main/java/me/lrxh/practice/match/Match.java
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ public void onRoundStart() {
// Reset snapshots
snapshots.clear();
timeData = System.currentTimeMillis() - timeData;

checkFollowers();
// Reset each game participant
for (GameParticipant<MatchGamePlayer> gameParticipant : getParticipants()) {
gameParticipant.reset();
Expand Down Expand Up @@ -551,7 +551,7 @@ public void addSpectator(Player spectator, Player target) {

if (bukkitPlayer != null) {
VisibilityLogic.handle(bukkitPlayer);
if(!profile.isSilent()){
if (!profile.isSilent()) {
bukkitPlayer.sendMessage(Locale.MATCH_NOW_SPECTATING.format(bukkitPlayer, spectator.getName()));
}
}
Expand Down Expand Up @@ -623,6 +623,18 @@ public void sendSound(Sound sound, float volume, float pitch) {
}
}

public void checkFollowers() {
for (GameParticipant<MatchGamePlayer> gameParticipant : getParticipants()) {
for (GamePlayer gamePlayer : gameParticipant.getPlayers()) {
if (!Profile.getByUuid(gamePlayer.getUuid()).getFollowers().isEmpty()) {
for (UUID playerUUID : Profile.getByUuid(gamePlayer.getUuid()).getFollowers()) {
Bukkit.getPlayer(playerUUID).chat("/spec " + gamePlayer.getUsername());
}
}
}
}
}

protected List<Player> getSpectatorsAsPlayers() {
List<Player> players = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public MatchLogicTask(Match match) {
}
}


@Override
public void run() {
nextAction--;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/me/lrxh/practice/profile/Profile.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public class Profile {
private final List<DuelRequest> duelRequests;
private final UUID uuid;
private final String username;
private final List<UUID> followers;
private final List<UUID> following;
private ProfileState state;
private DuelProcedure duelProcedure;
private ProfileRematchData rematchData;
Expand All @@ -53,6 +55,7 @@ public class Profile {
private Cooldown enderpearlCooldown;
private Cooldown voteCooldown;
private boolean silent = false;

public Profile(UUID uuid) {
this.uuid = uuid;
this.username = Bukkit.getPlayer(uuid).getName();
Expand All @@ -61,6 +64,8 @@ public Profile(UUID uuid) {
this.kitEditorData = new ProfileKitEditorData();
this.kitData = new HashMap<>();
this.duelRequests = new ArrayList<>();
this.followers = new ArrayList<>();
this.following = new ArrayList<>();
this.enderpearlCooldown = new Cooldown(0);
this.voteCooldown = new Cooldown(0);

Expand Down
22 changes: 22 additions & 0 deletions src/main/java/me/lrxh/practice/profile/ProfileListener.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.lrxh.practice.profile;

import me.lrxh.practice.Locale;
import me.lrxh.practice.Practice;
import me.lrxh.practice.profile.hotbar.HotbarItem;
import me.lrxh.practice.profile.meta.option.button.AllowSpectatorsOptionButton;
Expand All @@ -23,6 +24,8 @@
import org.bukkit.scheduler.BukkitRunnable;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class ProfileListener implements Listener {

Expand Down Expand Up @@ -159,6 +162,25 @@ public void onPlayerQuitEvent(PlayerQuitEvent event) {
event.setQuitMessage(null);

Profile profile = Profile.getProfiles().get(event.getPlayer().getUniqueId());

if (!profile.getFollowers().isEmpty()) {
for (UUID playerUUID : profile.getFollowers()) {
Bukkit.getPlayer(playerUUID).sendMessage(Locale.FOLLOWED_LEFT.format(Bukkit.getPlayer(playerUUID), event.getPlayer().getName()));
}
}

if (!profile.getFollowing().isEmpty()) {
List<UUID> followingCopy = new ArrayList<>(profile.getFollowing());

for (UUID playerUUID : followingCopy) {
Profile followerProfile = Profile.getByUuid(playerUUID);
followerProfile.getFollowers().remove(event.getPlayer().getUniqueId());

profile.getFollowing().remove(playerUUID);
}
}


new BukkitRunnable() {
@Override
public void run() {
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/me/lrxh/practice/util/PlaceholderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,22 @@ public static List<String> format(List<String> lines, Player player) {
line = line.replaceAll("<ping>", String.valueOf((BukkitReflection.getPing(player))));
line = line.replaceAll("<theme>", CC.translate("&" + profile.getOptions().theme().getColor().getChar()));

if (line.contains("<silent>") && !profile.isSilent()){
if (line.contains("<silent>") && !profile.isSilent()) {
continue;
}else{
} else {
line = line.replaceAll("<silent>", "&7&lSilent Mode");
}
if (line.contains("<follow>") && profile.getFollowing().isEmpty()) {
continue;
} else {
line = line.replaceAll("<follow>", "");
}

if (!profile.getFollowing().isEmpty()) {
line = line.replaceAll("<followedPlayer>", Bukkit.getPlayer(profile.getFollowing().get(0)).getName());
} else {
line = line.replaceAll("<followedPlayer>", "");
}

if (profile.getState() == ProfileState.QUEUEING) {
line = line.replaceAll("<kit>", queueProfile.getQueue().getKit().getName());
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ OPTIONS:
MENU_SOUNDS_DISABLED: '&cDisabled Menu sounds!'
SILENT_ENABLED: '&aEnabled Silent Mode!'
SILENT_DISABLED: '&cDisabled Silent Mode!'
FOLLOW_START: '&bStarted following &f{0}.'
FOLLOW_END: '&bStopped following &f{0}.'
LEADERBOARD:
MESSAGE: '&aLeaderboards Refreshed!'
FOLLOW:
FOLLOW_START: '&bStarted following &f{0}.'
FOLLOW_END: '&bStopped following &f{0}.'
FOLLOWED_LEFT: '&b{0} &left.'
PARTY:
HELP:
- '&7&m------------------------------------------------'
Expand Down

0 comments on commit f5965bf

Please sign in to comment.