Add click event to confirmation strings

This commit is contained in:
Jakub Kolář 2016-04-16 00:14:14 +02:00
parent 6c50eaf6c4
commit 2ce8337ed5
5 changed files with 85 additions and 3 deletions

View File

@ -95,6 +95,55 @@ public interface JSONHoverAction<T> {
}
/**
* Shows some JSON-formed text when hovering over the text in the chat.
*/
public class ShowStringText
implements JSONHoverAction<String> {
/**
* 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<String> 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.
*/

View File

@ -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,

View File

@ -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 {

View File

@ -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!");
}

View File

@ -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!'