Search in sources :

Example 11 with HoverEvent

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;
    }
}
Also used : HoverEvent(net.md_5.bungee.api.chat.HoverEvent) BaseComponent(net.md_5.bungee.api.chat.BaseComponent) UPlayer(xyz.derkades.ublisk.utils.UPlayer) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) PlayerNotFoundException(xyz.derkades.ublisk.utils.exception.PlayerNotFoundException) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Example 12 with HoverEvent

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;
}
Also used : HoverEvent(net.md_5.bungee.api.chat.HoverEvent) Player(org.bukkit.entity.Player) BaseComponent(net.md_5.bungee.api.chat.BaseComponent) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Aggregations

ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)12 HoverEvent (net.md_5.bungee.api.chat.HoverEvent)12 TextComponent (net.md_5.bungee.api.chat.TextComponent)9 ClickEvent (net.md_5.bungee.api.chat.ClickEvent)7 Player (org.bukkit.entity.Player)6 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)4 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)4 BaseComponent (net.md_5.bungee.api.chat.BaseComponent)4 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)2 UUID (java.util.UUID)2 EventHandler (org.bukkit.event.EventHandler)2 UPlayer (xyz.derkades.ublisk.utils.UPlayer)2 SoliniaItemException (com.solinia.solinia.Exceptions.SoliniaItemException)1 ISoliniaAAAbility (com.solinia.solinia.Interfaces.ISoliniaAAAbility)1 ISoliniaAARank (com.solinia.solinia.Interfaces.ISoliniaAARank)1 ISoliniaClass (com.solinia.solinia.Interfaces.ISoliniaClass)1 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)1 ISoliniaRace (com.solinia.solinia.Interfaces.ISoliniaRace)1 SoliniaAccountClaim (com.solinia.solinia.Models.SoliniaAccountClaim)1 Map (java.util.Map)1