Search in sources :

Example 1 with DiscordAdminChannelCommandSender

use of com.solinia.solinia.Providers.DiscordAdminChannelCommandSender in project solinia3-core by mixxit.

the class CommandSetClass method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player))
        return false;
    try {
        String prolist = "";
        String prolistunformatted = "";
        List<ISoliniaClass> pros = new ArrayList<ISoliniaClass>();
        List<ISoliniaClass> rawpros = StateManager.getInstance().getConfigurationManager().getClasses();
        if ((sender instanceof ConsoleCommandSender || sender instanceof DiscordDefaultChannelCommandSender || sender instanceof DiscordAdminChannelCommandSender)) {
            String tmplist = "";
            for (ISoliniaClass pro : rawpros) {
                tmplist = prolist + " " + ChatColor.LIGHT_PURPLE + pro.getName().toUpperCase() + ChatColor.RESET + "(A:" + pro.isAdmin() + ")";
            }
            sender.sendMessage(tmplist);
            return true;
        }
        Player player = (Player) sender;
        try {
            ISoliniaPlayer soliniaplayer = SoliniaPlayerAdapter.Adapt(player);
            if (soliniaplayer.hasChosenRace() == false) {
                SendProfessionFull(sender, rawpros);
                sender.sendMessage("You cannot pick a profession until you set your race with /setrace");
                return true;
            }
            if (soliniaplayer.hasChosenClass() == true) {
                SendProfessionFull(sender, rawpros);
                sender.sendMessage("You cannot pick a profession as you have already chosen one");
                return true;
            }
            for (ISoliniaClass pro : rawpros) {
                if (!pro.isAdmin() && StateManager.getInstance().getConfigurationManager().isValidRaceClass(soliniaplayer.getRaceId(), pro.getId())) {
                    prolist = prolist + " " + ChatColor.LIGHT_PURPLE + pro.getName().toUpperCase() + ChatColor.RESET;
                    prolistunformatted = prolistunformatted + " " + pro.getName().toUpperCase();
                    pros.add(pro);
                }
            }
            if (args.length == 0) {
                SendProfessionList(sender, rawpros, prolistunformatted);
                sender.sendMessage("Insufficient arguments Valid Professions are: [" + prolist + "]");
                if (soliniaplayer != null) {
                    ISoliniaClass profession = StateManager.getInstance().getConfigurationManager().getClassObj(soliniaplayer.getClassId());
                    if (profession != null)
                        sender.sendMessage("Your current profession is: " + profession.getName());
                    else
                        sender.sendMessage("Your current profession is: UNKNOWN");
                }
                return false;
            }
            String profession = args[0].toUpperCase();
            boolean found = false;
            ISoliniaClass solprofession = null;
            for (ISoliniaClass allowedprofession : pros) {
                if (allowedprofession.getName().equals(profession)) {
                    solprofession = allowedprofession;
                    found = true;
                }
            }
            if (found == false) {
                SendProfessionList(sender, rawpros, prolistunformatted);
                return false;
            }
            if (!StateManager.getInstance().getConfigurationManager().isValidRaceClass(soliniaplayer.getRaceId(), solprofession.getId())) {
                SendProfessionList(sender, rawpros, prolistunformatted);
                sender.sendMessage("That is not a valid Race / Profession");
                return true;
            }
            soliniaplayer.setClassId(solprofession.getId());
            soliniaplayer.setChosenClass(true);
            sender.sendMessage("* Profession set to " + profession);
            ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(player);
            solplayer.updateMaxHp();
            return true;
        } catch (CoreStateInitException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } catch (CoreStateInitException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
        sender.sendMessage(e1.getMessage());
        return false;
    }
    return true;
}
Also used : ISoliniaClass(com.solinia.solinia.Interfaces.ISoliniaClass) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) DiscordAdminChannelCommandSender(com.solinia.solinia.Providers.DiscordAdminChannelCommandSender) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ArrayList(java.util.ArrayList) DiscordDefaultChannelCommandSender(com.solinia.solinia.Providers.DiscordDefaultChannelCommandSender) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender)

Example 2 with DiscordAdminChannelCommandSender

use of com.solinia.solinia.Providers.DiscordAdminChannelCommandSender in project solinia3-core by mixxit.

the class CommandSetRace 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 /raceinfo for more information");
    String racelist = "";
    List<ISoliniaRace> races = new ArrayList<ISoliniaRace>();
    try {
        for (ISoliniaRace race : StateManager.getInstance().getConfigurationManager().getRaces()) {
            if (!race.isAdmin()) {
                racelist = racelist + " " + ChatColor.LIGHT_PURPLE + race.getName().toUpperCase() + ChatColor.RESET;
                races.add(race);
            }
        }
    } catch (CoreStateInitException e1) {
        sender.sendMessage("Race command failed. " + e1.getMessage());
        return false;
    }
    if ((sender instanceof ConsoleCommandSender || sender instanceof DiscordDefaultChannelCommandSender || sender instanceof DiscordAdminChannelCommandSender)) {
        try {
            Utils.sendRaceInfo(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("Race command failed. " + e2.getMessage());
        return false;
    }
    if (soliniaplayer.hasChosenRace() == true) {
        player.sendMessage("You cannot choose a race as you have already selected one");
        return true;
    }
    if (args.length == 0) {
        try {
            Utils.sendRaceInfo(sender);
        } catch (CoreStateInitException e1) {
        }
        player.sendMessage("Insufficient arguments. Please provide correct race name");
        if (soliniaplayer != null) {
            ISoliniaRace solrace;
            try {
                solrace = StateManager.getInstance().getConfigurationManager().getRace(soliniaplayer.getRaceId());
            } catch (CoreStateInitException e) {
                player.sendMessage("Race command failed. " + e.getMessage());
                return false;
            }
            if (solrace == null)
                player.sendMessage("Your current race is: UNKNOWN");
            else
                player.sendMessage("Your current race is: " + solrace.getName());
        }
        return false;
    }
    String race = args[0].toUpperCase();
    boolean found = false;
    for (ISoliniaRace allowedrace : races) {
        if (allowedrace.getName().equals(race)) {
            found = true;
        }
    }
    if (found == false) {
        try {
            Utils.sendRaceInfo(sender);
        } catch (CoreStateInitException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        player.sendMessage("Insufficient arguments. Please provide correct race name");
        return false;
    }
    try {
        if (StateManager.getInstance().getConfigurationManager().getRace(race) != null) {
            soliniaplayer.setRaceId(StateManager.getInstance().getConfigurationManager().getRace(race).getId());
            soliniaplayer.setChosenRace(true);
            player.sendMessage("* Race set to " + race);
            return true;
        } else {
            Utils.sendRaceInfo(sender);
            player.sendMessage("Insufficient arguments. Please provide correct race name");
            return false;
        }
    } catch (CoreStateInitException e) {
        player.sendMessage("Race command failed. " + e.getMessage());
        return false;
    }
}
Also used : Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) DiscordAdminChannelCommandSender(com.solinia.solinia.Providers.DiscordAdminChannelCommandSender) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ArrayList(java.util.ArrayList) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) DiscordDefaultChannelCommandSender(com.solinia.solinia.Providers.DiscordDefaultChannelCommandSender) DiscordAdminChannelCommandSender(com.solinia.solinia.Providers.DiscordAdminChannelCommandSender) DiscordDefaultChannelCommandSender(com.solinia.solinia.Providers.DiscordDefaultChannelCommandSender) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaRace(com.solinia.solinia.Interfaces.ISoliniaRace) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender)

Example 3 with DiscordAdminChannelCommandSender

use of com.solinia.solinia.Providers.DiscordAdminChannelCommandSender in project solinia3-core by mixxit.

the class CommandWho method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (sender instanceof Player) {
        Player player = (Player) sender;
        for (Player currentplayer : Bukkit.getServer().getOnlinePlayers()) {
            try {
                ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(currentplayer);
                int lvl = (int) Math.floor(solplayer.getLevel());
                String racename = "UNKNOWN";
                String classname = "UNKNOWN";
                if (solplayer.getRace() != null)
                    racename = solplayer.getRace().getName();
                if (solplayer.getClassObj() != null)
                    classname = solplayer.getClassObj().getName();
                player.sendMessage("[" + currentplayer.getName() + "]" + ChatColor.YELLOW + solplayer.getFullName().toUpperCase() + ChatColor.RESET + " [" + currentplayer.getWorld().getName() + "] - LVL " + ChatColor.AQUA + lvl + ChatColor.RESET + " " + racename + " " + ChatColor.AQUA + classname + ChatColor.RESET);
            } catch (CoreStateInitException e) {
            }
        }
    }
    if ((sender instanceof ConsoleCommandSender || sender instanceof DiscordDefaultChannelCommandSender || sender instanceof DiscordAdminChannelCommandSender)) {
        CommandSender player = (CommandSender) sender;
        for (Player currentplayer : Bukkit.getServer().getOnlinePlayers()) {
            ISoliniaPlayer solplayer;
            try {
                solplayer = SoliniaPlayerAdapter.Adapt(currentplayer);
                int lvl = (int) Math.floor(solplayer.getLevel());
                String racename = "UNKNOWN";
                String classname = "UNKNOWN";
                if (solplayer.getRace() != null)
                    racename = solplayer.getRace().getName();
                if (solplayer.getClassObj() != null)
                    classname = solplayer.getClassObj().getName();
                player.sendMessage("[" + currentplayer.getName() + "]" + ChatColor.YELLOW + solplayer.getFullName().toUpperCase() + ChatColor.RESET + " [" + currentplayer.getWorld().getName() + "] - LVL " + ChatColor.AQUA + lvl + ChatColor.RESET + " " + racename + " " + ChatColor.AQUA + classname + ChatColor.RESET);
            } catch (CoreStateInitException e) {
            }
        }
    }
    return true;
}
Also used : ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) Player(org.bukkit.entity.Player) DiscordAdminChannelCommandSender(com.solinia.solinia.Providers.DiscordAdminChannelCommandSender) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) DiscordDefaultChannelCommandSender(com.solinia.solinia.Providers.DiscordDefaultChannelCommandSender) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) DiscordDefaultChannelCommandSender(com.solinia.solinia.Providers.DiscordDefaultChannelCommandSender) DiscordAdminChannelCommandSender(com.solinia.solinia.Providers.DiscordAdminChannelCommandSender) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender)

Example 4 with DiscordAdminChannelCommandSender

use of com.solinia.solinia.Providers.DiscordAdminChannelCommandSender in project solinia3-core by mixxit.

the class CommandCommit method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player) && !(sender instanceof CommandSender)) {
        sender.sendMessage("This is a Player/Console only command");
        return false;
    }
    if (sender instanceof Player) {
        Player player = (Player) sender;
        if (!player.isOp()) {
            player.sendMessage("This is an operator only command");
            return true;
        }
    }
    sender.sendMessage("* Executing State Commit");
    try {
        StateManager.getInstance().Commit();
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        sender.sendMessage("Error: " + e.getMessage());
        return true;
    }
    if (args.length > 0 && (sender instanceof ConsoleCommandSender || sender instanceof DiscordDefaultChannelCommandSender || sender instanceof DiscordAdminChannelCommandSender)) {
        if (args[0].equals("provider")) {
            try {
                System.out.println("Recommiting all NPCs via provider");
                for (ISoliniaNPC npc : StateManager.getInstance().getConfigurationManager().getNPCs()) {
                    try {
                        npc.editSetting("name", npc.getName());
                        StateManager.getInstance().getEntityManager().getNPCEntityProvider().updateNpc(npc);
                    } catch (NumberFormatException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (InvalidNpcSettingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            } catch (CoreStateInitException e) {
            }
        }
        if (args[0].equals("patch")) {
            System.out.println("Patching");
            Utils.Patcher();
        }
    }
    sender.sendMessage("* Completed State Commit");
    return true;
}
Also used : Player(org.bukkit.entity.Player) DiscordAdminChannelCommandSender(com.solinia.solinia.Providers.DiscordAdminChannelCommandSender) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) DiscordDefaultChannelCommandSender(com.solinia.solinia.Providers.DiscordDefaultChannelCommandSender) DiscordAdminChannelCommandSender(com.solinia.solinia.Providers.DiscordAdminChannelCommandSender) DiscordDefaultChannelCommandSender(com.solinia.solinia.Providers.DiscordDefaultChannelCommandSender) InvalidNpcSettingException(com.solinia.solinia.Exceptions.InvalidNpcSettingException) IOException(java.io.IOException) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender)

Aggregations

CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)4 DiscordAdminChannelCommandSender (com.solinia.solinia.Providers.DiscordAdminChannelCommandSender)4 DiscordDefaultChannelCommandSender (com.solinia.solinia.Providers.DiscordDefaultChannelCommandSender)4 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)4 Player (org.bukkit.entity.Player)4 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)3 CommandSender (org.bukkit.command.CommandSender)3 ArrayList (java.util.ArrayList)2 InvalidNpcSettingException (com.solinia.solinia.Exceptions.InvalidNpcSettingException)1 ISoliniaClass (com.solinia.solinia.Interfaces.ISoliniaClass)1 ISoliniaNPC (com.solinia.solinia.Interfaces.ISoliniaNPC)1 ISoliniaRace (com.solinia.solinia.Interfaces.ISoliniaRace)1 IOException (java.io.IOException)1