use of net.md_5.bungee.api.chat.HoverEvent in project Ublisk by Derkades.
the class StatsCommand method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
UPlayer player = new UPlayer(sender);
if (args.length == 1) {
UPlayer target = null;
try {
target = new UPlayer(args[1]);
} catch (PlayerNotFoundException e) {
player.sendMessage(Message.PLAYER_NOT_FOUND);
return true;
}
BaseComponent[] hoverText = new ComponentBuilder("yes click me pls").create();
BaseComponent[] text = new ComponentBuilder("Click here to open " + target.getName() + "'s statistics page in your browser.").color(ChatColor.AQUA).bold(true).event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)).event(new ClickEvent(ClickEvent.Action.OPEN_URL, target.getStatsURL())).create();
player.sendMessage(text);
return true;
} else if (args.length == 0) {
BaseComponent[] hoverText = new ComponentBuilder("yes click me pls").create();
BaseComponent[] text = new ComponentBuilder("Click here to open your statistics page in your browser.").color(ChatColor.AQUA).bold(true).event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)).event(new ClickEvent(ClickEvent.Action.OPEN_URL, player.getStatsURL())).create();
player.sendMessage(text);
return true;
} else {
return false;
}
}
use of net.md_5.bungee.api.chat.HoverEvent in project Statz by Staartvin.
the class CommandsManager method onCommand.
/* (non-Javadoc)
* @see org.bukkit.command.CommandExecutor#onCommand(org.bukkit.command.CommandSender, org.bukkit.command.Command, java.lang.String, java.lang.String[])
*/
@Override
public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) {
if (args.length == 0) {
// If admin has predefined a list of stats, show that instead of the list view of all stats.
if (plugin.getConfigHandler().useCustomList() && sender instanceof Player) {
Player player = (Player) sender;
// Show custom stats that admin has provided in the config.
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
private String playerName;
private UUID uuid;
private int pageNumber;
private Runnable init(String playerName, UUID uuid, int pageNumber) {
this.playerName = playerName;
this.uuid = uuid;
this.pageNumber = pageNumber - 1;
return this;
}
public void run() {
plugin.getDataManager().sendStatisticsList(sender, playerName, uuid, pageNumber, plugin.getConfigHandler().getCustomList());
}
}.init(sender.getName(), player.getUniqueId(), 0));
return true;
} else {
// Just show information about the plugin.
sender.sendMessage(ChatColor.BLUE + "-----------------------------------------------------");
sender.sendMessage(ChatColor.GOLD + "Developed by: " + ChatColor.GRAY + plugin.getDescription().getAuthors());
sender.sendMessage(ChatColor.GOLD + "Version: " + ChatColor.GRAY + plugin.getDescription().getVersion());
sender.sendMessage(Lang.STATZ_HELP_COMMAND.getConfigValue());
}
return true;
}
final String action = args[0];
List<String> suggestions = new ArrayList<>();
List<String> bestSuggestions = new ArrayList<>();
// Go through every list and check if that action is in there.
for (final Entry<List<String>, StatzCommand> entry : registeredCommands.entrySet()) {
String suggestion = StatzUtil.findClosestSuggestion(action, entry.getKey());
if (suggestion != null) {
suggestions.add(suggestion);
}
for (final String actionString : entry.getKey()) {
if (actionString.equalsIgnoreCase(action)) {
// Check if player has proper permission
if (!this.hasPermission(entry.getValue().getPermission(), sender)) {
return true;
}
return entry.getValue().onCommand(sender, cmd, label, args);
}
}
}
// Search for suggestions if argument was not found
for (String suggestion : suggestions) {
String[] split = suggestion.split(";");
int editDistance = Integer.parseInt(split[1]);
// Only give suggestion if edit distance is small
if (editDistance <= 2) {
bestSuggestions.add(split[0]);
}
}
sender.sendMessage(Lang.COMMAND_NOT_RECOGNIZED.getConfigValue());
if (!bestSuggestions.isEmpty()) {
BaseComponent[] builder = new ComponentBuilder("Did you perhaps mean ").color(net.md_5.bungee.api.ChatColor.DARK_AQUA).append("/statz ").color(net.md_5.bungee.api.ChatColor.GREEN).append(StatzUtil.seperateList(bestSuggestions, "or")).event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("These are suggestions based on your input.").create())).append("?").color(net.md_5.bungee.api.ChatColor.DARK_AQUA).create();
if (sender instanceof Player) {
Player p = (Player) sender;
p.spigot().sendMessage(builder);
} else {
sender.sendMessage(ChatColor.DARK_AQUA + "Did you perhaps mean " + ChatColor.GREEN + "/statz " + StatzUtil.seperateList(bestSuggestions, "or") + ChatColor.DARK_AQUA + "?");
}
}
sender.sendMessage(Lang.STATZ_HELP_COMMAND.getConfigValue());
return true;
}
Aggregations