Skip to content

Commit

Permalink
Added /elo command
Browse files Browse the repository at this point in the history
  • Loading branch information
Devlrxxh committed Apr 1, 2024
1 parent 784ba0f commit 337dbb8
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 16 deletions.
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 @@ -14,6 +14,7 @@
import me.lrxh.practice.arena.command.ArenaCommand;
import me.lrxh.practice.commands.admin.general.MainCommand;
import me.lrxh.practice.commands.donater.FlyCommand;
import me.lrxh.practice.commands.user.EloCommand;
import me.lrxh.practice.commands.user.PingCommand;
import me.lrxh.practice.commands.user.StatsCommand;
import me.lrxh.practice.commands.user.duels.DuelCommand;
Expand Down Expand Up @@ -209,7 +210,8 @@ private void registerCommands() {
new RematchCommand(),
new ViewInventoryCommand(),
new SpectateCommand(),
new PartyCommand()
new PartyCommand(),
new EloCommand()
).forEach(command -> paperCommandManager.registerCommand(command));
}

Expand Down
52 changes: 52 additions & 0 deletions src/main/java/me/lrxh/practice/commands/user/EloCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package me.lrxh.practice.commands.user;

import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.*;
import me.lrxh.practice.Locale;
import me.lrxh.practice.Practice;
import me.lrxh.practice.match.Match;
import me.lrxh.practice.profile.Profile;
import me.lrxh.practice.queue.Queue;
import me.lrxh.practice.util.BukkitReflection;
import me.lrxh.practice.util.CC;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

@CommandAlias("elo")
@Description("Displays player elo.")
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(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---------------------------"));

}

