Skip to content

Commit

Permalink
Added party events scoreboard and improved a ton more stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Devlrxxh committed Apr 6, 2024
1 parent 9c191aa commit 9f7e764
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import me.lrxh.practice.Practice;
import me.lrxh.practice.party.Party;
import me.lrxh.practice.party.PartyPrivacy;
import me.lrxh.practice.party.menu.OtherPartiesMenu;
import me.lrxh.practice.party.menu.PartyEventSelectEventMenu;
import me.lrxh.practice.profile.Profile;
import me.lrxh.practice.profile.ProfileState;
import me.lrxh.practice.util.CC;
Expand Down Expand Up @@ -105,7 +107,6 @@ public void info(Player player) {
}

profile.getParty().sendInformation(player);

}

@Syntax("<name>")
Expand Down Expand Up @@ -248,6 +249,40 @@ public void kick(Player player, String playerName) {
profile.getParty().leave(target, true);
}

@Subcommand("event")
public void event(Player player) {
Profile profile = Profile.getByUuid(player.getUniqueId());

if (profile.getParty() == null) {
player.sendMessage(CC.RED + "You do not have a party.");
return;
}

if (!profile.getParty().getLeader().equals(player)) {
player.sendMessage(CC.RED + "You are not the leader of your party.");
return;
}

new PartyEventSelectEventMenu().openMenu(player);
}

@Subcommand("other")
public void other(Player player) {
Profile profile = Profile.getByUuid(player.getUniqueId());

if (profile.getParty() == null) {
player.sendMessage(CC.RED + "You do not have a party.");
return;
}

if (!profile.getParty().getLeader().equals(player)) {
player.sendMessage(CC.RED + "You are not the leader of your party.");
return;
}

new OtherPartiesMenu().openMenu(player);
}

