Search in sources :

Example 1 with ISoliniaClass

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

the class CommandEditClass 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 instanceof Player) {
        Player player = (Player) sender;
        if (!player.isOp()) {
            player.sendMessage("This is an operator only command");
            return false;
        }
    }
    if (args.length == 0) {
        return false;
    }
    int classid = Integer.parseInt(args[0]);
    if (args.length == 1) {
        try {
            ISoliniaClass solclass = StateManager.getInstance().getConfigurationManager().getClassObj(classid);
            if (solclass != null) {
                solclass.sendClassSettingsToSender(sender);
            } else {
                sender.sendMessage("CLASS ID doesnt exist");
            }
            return true;
        } catch (CoreStateInitException e) {
            sender.sendMessage(e.getMessage());
        }
    }
    if (args.length < 3) {
        sender.sendMessage("Insufficient arguments: classid setting value");
        return false;
    }
    String setting = args[1];
    String value = args[2];
    // a string
    if (args.length > 3 && (setting.toLowerCase().contains("text") || setting.toLowerCase().contains("description") || setting.toLowerCase().contains("title"))) {
        value = "";
        int current = 0;
        for (String entry : args) {
            current++;
            if (current <= 2)
                continue;
            value = value + entry + " ";
        }
        value = value.trim();
    }
    if (classid < 1) {
        sender.sendMessage("Invalid class id");
        return false;
    }
    try {
        if (StateManager.getInstance().getConfigurationManager().getClassObj(classid) == null) {
            sender.sendMessage("Cannot locate class id: " + classid);
            return false;
        }
        StateManager.getInstance().getConfigurationManager().editClass(classid, setting, value);
        sender.sendMessage("Updating setting on class");
    } catch (InvalidClassSettingException ne) {
        sender.sendMessage("Invalid class setting: " + ne.getMessage());
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : ISoliniaClass(com.solinia.solinia.Interfaces.ISoliniaClass) Player(org.bukkit.entity.Player) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) InvalidClassSettingException(com.solinia.solinia.Exceptions.InvalidClassSettingException) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender)

Example 2 with ISoliniaClass

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

the class SoliniaClassFactory method CreateClass.

public static ISoliniaClass CreateClass(String classname, boolean adminonly) throws CoreStateInitException, SoliniaClassCreationException {
    if (StateManager.getInstance().getConfigurationManager().getClassObj(classname.toUpperCase()) != null)
        throw new SoliniaClassCreationException("Class already exists");
    SoliniaClass classObj = new SoliniaClass();
    classObj.setId(StateManager.getInstance().getConfigurationManager().getNextClassId());
    classObj.setName(classname.toUpperCase());
    classObj.setAdmin(adminonly);
    StateManager.getInstance().getConfigurationManager().addClass(classObj);
    return classObj;
}
Also used : SoliniaClassCreationException(com.solinia.solinia.Exceptions.SoliniaClassCreationException) SoliniaClass(com.solinia.solinia.Models.SoliniaClass) ISoliniaClass(com.solinia.solinia.Interfaces.ISoliniaClass)

Example 3 with ISoliniaClass

use of com.solinia.solinia.Interfaces.ISoliniaClass 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 4 with ISoliniaClass

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

the class JsonClassRepository method reload.

@Override
public void reload() {
    List<ISoliniaClass> file = new ArrayList<ISoliniaClass>();
    try {
        Gson gson = new Gson();
        BufferedReader br = new BufferedReader(new FileReader(filePath));
        file = gson.fromJson(br, new TypeToken<List<SoliniaClass>>() {
        }.getType());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    classes.clear();
    for (ISoliniaClass i : file) {
        classes.put(i.getId(), i);
    }
    System.out.println("Reloaded " + classes.size() + " classes");
}
Also used : ISoliniaClass(com.solinia.solinia.Interfaces.ISoliniaClass) 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)

Example 5 with ISoliniaClass

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

the class ConfigurationManager method getSpellsByClassId.

@Override
public List<ISoliniaSpell> getSpellsByClassId(int classId) {
    List<ISoliniaSpell> returnSpells = new ArrayList<ISoliniaSpell>();
    ISoliniaClass classObj;
    try {
        classObj = StateManager.getInstance().getConfigurationManager().getClassObj(classId);
    } catch (CoreStateInitException e) {
        return returnSpells;
    }
    for (ISoliniaSpell spell : getSpells()) {
        boolean addSpell = false;
        for (SoliniaSpellClass spellclass : spell.getAllowedClasses()) {
            if (spellclass.getClassname().toUpperCase().equals(classObj.getName().toUpperCase())) {
                addSpell = true;
                break;
            }
        }
        if (addSpell == true)
            returnSpells.add(spell);
    }
    return returnSpells;
}
Also used : ISoliniaClass(com.solinia.solinia.Interfaces.ISoliniaClass) ISoliniaSpell(com.solinia.solinia.Interfaces.ISoliniaSpell) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ArrayList(java.util.ArrayList) SoliniaSpellClass(com.solinia.solinia.Models.SoliniaSpellClass)

Aggregations

ISoliniaClass (com.solinia.solinia.Interfaces.ISoliniaClass)11 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)7 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)5 Player (org.bukkit.entity.Player)5 ArrayList (java.util.ArrayList)4 CommandSender (org.bukkit.command.CommandSender)4 SoliniaItemException (com.solinia.solinia.Exceptions.SoliniaItemException)2 ISoliniaRace (com.solinia.solinia.Interfaces.ISoliniaRace)2 ISoliniaSpell (com.solinia.solinia.Interfaces.ISoliniaSpell)2 SoliniaSpellClass (com.solinia.solinia.Models.SoliniaSpellClass)2 Gson (com.google.gson.Gson)1 InvalidClassSettingException (com.solinia.solinia.Exceptions.InvalidClassSettingException)1 InvalidCraftSettingException (com.solinia.solinia.Exceptions.InvalidCraftSettingException)1 SoliniaClassCreationException (com.solinia.solinia.Exceptions.SoliniaClassCreationException)1 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)1 ISoliniaLootDrop (com.solinia.solinia.Interfaces.ISoliniaLootDrop)1 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)1 SoliniaClass (com.solinia.solinia.Models.SoliniaClass)1 DiscordAdminChannelCommandSender (com.solinia.solinia.Providers.DiscordAdminChannelCommandSender)1 DiscordDefaultChannelCommandSender (com.solinia.solinia.Providers.DiscordDefaultChannelCommandSender)1