@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;
}
Player otherP = Bukkit.getPlayer(otherPlayer);
Profile profile = Profile.getProfiles().get(otherP.getUniqueId());
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---------------------------"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void ping(Player player) {
if (profile.getMatch() != null) {
Match match = profile.getMatch();
player.sendMessage(Locale.PING_YOUR.format(player, BukkitReflection.getPing(player)));
player.sendMessage(Locale.PING_OTHERS.format(player, BukkitReflection.getPing(match.getOpponent(player)), match.getOpponent(player).getName()));
player.sendMessage(Locale.PING_OTHERS.format(player, BukkitReflection.getPing(match.getOpponent(player.getUniqueId())), match.getOpponent(player.getUniqueId()).getName()));
} else {
player.sendMessage(Locale.PING_YOUR.format(player, BukkitReflection.getPing(player)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public void open(Player player) {

}

@Default
@Syntax("<name>")
@CommandCompletion("@names")
public void statsOthers(Player player, String otherPlayer) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/me/lrxh/practice/match/Match.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ public void setupPlayer(Player player) {
} else {
player.getInventory().setArmorContents(getKit().getKitLoadout().getArmor());
player.getInventory().setContents(getKit().getKitLoadout().getContents());
player.sendMessage(Locale.MATCH_GIVE_KIT.format(player, "Default"));
player.sendMessage(Locale.MATCH_GIVE_KIT.format(player, "Default", kit.getName()));
}
}
}

public Player getOpponent(Player player) {
GameParticipant<MatchGamePlayer> playerParticipant = getParticipant(player);
public Player getOpponent(UUID playerUUID) {
GameParticipant<MatchGamePlayer> playerParticipant = getParticipant(Bukkit.getPlayer(playerUUID));
if (playerParticipant != null) {
for (GameParticipant<MatchGamePlayer> gameParticipant : getParticipants()) {
if (!gameParticipant.equals(playerParticipant)) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/lrxh/practice/match/MatchListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ public void onPlayerInteractEvent(PlayerInteractEvent event) {
}

if (kitLoadout != null) {
player.sendMessage(Locale.MATCH_GIVE_KIT.format(player, kitLoadout.getCustomName()));
player.sendMessage(Locale.MATCH_GIVE_KIT.format(player, kitLoadout.getCustomName(), kitName));
player.getInventory().setArmorContents(kitLoadout.getArmor());
player.getInventory().setContents(kitLoadout.getContents());
player.updateInventory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import me.lrxh.practice.util.ChatComponentBuilder;
import me.lrxh.practice.util.PlayerUtil;
import net.md_5.bungee.api.chat.BaseComponent;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -65,7 +66,7 @@ public void setupPlayer(Player player) {
} else {
player.getInventory().setArmorContents(getKit().getKitLoadout().getArmor());
player.getInventory().setContents(getKit().getKitLoadout().getContents());
player.sendMessage(Locale.MATCH_GIVE_KIT.format(player, "Default"));
player.sendMessage(Locale.MATCH_GIVE_KIT.format(player, "Default", kit.getName()));
}
}

Expand Down Expand Up @@ -158,8 +159,10 @@ public List<String> getScoreboardLines(Player player) {
@Override
public void addSpectator(Player spectator, Player target) {
super.addSpectator(spectator, target);
Profile profile = Profile.getByUuid(spectator.getUniqueId());
Match match = profile.getMatch();

spectator.sendMessage(Locale.MATCH_START_SPECTATING.format(spectator, CC.GREEN, target.getUniqueId()));
spectator.sendMessage(Locale.MATCH_START_SPECTATING.format(spectator, CC.GREEN, target.getUniqueId(), CC.GREEN, match.getOpponent(target.getUniqueId())));
}

@Override
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/me/lrxh/practice/util/PlaceholderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public static List<String> format(List<String> lines, Player player) {

if (profile.getState() == ProfileState.FIGHTING) {
Match match = profile.getMatch();
line = line.replaceAll("<opponent>", match.getOpponent(player).getName());
line = line.replaceAll("<opponent>", match.getOpponent(player.getUniqueId()).getName());
line = line.replaceAll("<duration>", match.getDuration());
line = line.replaceAll("<opponent-ping>", String.valueOf(BukkitReflection.getPing(match.getOpponent(player))));
line = line.replaceAll("<opponent-ping>", String.valueOf(BukkitReflection.getPing(match.getOpponent(player.getUniqueId()))));
line = line.replaceAll("<your-hits>", String.valueOf(match.getGamePlayer(player).getHits()));
line = line.replaceAll("<their-hits>", String.valueOf(match.getGamePlayer(match.getOpponent(player)).getHits()));
line = line.replaceAll("<their-hits>", String.valueOf(match.getGamePlayer(match.getOpponent(player.getUniqueId())).getHits()));
line = line.replaceAll("<diffrence>", getDifference(player));
}

Expand All @@ -69,12 +69,12 @@ public static List<String> format(List<String> lines, Player player) {
public String getDifference(Player player) {
Profile profile = Profile.getByUuid(player.getUniqueId());
Match match = profile.getMatch();
if (match.getGamePlayer(player).getHits() - match.getGamePlayer(match.getOpponent(player)).getHits() > 0) {
return CC.translate("&a(+" + (match.getGamePlayer(player).getHits() - match.getGamePlayer(match.getOpponent(player)).getHits()) + ")");
} else if (match.getGamePlayer(player).getHits() - match.getGamePlayer(match.getOpponent(player)).getHits() < 0) {
return CC.translate("&c(" + (match.getGamePlayer(player).getHits() - match.getGamePlayer(match.getOpponent(player)).getHits()) + ")");
if (match.getGamePlayer(player).getHits() - match.getGamePlayer(match.getOpponent(player.getUniqueId())).getHits() > 0) {
return CC.translate("&a(+" + (match.getGamePlayer(player).getHits() - match.getGamePlayer(match.getOpponent(player.getUniqueId())).getHits()) + ")");
} else if (match.getGamePlayer(player).getHits() - match.getGamePlayer(match.getOpponent(player.getUniqueId())).getHits() < 0) {
return CC.translate("&c(" + (match.getGamePlayer(player).getHits() - match.getGamePlayer(match.getOpponent(player.getUniqueId())).getHits()) + ")");
} else {
return CC.translate("&e(" + (match.getGamePlayer(player).getHits() - match.getGamePlayer(match.getOpponent(player)).getHits()) + ")");
return CC.translate("&e(" + (match.getGamePlayer(player).getHits() - match.getGamePlayer(match.getOpponent(player.getUniqueId())).getHits()) + ")");
}
}

Expand Down

0 comments on commit 337dbb8

Please sign in to comment.