@Subcommand("leave")
public void leave(Player player) {
Profile profile = Profile.getByUuid(player.getUniqueId());
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/me/lrxh/practice/match/Match.java
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,9 @@ public void onDeath(Player dead) {
PlayerUtil.animateDeath(dead);

if (killer != null) {
PlayerUtil.sendTitle(dead, CC.translate("&cLOST!"), "&c" + killer.getName() + " &fwon the match!", 70);
PlayerUtil.sendTitle(dead, CC.translate("&cDEFEAT!"), "&a" + killer.getName() + " &7won the match!", 70);
} else {
PlayerUtil.sendTitle(dead, CC.translate("&cDEFEAT!"), "&aEnemy" + " &7won the match!", 70);
}

// Don't continue if the player is already dead
Expand All @@ -515,7 +517,7 @@ public void onDeath(Player dead) {
if (killer != null) {
Profile killerProfile = Profile.getByUuid(killer.getUniqueId());
killerProfile.getOptions().killEffect().execute(killer, dead.getLocation());
PlayerUtil.sendTitle(killer, CC.translate("&aVICTORY!"), "&a" + killer.getName() + " &fwon the match!", 70);
PlayerUtil.sendTitle(killer, CC.translate("&aVICTORY!"), "&aYou" + " &7won the match!", 70);
killer.playSound(killer.getLocation(), Sound.EXPLODE, 1.0f, 1.0f);
PlayerUtil.doVelocityChange(killer);
}
Expand Down Expand Up @@ -616,8 +618,6 @@ public MatchGamePlayer getGamePlayer(Player player) {

public abstract ChatColor getRelationColor(Player viewer, Player target);

public abstract List<String> getScoreboardLines(Player player);

public void addSpectator(Player spectator, Player target) {
spectators.add(spectator.getUniqueId());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,22 +147,6 @@ public org.bukkit.ChatColor getRelationColor(Player viewer, Player target) {
}
}

@Override
public List<String> getScoreboardLines(Player player) {
List<String> lines = new ArrayList<>();

if (getParticipant(player) != null) {
lines.add("&cDuration: &r" + getDuration());
lines.add("&cOpponents: &r" + (getRemainingTeams() - 1));
} else {
lines.add("&cKit: &7" + getKit().getName());
lines.add("&cDuration: &7" + getDuration());
lines.add("&cTeams: &7" + getRemainingTeams());
}

return lines;
}

@Override
public void addSpectator(Player spectator, Player target) {
super.addSpectator(spectator, target);
Expand Down Expand Up @@ -204,7 +188,7 @@ public List<BaseComponent[]> generateEndComponents() {
return componentsList;
}

private int getRemainingTeams() {
public int getRemainingTeams() {
int remaining = 0;

for (GameParticipant<MatchGamePlayer> gameParticipant : participants) {
Expand Down
75 changes: 0 additions & 75 deletions src/main/java/me/lrxh/practice/match/impl/BasicTeamMatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
import me.lrxh.practice.kit.Kit;
import me.lrxh.practice.match.Match;
import me.lrxh.practice.match.MatchSnapshot;
import me.lrxh.practice.match.MatchState;
import me.lrxh.practice.match.participant.MatchGamePlayer;
import me.lrxh.practice.participant.GameParticipant;
import me.lrxh.practice.profile.Profile;
import me.lrxh.practice.profile.meta.ProfileRematchData;
import me.lrxh.practice.queue.Queue;
import me.lrxh.practice.util.ChatComponentBuilder;
import me.lrxh.practice.util.TimeUtil;
import me.lrxh.practice.util.elo.EloUtil;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent;
Expand Down Expand Up @@ -220,79 +218,6 @@ public org.bukkit.ChatColor getRelationColor(Player viewer, Player target) {
}
}

@Override
public List<String> getScoreboardLines(Player player) {
List<String> lines = new ArrayList<>();

if (getParticipant(player) != null) {
if (state == MatchState.STARTING_ROUND || state == MatchState.PLAYING_ROUND) {
if (participantA.getPlayers().size() == 1 && participantB.getPlayers().size() == 1) {
GameParticipant<MatchGamePlayer> opponent;

if (participantA.containsPlayer(player.getUniqueId())) {
opponent = participantB;
} else {
opponent = participantA;
}

lines.add("&cDuration: &r" + getDuration());
lines.add("&cOpponent: &r" + opponent.getConjoinedNames());
} else {
GameParticipant<MatchGamePlayer> friendly = getParticipant(player);
GameParticipant<MatchGamePlayer> opponent = participantA.equals(friendly) ?
participantB : participantA;

if (friendly.getPlayers().size() + opponent.getPlayers().size() <= 6) {
lines.add("&cDuration: &7" + getDuration());
lines.add("");
lines.add("&aTeam &a(" + friendly.getAliveCount() + "/" + friendly.getPlayers().size() + ")");

for (MatchGamePlayer gamePlayer : friendly.getPlayers()) {
lines.add(" " + (gamePlayer.isDead() || gamePlayer.isDisconnected() ? "&7&m" : "") +
gamePlayer.getUsername());
}

lines.add("");
lines.add("&cOpponents &c(" + opponent.getAliveCount() + "/" + opponent.getPlayers().size() +
")");

for (MatchGamePlayer gamePlayer : opponent.getPlayers()) {
lines.add(" " + (gamePlayer.isDead() || gamePlayer.isDisconnected() ? "&7&m" : "") +
gamePlayer.getUsername());
}
} else {
lines.add("&cDuration: &7" + getDuration());
lines.add("&aTeam: &7" + friendly.getAliveCount() + "/" + friendly.getPlayers().size());
lines.add("&cOpponents: &7" + opponent.getAliveCount() + "/" + opponent.getPlayers().size());
}
}
} else {
lines.add("&cDuration: &7" + TimeUtil.millisToTimer(timeData));
}
} else {
lines.add("&cKit: &7" + getKit().getName());
lines.add("&cDuration: &7" + getDuration());
lines.add("");

if (participantA.getPlayers().size() <= 2 && participantB.getPlayers().size() <= 2) {
for (MatchGamePlayer gamePlayer : participantA.getPlayers()) {
lines.add(gamePlayer.getUsername());
}

lines.add("vs");

for (MatchGamePlayer gamePlayer : participantB.getPlayers()) {
lines.add(gamePlayer.getUsername());
}
} else {
lines.add(participantA.getLeader().getUsername() + "'s Team");
lines.add(participantB.getLeader().getUsername() + "'s Team");
}
}

return lines;
}

@Override
public void addSpectator(Player spectator, Player target) {
super.addSpectator(spectator, target);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/me/lrxh/practice/match/task/MatchLogicTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import me.lrxh.practice.Practice;
import me.lrxh.practice.match.Match;
import me.lrxh.practice.match.MatchState;
import me.lrxh.practice.match.impl.BasicTeamMatch;
import me.lrxh.practice.match.participant.MatchGamePlayer;
import me.lrxh.practice.participant.GameParticipant;
import me.lrxh.practice.participant.GamePlayer;
Expand Down Expand Up @@ -32,7 +33,7 @@ public void run() {
}
nextAction--;
if (match.getState() == MatchState.STARTING_ROUND) {
if (match.getKit().getGameRules().isSumo() || match.getKit().getGameRules().isBedwars()) {
if (match.getKit().getGameRules().isSumo() || match.getKit().getGameRules().isBedwars() || match instanceof BasicTeamMatch) {
for (GameParticipant<MatchGamePlayer> gameParticipant : match.getParticipants()) {
for (GamePlayer gamePlayer : gameParticipant.getPlayers()) {
PlayerUtil.denyMovement(gamePlayer.getPlayer());
Expand All @@ -46,7 +47,7 @@ public void run() {
match.sendMessage(" ");
match.sendMessage(Locale.MATCH_WARNING.format());

if (match.getKit().getGameRules().isSumo() || match.getKit().getGameRules().isBedwars()) {
if (match.getKit().getGameRules().isSumo() || match.getKit().getGameRules().isBedwars() || match instanceof BasicTeamMatch) {
for (GameParticipant<MatchGamePlayer> gameParticipant : match.getParticipants()) {
for (GamePlayer gamePlayer : gameParticipant.getPlayers()) {
PlayerUtil.allowMovement(gamePlayer.getPlayer());
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/me/lrxh/practice/party/Party.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ public void disband() {
// Remove any party duel requests
Profile leaderProfile = Profile.getByUuid(leader.getUniqueId());

if (leaderProfile != null) {
leaderProfile.getDuelRequests().removeIf(DuelRequest::isParty);
}
leaderProfile.getDuelRequests().removeIf(DuelRequest::isParty);

// Reset player profiles
for (Player player : getListOfPlayers()) {
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/me/lrxh/practice/party/PartyEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
@Getter
public enum PartyEvent {

FFA("FFA"),
SPLIT("Split");

private String name;
FFA("Party FFA"),
SPLIT("Party Split");

private final String name;
}
28 changes: 0 additions & 28 deletions src/main/java/me/lrxh/practice/party/PartyListener.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
package me.lrxh.practice.party;

import me.lrxh.practice.Practice;
import me.lrxh.practice.party.menu.OtherPartiesMenu;
import me.lrxh.practice.party.menu.PartyEventSelectEventMenu;
import me.lrxh.practice.profile.Profile;
import me.lrxh.practice.profile.hotbar.HotbarItem;
import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;

public class PartyListener implements Listener {
Expand All @@ -28,28 +22,6 @@ public void onAsyncPlayerChatEvent(AsyncPlayerChatEvent event) {
}
}

@EventHandler(priority = EventPriority.HIGH)
public void onPlayerInteractEvent(PlayerInteractEvent event) {
if (event.getItem() != null && (event.getAction() == Action.RIGHT_CLICK_AIR ||
event.getAction() == Action.RIGHT_CLICK_BLOCK)) {
HotbarItem hotbarItem = Practice.getInstance().getHotbar().fromItemStack(event.getItem());

if (hotbarItem != null) {
boolean cancelled = true;

if (hotbarItem == HotbarItem.PARTY_EVENTS) {
new PartyEventSelectEventMenu().openMenu(event.getPlayer());
} else if (hotbarItem == HotbarItem.OTHER_PARTIES) {
new OtherPartiesMenu().openMenu(event.getPlayer());
} else {
cancelled = false;
}

event.setCancelled(cancelled);
}
}
}

@EventHandler(priority = EventPriority.LOW)
public void onPlayerQuitEvent(PlayerQuitEvent event) {
Profile profile = Profile.getProfiles().get(event.getPlayer().getUniqueId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class PartyEventSelectEventMenu extends Menu {
Expand Down Expand Up @@ -49,8 +51,21 @@ private static class SelectEventButton extends Button {

@Override
public ItemStack getButtonItem(Player player) {
return new ItemBuilder(partyEvent == PartyEvent.FFA ? Material.QUARTZ : Material.REDSTONE)
List<String> splitLore = new ArrayList<>();
splitLore.add(CC.translate("&7Split your party into"));
splitLore.add(CC.translate("&72 teams and fight."));
splitLore.add(CC.translate(""));
splitLore.add(CC.translate("&aClick to host!"));

List<String> ffaLore = new ArrayList<>();
ffaLore.add(CC.translate("&7Everybody in the party"));
ffaLore.add(CC.translate("&7fights everybody else."));
ffaLore.add(CC.translate(""));
ffaLore.add(CC.translate("&aClick to host!"));

return new ItemBuilder(partyEvent == PartyEvent.FFA ? Material.DIAMOND_SWORD : Material.GOLD_AXE)
.name(Practice.getInstance().getMenusConfig().getString("PARTY.EVENTS.EVENT-COLOR").replace("<event>", partyEvent.getName()))
.lore(partyEvent == PartyEvent.FFA ? ffaLore : splitLore)
.clearFlags()
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import me.lrxh.practice.util.ItemBuilder;
import me.lrxh.practice.util.menu.Button;
import me.lrxh.practice.util.menu.Menu;
import me.lrxh.practice.util.menu.filters.Filters;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
Expand All @@ -34,13 +35,24 @@ public String getTitle(Player player) {
return Practice.getInstance().getMenusConfig().getString("PARTY.EVENTS.SELECT-KIT.TITLE");
}

@Override
public Filters getFilter() {
return Filters.valueOf(Practice.getInstance().getMenusConfig().getString("PARTY.EVENTS.FILTER"));
}


public int getSize() {
return Practice.getInstance().getMenusConfig().getInteger("PARTY.EVENTS.SELECT-KIT.SIZE");
}

@Override
public Map<Integer, Button> getButtons(Player player) {
Map<Integer, Button> buttons = new HashMap<>();
int i = 10;

for (Kit kit : Kit.getKits()) {
if (kit.isEnabled()) {
buttons.put(buttons.size(), new SelectKitButton(partyEvent, kit));
buttons.put(i++, new SelectKitButton(partyEvent, kit));
}
}

Expand All @@ -56,7 +68,7 @@ private static class SelectKitButton extends Button {
@Override
public ItemStack getButtonItem(Player player) {
return new ItemBuilder(kit.getDisplayIcon())
.name("&6" + kit.getName())
.name(Practice.getInstance().getMenusConfig().getString("PARTY.EVENTS.SELECT-KIT.KIT-NAME").replace("<kit>", kit.getName()))
.clearFlags()
.build();
}
Expand Down
Loading

0 comments on commit 9f7e764

Please sign in to comment.