Search in sources :

Example 16 with BaseComponent

use of net.md_5.bungee.api.chat.BaseComponent 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)

Example 17 with BaseComponent

use of net.md_5.bungee.api.chat.BaseComponent in project Minigames by AddstarMC.

the class MessageManager method sendClickedCommandMessage.

public static void sendClickedCommandMessage(CommandSender target, String command, String identifier, String key, Object... args) {
    BaseComponent init = getMessageStart(MinigameMessageType.INFO);
    TextComponent message = new TextComponent(getMessage(identifier, key, args));
    message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command));
    sendMessage(target, init, message);
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) BaseComponent(net.md_5.bungee.api.chat.BaseComponent) ClickEvent(net.md_5.bungee.api.chat.ClickEvent)

Example 18 with BaseComponent

use of net.md_5.bungee.api.chat.BaseComponent in project Minigames by AddstarMC.

the class MessageManager method sendMessage.

public static void sendMessage(CommandSender target, MinigameMessageType type, String identifier, String key, Object... args) {
    BaseComponent init = getMessageStart(type);
    TextComponent message = new TextComponent(getMessage(identifier, key, args));
    sendMessage(target, init, message);
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) BaseComponent(net.md_5.bungee.api.chat.BaseComponent)

Example 19 with BaseComponent

use of net.md_5.bungee.api.chat.BaseComponent in project Minigames by AddstarMC.

the class MessageManager method broadcast.

/**
 * Broadcasts a server message without a permission.
 *
 * @param message     - The message to be broadcasted (Can be manipulated with MinigamesBroadcastEvent)
 * @param minigame    - The Minigame this broadcast is related to.
 * @param prefixColor - The color to be used in the prefix.
 */
public static void broadcast(String message, Minigame minigame, org.bukkit.ChatColor prefixColor) {
    BaseComponent init = new TextComponent("[Minigames]");
    init.setColor(prefixColor.asBungee());
    TextComponent m = new TextComponent(" " + message);
    MinigamesBroadcastEvent ev = new MinigamesBroadcastEvent(prefixColor + "[Minigames]" + org.bukkit.ChatColor.WHITE, message, minigame);
    Bukkit.getPluginManager().callEvent(ev);
    // Only send broadcast if event was not cancelled and is not empty
    if (!ev.isCancelled() && !ev.getMessage().isEmpty()) {
        if (PaperLib.isPaper()) {
            Bukkit.getServer().broadcast(init, m);
        } else {
            Bukkit.getServer().spigot().broadcast(init, m);
        }
    }
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) BaseComponent(net.md_5.bungee.api.chat.BaseComponent) MinigamesBroadcastEvent(au.com.mineauz.minigames.events.MinigamesBroadcastEvent)

Example 20 with BaseComponent

use of net.md_5.bungee.api.chat.BaseComponent in project Denizen-For-Bukkit by DenizenScript.

the class ItemHelperImpl method getLore.

@Override
public List<String> getLore(ItemTag item) {
    if (!item.getItemMeta().hasLore()) {
        return null;
    }
    net.minecraft.world.item.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(item.getItemStack());
    ListTag list = ((net.minecraft.nbt.CompoundTag) nmsItemStack.getTag().get("display")).getList("Lore", 8);
    List<String> outList = new ArrayList<>();
    for (int i = 0; i < list.size(); i++) {
        BaseComponent[] lineComponent = ComponentSerializer.parse(list.getString(i));
        outList.add(FormattedTextHelper.stringify(lineComponent, ChatColor.WHITE));
    }
    return outList;
}
Also used : BaseComponent(net.md_5.bungee.api.chat.BaseComponent) ListTag(net.minecraft.nbt.ListTag)

Aggregations

BaseComponent (net.md_5.bungee.api.chat.BaseComponent)23 TextComponent (net.md_5.bungee.api.chat.TextComponent)8 ClickEvent (net.md_5.bungee.api.chat.ClickEvent)7 ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)6 HoverEvent (net.md_5.bungee.api.chat.HoverEvent)5 Player (org.bukkit.entity.Player)4 BookMeta (org.bukkit.inventory.meta.BookMeta)4 UPlayer (xyz.derkades.ublisk.utils.UPlayer)4 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)3 ListTag (com.denizenscript.denizencore.objects.core.ListTag)3 ChatColor (net.md_5.bungee.api.ChatColor)3 MapTag (com.denizenscript.denizencore.objects.core.MapTag)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ListTag (net.minecraft.nbt.ListTag)2 EventHandler (org.bukkit.event.EventHandler)2 PlayerNotFoundException (xyz.derkades.ublisk.utils.exception.PlayerNotFoundException)2 MinigamesBroadcastEvent (au.com.mineauz.minigames.events.MinigamesBroadcastEvent)1 EntityTag (com.denizenscript.denizen.objects.EntityTag)1 ItemTag (com.denizenscript.denizen.objects.ItemTag)1