diff --git a/src/main/java/tntrun/messages/Messages.java b/src/main/java/tntrun/messages/Messages.java index d194df19..e490db4b 100644 --- a/src/main/java/tntrun/messages/Messages.java +++ b/src/main/java/tntrun/messages/Messages.java @@ -195,6 +195,10 @@ public class Messages { public static String partynotexist = "&c The selected party does not exist"; public static String partynoinvite = "&c You do not have an invitation to this party"; public static String partynotenabled = "&c TNTRun parties are not currently enabled"; + public static String partyclickaccept = "&6&lAccept"; + public static String partyclickdecline = "&6&lDecline"; + public static String partyaccepttext = "&7Click to &baccept &7the invitation"; + public static String partydeclinetext = "&7Click to &cdecline &7the invitation"; public static void sendMessage(CommandSender sender, String message) { sendMessage(sender, message, true); @@ -381,6 +385,10 @@ public static void loadMessages(TNTRun plugin) { partynotexist = config.getString("partynotexist", partynotexist); partynoinvite = config.getString("partynoinvite", partynoinvite); partynotenabled = config.getString("partynotenabled", partynotenabled); + partyclickaccept = config.getString("partyclickaccept", partyclickaccept); + partyclickdecline = config.getString("partyclickdecline", partyclickdecline); + partyaccepttext = config.getString("partyaccepttext", partyaccepttext); + partydeclinetext = config.getString("partydeclinetext", partydeclinetext); saveMessages(messageconfig); } @@ -548,6 +556,10 @@ private static void saveMessages(File messageconfig) { config.set("partynotexist", partynotexist); config.set("partynoinvite", partynoinvite); config.set("partynotenabled", partynotenabled); + config.set("partyclickaccept", partyclickaccept); + config.set("partyclickdecline", partyclickdecline); + config.set("partyaccepttext", partyaccepttext); + config.set("partydeclinetext", partydeclinetext); try { config.save(messageconfig); } catch (IOException e) { diff --git a/src/main/java/tntrun/parties/Parties.java b/src/main/java/tntrun/parties/Parties.java index 7be08878..831aa2c9 100644 --- a/src/main/java/tntrun/parties/Parties.java +++ b/src/main/java/tntrun/parties/Parties.java @@ -162,7 +162,7 @@ private void inviteToParty(Player player, String targetName) { invitedMap.computeIfAbsent(player.getName(), k -> new ArrayList<>()).add(targetName); Messages.sendMessage(Bukkit.getPlayer(targetName), Messages.partyinvite.replace("{PLAYER}", player.getName())); - Utils.displayPartyInvite(player, targetName, ""); + Utils.displayPartyInvite(player, targetName); } /** diff --git a/src/main/java/tntrun/utils/Utils.java b/src/main/java/tntrun/utils/Utils.java index ab8c9e8a..23eb1a15 100644 --- a/src/main/java/tntrun/utils/Utils.java +++ b/src/main/java/tntrun/utils/Utils.java @@ -170,22 +170,22 @@ public static void displayHelp(Player player) { player.spigot().sendMessage(getTextComponent("/trsetup finish {arena}", true), getTextComponent(Messages.setupfinish)); } + /** + * Display a clickable invitation message when the first player joins an arena. + * + * @param player first player that joins an arena + * @param arenaname + * @param joinMessage + */ public static void displayJoinMessage(Player player, String arenaname, String joinMessage) { + final String command = "/tntrun joinorspectate "; final String border = FormattingCodesParser.parseFormattingCodes(Messages.playerborderinvite); TextComponent jointc = new TextComponent(TextComponent.fromLegacy(border + "\n")); - jointc.addExtra(getJoinTextComponent(joinMessage, arenaname)); - jointc.addExtra(new TextComponent(TextComponent.fromLegacy("\n" + border))); - player.spigot().sendMessage(jointc); - } - private static TextComponent getJoinTextComponent(String text, String arenaname) { - String hoverMessage = FormattingCodesParser.parseFormattingCodes(Messages.playerclickinvite.replace("{ARENA}", arenaname)); - Content content = new Text(hoverMessage); - TextComponent component = new TextComponent(TextComponent.fromLegacy(ChatColor.translateAlternateColorCodes('&', text))); + jointc.addExtra(buildComponent(joinMessage, Messages.playerclickinvite.replace("{ARENA}", arenaname), arenaname, command)); - component.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tntrun joinorspectate " + arenaname)); - component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, content)); - return component; + jointc.addExtra(new TextComponent(TextComponent.fromLegacy("\n" + border))); + player.spigot().sendMessage(jointc); } public static String getTitleCase(String input) { @@ -410,21 +410,37 @@ public static int getAllowedDoubleJumps(Player player, int max) { return max; } - public static void displayPartyInvite(Player player, String target, String joinMessage) { - TextComponent partytc = new TextComponent(TextComponent.fromLegacy("Would you like to ")); - partytc.addExtra(getPartyInviteComponent("Accept", "Click to Accept", player, target)); - partytc.addExtra(" or "); - partytc.addExtra(getPartyInviteComponent("Decline", "Click to Decline", player, target)); - partytc.addExtra(" the party invitation?"); - Bukkit.getPlayer(target).spigot().sendMessage(partytc); + /** + * Display a clickable invitation to join a TNTRun party. + * + * @param player party leader + * @param target player being invited + */ + public static void displayPartyInvite(Player player, String target) { + final String command1 = "/tntrun party accept "; + final String command2 = "/tntrun party decline "; + + TextComponent accept = buildComponent(Messages.partyclickaccept, Messages.partyaccepttext, player.getName(), command1); + TextComponent decline = buildComponent(Messages.partyclickdecline, Messages.partydeclinetext, player.getName(), command2); + accept.addExtra(" | "); + + Bukkit.getPlayer(target).spigot().sendMessage(accept, decline); } - private static TextComponent getPartyInviteComponent(String text, String hoverMessage, Player player, String target) { - Content content = new Text(hoverMessage); - TextComponent component = new TextComponent(text); - component.setColor(ChatColor.GOLD); - component.setBold(true); - component.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tntrun party " + text + " " + player.getName())); + /** + * Add the click event and hover text to the text component. + * + * @param text + * @param hoverMessage + * @param target target of command, e.g. party leader or arena + * @param command + * @return + */ + private static TextComponent buildComponent(String text, String hoverMessage, String target, String command) { + Content content = new Text(ChatColor.translateAlternateColorCodes('&', hoverMessage)); + TextComponent component = new TextComponent(ChatColor.translateAlternateColorCodes('&', text)); + + component.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command + target)); component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, content)); return component; }