Search in sources :

Example 6 with ISoliniaRace

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

the class JsonRaceRepository method reload.

@Override
public void reload() {
    List<ISoliniaRace> file = new ArrayList<ISoliniaRace>();
    try {
        Gson gson = new Gson();
        BufferedReader br = new BufferedReader(new FileReader(filePath));
        file = gson.fromJson(br, new TypeToken<List<SoliniaRace>>() {
        }.getType());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    races.clear();
    for (ISoliniaRace race : file) {
        races.put(race.getId(), race);
    }
    System.out.println("Reloaded " + races.size() + " races");
}
Also used : ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) Gson(com.google.gson.Gson) FileReader(java.io.FileReader) ArrayList(java.util.ArrayList) List(java.util.List) ISoliniaRace(com.solinia.solinia.Interfaces.ISoliniaRace)

Example 7 with ISoliniaRace

use of com.solinia.solinia.Interfaces.ISoliniaRace 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)

Example 8 with ISoliniaRace

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

the class CommandAddRaceClass 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 < 2)
        return false;
    String racename = args[0];
    String classname = args[1];
    try {
        ISoliniaRace race = StateManager.getInstance().getConfigurationManager().getRace(racename);
        ISoliniaClass classobj = StateManager.getInstance().getConfigurationManager().getClassObj(classname);
        if (race == null) {
            sender.sendMessage("Race does not exist");
            return false;
        }
        if (classobj == null) {
            sender.sendMessage("Class does not exist");
            return false;
        }
        if (classobj.getValidRaces() != null)
            if (classobj.getValidRaces().contains(race.getId())) {
                sender.sendMessage("Race already contains class");
                return false;
            }
        StateManager.getInstance().getConfigurationManager().addRaceClass(race.getId(), classobj.getId());
        sender.sendMessage("* Race class combination added");
        return true;
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return true;
}
Also used : ISoliniaClass(com.solinia.solinia.Interfaces.ISoliniaClass) Player(org.bukkit.entity.Player) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) ISoliniaRace(com.solinia.solinia.Interfaces.ISoliniaRace)

Aggregations

ISoliniaRace (com.solinia.solinia.Interfaces.ISoliniaRace)8 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)5 CommandSender (org.bukkit.command.CommandSender)4 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)4 Player (org.bukkit.entity.Player)4 ArrayList (java.util.ArrayList)3 SoliniaRaceCreationException (com.solinia.solinia.Exceptions.SoliniaRaceCreationException)2 ISoliniaClass (com.solinia.solinia.Interfaces.ISoliniaClass)2 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)2 Gson (com.google.gson.Gson)1 InvalidRaceSettingException (com.solinia.solinia.Exceptions.InvalidRaceSettingException)1 ISoliniaAlignment (com.solinia.solinia.Interfaces.ISoliniaAlignment)1 SoliniaRace (com.solinia.solinia.Models.SoliniaRace)1 DiscordAdminChannelCommandSender (com.solinia.solinia.Providers.DiscordAdminChannelCommandSender)1 DiscordDefaultChannelCommandSender (com.solinia.solinia.Providers.DiscordDefaultChannelCommandSender)1 BufferedReader (java.io.BufferedReader)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 HashMap (java.util.HashMap)1 List (java.util.List)1