Search in sources :

Example 6 with SoliniaDisguise

use of com.solinia.solinia.Models.SoliniaDisguise in project solinia3-core by mixxit.

the class CommandListDisguises method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player) && !(sender instanceof CommandSender))
        return false;
    if (!sender.isOp() && !sender.hasPermission("solinia.listdisguises")) {
        sender.sendMessage("You do not have permission to access this command");
        return false;
    }
    try {
        if (args.length == 0) {
            // Return all
            for (SoliniaDisguise entity : StateManager.getInstance().getConfigurationManager().getSoliniaDisguises()) {
                TextComponent textComponent = new TextComponent();
                String title = "DisguiseId: " + ChatColor.GOLD + entity.getId() + ChatColor.RESET + " - " + entity.getDisguiseName();
                textComponent.setText(title);
                String transfertext = "/editdisguise" + entity.getId() + "";
                textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, transfertext));
                sender.spigot().sendMessage(textComponent);
            }
            return true;
        }
        if (args.length > 0 && args[0].equals(".criteria")) {
            try {
                ChatUtils.sendFilterByCriteria(StateManager.getInstance().getConfigurationManager().getSoliniaDisguises(), sender, args, SoliniaDisguise.class);
                return true;
            } catch (CoreStateInitException e) {
                // TODO Auto-generated catch block
                sender.sendMessage(e.getMessage());
                e.printStackTrace();
            }
        }
        // Filter for name
        for (SoliniaDisguise entity : StateManager.getInstance().getConfigurationManager().getSoliniaDisguises()) {
            if (entity.getDisguiseName().toUpperCase().contains(args[0].toUpperCase())) {
                TextComponent textComponent = new TextComponent();
                String title = "DisguiseID: " + ChatColor.GOLD + entity.getId() + ChatColor.RESET + " - " + entity.getDisguiseName();
                textComponent.setText(title);
                String transfertext = "/editdisguise " + entity.getId() + "";
                textComponent.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, transfertext));
                sender.spigot().sendMessage(textComponent);
            }
        }
    } catch (CoreStateInitException e) {
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) Player(org.bukkit.entity.Player) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) CommandSender(org.bukkit.command.CommandSender) SoliniaDisguise(com.solinia.solinia.Models.SoliniaDisguise)

Aggregations

SoliniaDisguise (com.solinia.solinia.Models.SoliniaDisguise)6 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)3 CommandSender (org.bukkit.command.CommandSender)3 Player (org.bukkit.entity.Player)3 Gson (com.google.gson.Gson)2 SoliniaDisguiseCreationException (com.solinia.solinia.Exceptions.SoliniaDisguiseCreationException)2 FileNotFoundException (java.io.FileNotFoundException)2 GsonBuilder (com.google.gson.GsonBuilder)1 TypeToken (com.google.gson.reflect.TypeToken)1 InvalidDisguiseSettingException (com.solinia.solinia.Exceptions.InvalidDisguiseSettingException)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ClickEvent (net.md_5.bungee.api.chat.ClickEvent)1 TextComponent (net.md_5.bungee.api.chat.TextComponent)1