From 2ce8337ed5120fc63ee6902d46d0da616aafa023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kol=C3=A1=C5=99?= Date: Sat, 16 Apr 2016 00:14:14 +0200 Subject: [PATCH] Add click event to confirmation strings --- .../mcapi/json/JSONHoverAction.java | 49 +++++++++++++++++++ .../cz/boosik/boosCooldown/BoosCoolDown.java | 4 +- .../boosCooldown/BoosCoolDownListener.java | 25 +++++++++- .../Managers/BoosConfigManager.java | 8 +++ plugin/src/main/resources/config.yml | 2 + 5 files changed, 85 insertions(+), 3 deletions(-) diff --git a/plugin/src/main/java/com/coloredcarrot/mcapi/json/JSONHoverAction.java b/plugin/src/main/java/com/coloredcarrot/mcapi/json/JSONHoverAction.java index 220ab0e..422ff01 100644 --- a/plugin/src/main/java/com/coloredcarrot/mcapi/json/JSONHoverAction.java +++ b/plugin/src/main/java/com/coloredcarrot/mcapi/json/JSONHoverAction.java @@ -95,6 +95,55 @@ public interface JSONHoverAction { } + /** + * Shows some JSON-formed text when hovering over the text in the chat. + */ + public class ShowStringText + implements JSONHoverAction { + + /** + * The action name + * + * @see #getActionName() + */ + public static final String NAME = "show_text"; + + private String value; + + /** + * Constructs a {@link JSONHoverAction.ShowText} + * + * @param value (JSON) - the value associated with this JSONHoverAction + */ + public ShowStringText(String value) { + + this.value = value; + + } + + @Override + public String getValue() { + return value; + } + + @Override + public JSONHoverAction setValue(String newValue) { + value = newValue; + return this; + } + + @Override + public String getValueString() { + return value + "\""; + } + + @Override + public String getActionName() { + return NAME; + } + + } + /** * Shows an item when hovering over the text in the chat. */ diff --git a/plugin/src/main/java/cz/boosik/boosCooldown/BoosCoolDown.java b/plugin/src/main/java/cz/boosik/boosCooldown/BoosCoolDown.java index 2c8c137..5fb1cfa 100644 --- a/plugin/src/main/java/cz/boosik/boosCooldown/BoosCoolDown.java +++ b/plugin/src/main/java/cz/boosik/boosCooldown/BoosCoolDown.java @@ -209,7 +209,9 @@ public class BoosCoolDown extends JavaPlugin implements Runnable { String jmeno = args[1]; Player player = Bukkit.getPlayerExact(jmeno); UUID uuid = player.getUniqueId(); - if (sender.hasPermission("booscooldowns.clearcooldowns") && args[0].equalsIgnoreCase("clearcooldowns")) { + if (args[0].equalsIgnoreCase("chat")) { + player.chat(args[1]); + } else if (sender.hasPermission("booscooldowns.clearcooldowns") && args[0].equalsIgnoreCase("clearcooldowns")) { String co = "cooldown"; BoosConfigManager.clearSomething(co, uuid); boosChat.sendMessageToCommandSender(sender, diff --git a/plugin/src/main/java/cz/boosik/boosCooldown/BoosCoolDownListener.java b/plugin/src/main/java/cz/boosik/boosCooldown/BoosCoolDownListener.java index 334df7c..2519912 100644 --- a/plugin/src/main/java/cz/boosik/boosCooldown/BoosCoolDownListener.java +++ b/plugin/src/main/java/cz/boosik/boosCooldown/BoosCoolDownListener.java @@ -20,6 +20,10 @@ import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import com.coloredcarrot.mcapi.json.JSON; +import com.coloredcarrot.mcapi.json.JSONClickAction; +import com.coloredcarrot.mcapi.json.JSONColor; +import com.coloredcarrot.mcapi.json.JSONComponent; +import com.coloredcarrot.mcapi.json.JSONHoverAction; import cz.boosik.boosCooldown.Managers.BoosAliasManager; import cz.boosik.boosCooldown.Managers.BoosConfigManager; import cz.boosik.boosCooldown.Managers.BoosCoolDownManager; @@ -295,8 +299,25 @@ public class BoosCoolDownListener implements Listener { .replace("&uses&", String.valueOf(limit - uses)); boosChat.sendMessageToPlayer(player, " " + limitMessage); } - boosChat.sendMessageToPlayer(player, " &2" + BoosConfigManager.getConfirmCommandMessage()); - boosChat.sendMessageToPlayer(player, " &c" + BoosConfigManager.getCancelCommandMessage()); + String yesString = BoosConfigManager.getConfirmCommandMessage(); + JSONClickAction yesClick = new JSONClickAction.RunCommand(yesString); + JSONHoverAction yesHover = new JSONHoverAction.ShowStringText(BoosConfigManager.getConfirmCommandHint()); + JSONComponent yes = new JSONComponent(" " + yesString); + yes.setColor(JSONColor.GREEN).setBold(true); + yes.setClickAction(yesClick); + yes.setHoverAction(yesHover); + String test = yes.get(); + yes.send(player); + + String noString = BoosConfigManager.getCancelCommandMessage(); + JSONClickAction noClick = new JSONClickAction.RunCommand(noString); + JSONHoverAction noHover = new JSONHoverAction.ShowStringText(BoosConfigManager.getCancelCommandHint()); + JSONComponent no = new JSONComponent(" " + noString); + no.setColor(JSONColor.RED).setBold(true); + no.setClickAction(noClick); + no.setHoverAction(noHover); + no.send(player); + event.setCancelled(true); return; } else { diff --git a/plugin/src/main/java/cz/boosik/boosCooldown/Managers/BoosConfigManager.java b/plugin/src/main/java/cz/boosik/boosCooldown/Managers/BoosConfigManager.java index 9c742da..5108641 100644 --- a/plugin/src/main/java/cz/boosik/boosCooldown/Managers/BoosConfigManager.java +++ b/plugin/src/main/java/cz/boosik/boosCooldown/Managers/BoosConfigManager.java @@ -614,6 +614,14 @@ public class BoosConfigManager { return conf.getString("options.messages.confirmation_confirm_command_execution", "Yes"); } + public static String getCancelCommandHint() { + return conf.getString("options.messages.confirmation_cancel_command_execution_hint", "Click to cancel"); + } + + public static String getConfirmCommandHint() { + return conf.getString("options.messages.confirmation_confirm_command_execution_hint", "Click to confirm"); + } + public static String getConfirmToggleMessageTrue() { return conf.getString("options.messages.confirmation_toggle_enable", "Confirmation messages are now enabled for you!"); } diff --git a/plugin/src/main/resources/config.yml b/plugin/src/main/resources/config.yml index 3d3825d..4d7f610 100644 --- a/plugin/src/main/resources/config.yml +++ b/plugin/src/main/resources/config.yml @@ -87,7 +87,9 @@ options: confirmation_limit_of_command: '&6it is limited to&e &limit& &6uses and you can still use it&e &uses& &6times' confirmation_xp_price_of_command: '&6its price is&e &xpprice& experience levels' confirmation_confirm_command_execution: 'Yes' + confirmation_confirm_command_execution_hint: 'Click to confirm' confirmation_cancel_command_execution: 'No' + confirmation_cancel_command_execution_hint: 'Click to cancel' confirmation_command_cancelled: '&6Execution of command&e &command& &6was cancelled' confirmation_toggle_disable: 'Confirmation messages are now disabled for you!' confirmation_toggle_enable: 'Confirmation messages are now enabled for you!'