Search in sources :

Example 6 with ISoliniaGod

use of com.solinia.solinia.Interfaces.ISoliniaGod in project solinia3-core by mixxit.

the class CommandSetGod method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player) && !(sender instanceof CommandSender))
        return false;
    sender.sendMessage("See /godinfo for more information");
    String godlist = "";
    List<ISoliniaGod> gods = new ArrayList<ISoliniaGod>();
    try {
        for (ISoliniaGod god : StateManager.getInstance().getConfigurationManager().getGods()) {
            godlist = godlist + " " + ChatColor.LIGHT_PURPLE + god.getName().toUpperCase() + ChatColor.RESET;
            gods.add(god);
        }
    } catch (CoreStateInitException e1) {
        sender.sendMessage("God command failed. " + e1.getMessage());
        return false;
    }
    if ((sender instanceof ConsoleCommandSender)) {
        try {
            ChatUtils.sendGodInfo(sender);
        } catch (CoreStateInitException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return true;
    }
    Player player = (Player) sender;
    ISoliniaPlayer soliniaplayer;
    try {
        soliniaplayer = SoliniaPlayerAdapter.Adapt(player);
    } catch (CoreStateInitException e2) {
        player.sendMessage("God command failed. " + e2.getMessage());
        return false;
    }
    if (soliniaplayer.hasChosenGod() == true) {
        player.sendMessage("You cannot choose a god as you have already selected one");
        return true;
    }
    if (args.length == 0) {
        try {
            ChatUtils.sendGodInfo(sender);
        } catch (CoreStateInitException e1) {
        }
        player.sendMessage("Insufficient arguments. Please provide correct god name");
        if (soliniaplayer != null) {
            ISoliniaGod solgod;
            try {
                solgod = StateManager.getInstance().getConfigurationManager().getGod(soliniaplayer.getGodId());
            } catch (CoreStateInitException e) {
                player.sendMessage("God command failed. " + e.getMessage());
                return false;
            }
            if (solgod == null)
                player.sendMessage("Your current god is: UNKNOWN");
            else
                player.sendMessage("Your current god is: " + solgod.getName());
        }
        return false;
    }
    String god = args[0].toUpperCase();
    boolean found = false;
    for (ISoliniaGod allowedgod : gods) {
        if (allowedgod.getName().equals(god)) {
            found = true;
        }
    }
    if (found == false) {
        try {
            ChatUtils.sendGodInfo(sender);
        } catch (CoreStateInitException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        player.sendMessage("Insufficient arguments. Please provide correct god name");
        return false;
    }
    try {
        if (StateManager.getInstance().getConfigurationManager().getGod(god) != null) {
            ISoliniaGod solGod = StateManager.getInstance().getConfigurationManager().getGod(god);
            soliniaplayer.setGodId(solGod.getId());
            soliniaplayer.setHasChosenGod(true);
            player.sendMessage("* God set to " + god);
            return true;
        } else {
            ChatUtils.sendGodInfo(sender);
            player.sendMessage("Insufficient arguments. Please provide correct god name");
            return false;
        }
    } catch (CoreStateInitException e) {
        player.sendMessage("God command failed. " + e.getMessage());
        return false;
    }
}
Also used : ISoliniaGod(com.solinia.solinia.Interfaces.ISoliniaGod) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ArrayList(java.util.ArrayList) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender)

Aggregations

ISoliniaGod (com.solinia.solinia.Interfaces.ISoliniaGod)6 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)3 CommandSender (org.bukkit.command.CommandSender)3 Player (org.bukkit.entity.Player)3 ArrayList (java.util.ArrayList)2 Gson (com.google.gson.Gson)1 InvalidGodSettingException (com.solinia.solinia.Exceptions.InvalidGodSettingException)1 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)1 SoliniaGod (com.solinia.solinia.Models.SoliniaGod)1 BufferedReader (java.io.BufferedReader)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 List (java.util.List)1 ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)1 HoverEvent (net.md_5.bungee.api.chat.HoverEvent)1 TextComponent (net.md_5.bungee.api.chat.TextComponent)1 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)1