diff --git a/pom.xml b/pom.xml index 20bfc02..b278278 100644 --- a/pom.xml +++ b/pom.xml @@ -136,4 +136,4 @@ - + \ No newline at end of file diff --git a/src/main/java/me/lrxh/practice/Locale.java b/src/main/java/me/lrxh/practice/Locale.java index 6a529ca..449325d 100644 --- a/src/main/java/me/lrxh/practice/Locale.java +++ b/src/main/java/me/lrxh/practice/Locale.java @@ -52,6 +52,8 @@ public enum Locale { MATCH_SHOW_REPLAY("MATCH.REPLAY.SHOW_REPLAY"), MATCH_SHOW_REPLAY_HOVER("MATCH.REPLAY.RECEIVED_HOVER"), MATCH_SHOW_REPLAY_RECEIVED_CLICKABLE("MATCH.REPLAY.RECEIVED_CLICKABLE"), + REMATCH_SHOW_REPLAY_HOVER("MATCH.REMATCH.RECEIVED_HOVER"), + REMATCH_SHOW_REPLAY_RECEIVED_CLICKABLE("MATCH.REMATCH.RECEIVED_CLICKABLE"), MATCH_START_TIMER("MATCH.START_TIMER"), MATCH_RESPAWN_TIMER("MATCH.RESPAWN_TIMER"), MATCH_RESPAWNED("MATCH.RESPAWNED"), diff --git a/src/main/java/me/lrxh/practice/arena/selection/Selection.java b/src/main/java/me/lrxh/practice/arena/selection/Selection.java index 5c0511f..3b36349 100644 --- a/src/main/java/me/lrxh/practice/arena/selection/Selection.java +++ b/src/main/java/me/lrxh/practice/arena/selection/Selection.java @@ -21,7 +21,6 @@ public class Selection { private static final String SELECTION_METADATA_KEY = "CLAIM_SELECTION"; - static { SELECTION_WAND = new ItemBuilder(Material.GOLD_AXE) .name("&6Selection Wand") diff --git a/src/main/java/me/lrxh/practice/match/Match.java b/src/main/java/me/lrxh/practice/match/Match.java index a66eec7..094fa26 100644 --- a/src/main/java/me/lrxh/practice/match/Match.java +++ b/src/main/java/me/lrxh/practice/match/Match.java @@ -94,6 +94,20 @@ public static void cleanup() { } } + public static ChatComponentBuilder[] getTeamAsComponent(GameParticipant participants) { + List chatComponentBuilders = new ArrayList<>(); + + for (MatchGamePlayer matchGamePlayer : participants.getPlayers()) { + ChatComponentBuilder current = new ChatComponentBuilder( + Locale.MATCH_CLICK_TO_VIEW_NAME.format(matchGamePlayer.getUsername())) + .attachToEachPart(ChatHelper.hover(Locale.MATCH_CLICK_TO_VIEW_HOVER.format(matchGamePlayer.getUsername()))) + .attachToEachPart(ChatHelper.click("/viewinv " + matchGamePlayer.getUuid().toString())); + chatComponentBuilders.add(current); + } + return chatComponentBuilders.toArray(new ChatComponentBuilder[0]); + } + + public static int getInFightsCount(Queue queue) { int i = 0; @@ -305,25 +319,6 @@ public void end() { arena.setActive(false); } - for (Player participant : getPlayers()) { - if (participant != null && participant.isOnline()) { - if (Practice.getInstance().isReplay() && !kit.getGameRules().isBuild()) { - for (String msg : Locale.MATCH_SHOW_REPLAY.formatLines(participant)) { - if (msg.contains("%CLICKABLE%")) { - ChatComponentBuilder builder = new ChatComponentBuilder(Locale.MATCH_SHOW_REPLAY_RECEIVED_CLICKABLE.format(participant - )); - builder.attachToEachPart(ChatHelper.click("/replay play " + participant.getUniqueId())); - builder.attachToEachPart(ChatHelper.hover(Locale.MATCH_SHOW_REPLAY_HOVER.format(participant))); - - participant.sendMessage(builder.create()); - } else { - participant.sendMessage(msg); - } - } - } - } - } - Practice.getInstance().getCache().getMatches().remove(this); } @@ -375,29 +370,20 @@ public void onRoundEnd() { MatchSnapshot.getSnapshots().put(snapshot.getUuid(), snapshot); } - List endingMessages = generateEndComponents(); // Send ending messages to game participants for (GameParticipant gameParticipant : getParticipants()) { for (MatchGamePlayer gamePlayer : gameParticipant.getPlayers()) { if (!gamePlayer.isDisconnected()) { Player player = gamePlayer.getPlayer(); - - if (player != null) { - for (BaseComponent[] components : endingMessages) { - player.sendMessage(components); - } - } + sendEndMessage(player); } } } // Send ending messages to spectators for (Player player : getSpectatorsAsPlayers()) { - for (BaseComponent[] components : endingMessages) { - player.sendMessage(components); - } - + sendEndMessage(player); removeSpectator(player); } } @@ -800,7 +786,7 @@ protected List getSpectatorsAsPlayers() { return players; } - public abstract List generateEndComponents(); + public abstract void sendEndMessage(Player player); public void sendDeathMessage(Player dead, Player killer, boolean finalKill) { diff --git a/src/main/java/me/lrxh/practice/match/impl/BasicFreeForAllMatch.java b/src/main/java/me/lrxh/practice/match/impl/BasicFreeForAllMatch.java index 2354047..8c28d36 100644 --- a/src/main/java/me/lrxh/practice/match/impl/BasicFreeForAllMatch.java +++ b/src/main/java/me/lrxh/practice/match/impl/BasicFreeForAllMatch.java @@ -14,7 +14,6 @@ import me.lrxh.practice.util.ChatComponentBuilder; import me.lrxh.practice.util.InventoryUtil; import me.lrxh.practice.util.PlayerUtil; -import net.md_5.bungee.api.chat.BaseComponent; import org.bukkit.Color; import org.bukkit.Location; import org.bukkit.Material; @@ -22,6 +21,7 @@ import org.bukkit.inventory.ItemStack; import java.util.ArrayList; +import java.util.Collections; import java.util.List; public class BasicFreeForAllMatch extends Match { @@ -157,37 +157,58 @@ public void addSpectator(Player spectator, Player target) { } @Override - public List generateEndComponents() { - List componentsList = new ArrayList<>(); - - for (String line : Locale.MATCH_END_DETAILS.formatLines()) { - if (line.equalsIgnoreCase("%INVENTORIES%")) { - List> participants = new ArrayList<>(this.participants); - participants.remove(winningParticipant); - - - BaseComponent[] winners = generateInventoriesComponents( - Locale.MATCH_END_WINNER_INVENTORY.format(""), winningParticipant); - - BaseComponent[] losers = generateInventoriesComponents( - Locale.MATCH_END_LOSER_INVENTORY.format(participants.size() > 1 ? "s" : ""), participants); - - componentsList.add(winners); - componentsList.add(losers); - - continue; - } - - if (line.equalsIgnoreCase("%ELO_CHANGES%")) { - continue; + public void sendEndMessage(Player player) { + List formattedStrings = new ArrayList<>(Locale.MATCH_END_DETAILS.formatLines()); + for (String string : formattedStrings) { + if (string.equalsIgnoreCase("%INVENTORIES%")) { + ChatComponentBuilder winner = new ChatComponentBuilder(Locale.MATCH_END_WINNER_INVENTORY + .format(player)); + + PlayerUtil.sendMessage(player, Collections.singletonList(winner).toArray(new ChatComponentBuilder[0]), getTeamAsComponent(winningParticipant), + getTeamAsComponent(winningParticipant)); + + } else if (string.equalsIgnoreCase("%ENDMESSAGE%")) { + formattedStrings.remove(string); + } else if (string.equalsIgnoreCase("%ELO_CHANGES%")) { + formattedStrings.remove(string); + } else { + player.sendMessage(CC.translate(string)); } - - componentsList.add(new ChatComponentBuilder("").parse(line).create()); } - - return componentsList; } +// @Override +// public List generateEndComponents(Player player) { +// List componentsList = new ArrayList<>(); +// +// for (String line : Locale.MATCH_END_DETAILS.formatLines()) { +// if (line.equalsIgnoreCase("%INVENTORIES%")) { +// List> participants = new ArrayList<>(this.participants); +// participants.remove(winningParticipant); +// +// +// BaseComponent[] winners = generateInventoriesComponents( +// Locale.MATCH_END_WINNER_INVENTORY.format(""), winningParticipant); +// +// BaseComponent[] losers = generateInventoriesComponents( +// Locale.MATCH_END_LOSER_INVENTORY.format(participants.size() > 1 ? "s" : ""), participants); +// +// componentsList.add(winners); +// componentsList.add(losers); +// +// continue; +// } +// +// if (line.equalsIgnoreCase("%ELO_CHANGES%")) { +// continue; +// } +// +// componentsList.add(new ChatComponentBuilder("").parse(line).create()); +// } +// +// return componentsList; +// } + public int getRemainingTeams() { int remaining = 0; diff --git a/src/main/java/me/lrxh/practice/match/impl/BasicTeamMatch.java b/src/main/java/me/lrxh/practice/match/impl/BasicTeamMatch.java index e85fce3..03251ef 100644 --- a/src/main/java/me/lrxh/practice/match/impl/BasicTeamMatch.java +++ b/src/main/java/me/lrxh/practice/match/impl/BasicTeamMatch.java @@ -12,20 +12,18 @@ import me.lrxh.practice.profile.Profile; import me.lrxh.practice.profile.meta.ProfileRematchData; import me.lrxh.practice.queue.Queue; +import me.lrxh.practice.util.CC; import me.lrxh.practice.util.ChatComponentBuilder; +import me.lrxh.practice.util.ChatHelper; +import me.lrxh.practice.util.PlayerUtil; import me.lrxh.practice.util.elo.EloUtil; import net.md_5.bungee.api.ChatColor; -import net.md_5.bungee.api.chat.BaseComponent; -import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.UUID; +import java.util.*; @Getter public class BasicTeamMatch extends Match { @@ -253,42 +251,46 @@ public void addSpectator(Player spectator, Player target) { } @Override - public List generateEndComponents() { - List componentsList = new ArrayList<>(); - - for (String line : Locale.MATCH_END_DETAILS.formatLines()) { - if (line.equalsIgnoreCase("%INVENTORIES%")) { - BaseComponent[] winners = generateInventoriesComponents( - Locale.MATCH_END_WINNER_INVENTORY.format(participantA.getPlayers().size() == 1 ? "" : "s"), - winningParticipant); - - BaseComponent[] losers = generateInventoriesComponents( - Locale.MATCH_END_LOSER_INVENTORY.format(participantB.getPlayers().size() == 1 ? "" : "s"), - losingParticipant); - - if (participantA.getPlayers().size() == 1 && participantB.getPlayers().size() == 1) { - ChatComponentBuilder builder = new ChatComponentBuilder(""); - - for (BaseComponent component : winners) { - builder.append((TextComponent) component); - } - - builder.append(new ChatComponentBuilder("&7 | ").create()); - - for (BaseComponent component : losers) { - builder.append((TextComponent) component); - } - - componentsList.add(builder.create()); + public void sendEndMessage(Player player) { + List formattedStrings = new ArrayList<>(Locale.MATCH_END_DETAILS.formatLines()); + for (String string : formattedStrings) { + if (string.equalsIgnoreCase("%INVENTORIES%")) { + ChatComponentBuilder winner = new ChatComponentBuilder(Locale.MATCH_END_WINNER_INVENTORY + .format(player)); + + ChatComponentBuilder separator = new ChatComponentBuilder("&7 | "); + + ChatComponentBuilder loser = new ChatComponentBuilder(Locale.MATCH_END_LOSER_INVENTORY + .format(player)); + + PlayerUtil.sendMessage(player, + Collections.singletonList(winner).toArray(new ChatComponentBuilder[0]), + getTeamAsComponent(winningParticipant), + Collections.singletonList(separator).toArray(new ChatComponentBuilder[0]), + Collections.singletonList(loser).toArray(new ChatComponentBuilder[0]), + getTeamAsComponent(losingParticipant)); + + } else if (string.equalsIgnoreCase("%ENDMESSAGE%")) { + ChatComponentBuilder replay = new ChatComponentBuilder(Locale.MATCH_SHOW_REPLAY_RECEIVED_CLICKABLE.format(player)); + replay.attachToEachPart(ChatHelper.click("/replay play " + player.getUniqueId())); + replay.attachToEachPart(ChatHelper.hover(Locale.MATCH_SHOW_REPLAY_HOVER.format(player))); + + ChatComponentBuilder rematch = new ChatComponentBuilder(Locale.REMATCH_SHOW_REPLAY_RECEIVED_CLICKABLE.format(player)); + rematch.attachToEachPart(ChatHelper.click("/rematch " + player.getName())); + rematch.attachToEachPart(ChatHelper.hover(Locale.REMATCH_SHOW_REPLAY_HOVER.format(player))); + + + if (Practice.getInstance().isReplay() && !kit.getGameRules().isBuild()) { + PlayerUtil.sendMessage(player, + Collections.singletonList(replay).toArray(new ChatComponentBuilder[0]), + Collections.singletonList(rematch).toArray(new ChatComponentBuilder[0])); } else { - componentsList.add(winners); - componentsList.add(losers); - } + PlayerUtil.sendMessage(player, + Collections.singletonList(rematch).toArray(new ChatComponentBuilder[0])); - continue; - } + } - if (line.equalsIgnoreCase("%ELO_CHANGES%")) { + } else if (string.equalsIgnoreCase("%ELO_CHANGES%")) { if (participantA.getPlayers().size() == 1 && participantB.getPlayers().size() == 1 && ranked) { List sectionLines = Locale.MATCH_ELO_CHANGES.formatLines( winningParticipant.getConjoinedNames(), @@ -298,19 +300,15 @@ public List generateEndComponents() { (losingParticipant.getLeader().getEloMod()), (losingParticipant.getLeader().getElo() - losingParticipant.getLeader().getEloMod()) ); - for (String sectionLine : sectionLines) { - componentsList.add(new ChatComponentBuilder("").parse(sectionLine).create()); + player.sendMessage(CC.translate(sectionLine)); } } - - continue; + } else { + player.sendMessage(CC.translate(string)); } - - componentsList.add(new ChatComponentBuilder("").parse(line).create()); } - - return componentsList; } + } diff --git a/src/main/java/me/lrxh/practice/profile/meta/ProfileRematchData.java b/src/main/java/me/lrxh/practice/profile/meta/ProfileRematchData.java index 7f742a1..da6f36d 100644 --- a/src/main/java/me/lrxh/practice/profile/meta/ProfileRematchData.java +++ b/src/main/java/me/lrxh/practice/profile/meta/ProfileRematchData.java @@ -30,7 +30,7 @@ public class ProfileRematchData { private final UUID target; private final Kit kit; private final long timestamp; - private Arena arena; + private final Arena arena; private boolean sent; private boolean receive; private boolean cancelled; @@ -41,6 +41,7 @@ public ProfileRematchData(UUID key, UUID sender, UUID target, Kit kit) { this.target = target; this.kit = kit; this.timestamp = System.currentTimeMillis(); + this.arena = Arena.getRandomArena(kit); } public void request() { @@ -80,7 +81,7 @@ public void request() { BaseComponent[] lineComponents = new ChatComponentBuilder("") .parse(line) .attachToEachPart(ChatHelper.hover(Locale.REMATCH_RECEIVED_REQUEST_HOVER.format(target))) - .attachToEachPart(ChatHelper.click("/rematch")) + .attachToEachPart(ChatHelper.click("/rematch " + sender.getName())) .create(); components.add(lineComponents); diff --git a/src/main/java/me/lrxh/practice/util/PlayerUtil.java b/src/main/java/me/lrxh/practice/util/PlayerUtil.java index 9ce1d4a..ef48bda 100644 --- a/src/main/java/me/lrxh/practice/util/PlayerUtil.java +++ b/src/main/java/me/lrxh/practice/util/PlayerUtil.java @@ -3,6 +3,7 @@ import lombok.experimental.UtilityClass; import me.lrxh.practice.Practice; import me.lrxh.practice.profile.SpawnTeleportEvent; +import net.md_5.bungee.api.chat.BaseComponent; import net.minecraft.server.v1_8_R3.MinecraftServer; import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy; import net.minecraft.server.v1_8_R3.PacketPlayOutEntityStatus; @@ -20,10 +21,7 @@ import org.github.paperspigot.Title; import java.lang.reflect.Field; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.UUID; +import java.util.*; @UtilityClass public class PlayerUtil { @@ -78,6 +76,34 @@ public Player getLastAttacker(Player victim) { } } + public void sendMessage(Player player, ChatComponentBuilder[]... chatComponentBuilders) { + List components = new ArrayList<>(); + for (ChatComponentBuilder[] builderArray : chatComponentBuilders) { + for (ChatComponentBuilder chatComponentBuilder : builderArray) { + components.add(chatComponentBuilder.create()); + } + } + if (player != null) { + BaseComponent[] concatenatedComponents = concatenateComponents(components); + player.sendMessage(concatenatedComponents); + } + } + + + private BaseComponent[] concatenateComponents(List components) { + int totalLength = 0; + for (BaseComponent[] component : components) { + totalLength += component.length; + } + BaseComponent[] concatenatedComponents = new BaseComponent[totalLength]; + int currentIndex = 0; + for (BaseComponent[] component : components) { + System.arraycopy(component, 0, concatenatedComponents, currentIndex, component.length); + currentIndex += component.length; + } + return concatenatedComponents; + } + public static void sendTitle(Player player, String header, String footer, int duration) { player.sendTitle(new Title(CC.translate(header), CC.translate(footer), 1, duration, 10)); } diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index 74976a7..3b67f5e 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -116,23 +116,29 @@ MATCH: - '&7&m------------------------------------------------' - 'Post-Match Inventories &7&o&7(Click to view)' - '%INVENTORIES%' + - '%ENDMESSAGE%' - '%ELO_CHANGES%' - '&7&m------------------------------------------------' END_WINNER_INVENTORY: '&aWinner{0}: ' END_LOSER_INVENTORY: '&cLoser{0}: ' CLICK_TO_VIEW_NAME: '&e{0}' CLICK_TO_VIEW_HOVER: '&eClick to view {0}&e''''s inventory.' + REPLAY: + SHOW_REPLAY: + - '%CLICKABLE%' + RECEIVED_HOVER: '&aClick here to see a replay of your fight.' + RECEIVED_CLICKABLE: '&7Want to replay your match? &a(CLICK HERE)' + REMATCH: + MESSAGE: + - '%CLICKABLE%' + RECEIVED_HOVER: '&aClick here to see a replay of your fight.' + RECEIVED_CLICKABLE: '&7Want to replay your match? &a(CLICK HERE)' ELO_CHANGES: - '&a{0} +{1} ({2}) &7| &c{3} -{4} ({5})' PLAYER_KILLED: '&a{1} &7killed &c{0}&7.' PLAYER_DIED: '{0} &7committed suicide.' PLAYER_FINAL_KILL: '&a{1} &7killed &c{0}&7. &b&lFINAL KILL' PLAYER_DIED_FINAL: '{0} &7committed suicide. &b&lFINAL KILL' - REPLAY: - SHOW_REPLAY: - - '%CLICKABLE%' - RECEIVED_HOVER: '&aClick here to see a replay of your fight.' - RECEIVED_CLICKABLE: '&7Want to replay your match? &a(CLICK HERE)' ROUNDS_TO_WIN: '' REMATCH: SENT_REQUEST: