Search in sources :

Example 1 with SoliniaRaceCreationException

use of com.solinia.solinia.Exceptions.SoliniaRaceCreationException in project solinia3-core by mixxit.

the class SoliniaRaceFactory method CreateRace.

public static ISoliniaRace CreateRace(String racename, int strength, int stamina, int agility, int dexterity, int wisdom, int intelligence, int charisma, boolean adminonly) throws CoreStateInitException, SoliniaRaceCreationException {
    if (StateManager.getInstance().getConfigurationManager().getRace(racename.toUpperCase()) != null)
        throw new SoliniaRaceCreationException("Race already exists");
    SoliniaRace race = new SoliniaRace();
    race.setId(StateManager.getInstance().getConfigurationManager().getNextRaceId());
    race.setName(racename.toUpperCase());
    race.setStrength(strength);
    race.setStamina(stamina);
    race.setAgility(agility);
    race.setDexterity(dexterity);
    race.setWisdom(wisdom);
    race.setIntelligence(intelligence);
    race.setCharisma(charisma);
    race.setAdmin(adminonly);
    StateManager.getInstance().getConfigurationManager().addRace(race);
    return race;
}
Also used : SoliniaRaceCreationException(com.solinia.solinia.Exceptions.SoliniaRaceCreationException) ISoliniaRace(com.solinia.solinia.Interfaces.ISoliniaRace) SoliniaRace(com.solinia.solinia.Models.SoliniaRace)

Example 2 with SoliniaRaceCreationException

use of com.solinia.solinia.Exceptions.SoliniaRaceCreationException in project solinia3-core by mixxit.

the class CommandAddRace 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;
        }
    }
    if (args.length < 9)
        return false;
    String racename = args[0];
    int strength = Integer.parseInt(args[1]);
    int stamina = Integer.parseInt(args[2]);
    int agility = Integer.parseInt(args[3]);
    int dexterity = Integer.parseInt(args[4]);
    int wisdom = Integer.parseInt(args[5]);
    int intelligence = Integer.parseInt(args[6]);
    int charisma = Integer.parseInt(args[7]);
    boolean adminonly = Boolean.parseBoolean(args[8]);
    try {
        ISoliniaRace race = SoliniaRaceFactory.CreateRace(racename, strength, stamina, agility, dexterity, wisdom, intelligence, charisma, adminonly);
        sender.sendMessage("* Race created [" + race.getId() + "]");
    } catch (CoreStateInitException | SoliniaRaceCreationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        sender.sendMessage("Error: " + e.getMessage());
        return true;
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) SoliniaRaceCreationException(com.solinia.solinia.Exceptions.SoliniaRaceCreationException) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) ISoliniaRace(com.solinia.solinia.Interfaces.ISoliniaRace)

Aggregations

SoliniaRaceCreationException (com.solinia.solinia.Exceptions.SoliniaRaceCreationException)2 ISoliniaRace (com.solinia.solinia.Interfaces.ISoliniaRace)2 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)1 SoliniaRace (com.solinia.solinia.Models.SoliniaRace)1 CommandSender (org.bukkit.command.CommandSender)1 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)1 Player (org.bukkit.entity.Player)1