Search in sources :

Example 1 with SoliniaCraftCreationException

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

the class SoliniaCraftFactory method Create.

public static SoliniaCraft Create(String craftname, int x, int y, int z, boolean operatorCreated) throws CoreStateInitException, SoliniaCraftCreationException {
    if (StateManager.getInstance().getConfigurationManager().getCraft(craftname.toUpperCase()) != null)
        throw new SoliniaCraftCreationException("Craft already exists");
    SoliniaCraft craft = new SoliniaCraft();
    craft.setId(StateManager.getInstance().getConfigurationManager().getNextCraftId());
    craft.setRecipeName(craftname.toUpperCase());
    craft.setItem1(x);
    craft.setItem2(y);
    craft.setOutputItem(z);
    craft.setOperatorCreated(operatorCreated);
    StateManager.getInstance().getConfigurationManager().addCraft(craft);
    return craft;
}
Also used : SoliniaCraft(com.solinia.solinia.Models.SoliniaCraft) SoliniaCraftCreationException(com.solinia.solinia.Exceptions.SoliniaCraftCreationException)

Example 2 with SoliniaCraftCreationException

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

the class CommandCreateCraft 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.hasPermission("solinia.createcraft")) {
            player.sendMessage("You do not have permission to access this command");
            return false;
        }
    }
    if (args.length < 4) {
        sender.sendMessage("Insufficient arguments: namenospaces itemid1 itemid2 outpitemid");
        return false;
    }
    String craftname = args[0].toUpperCase();
    int item1 = Integer.parseInt(args[1]);
    int item2 = Integer.parseInt(args[2]);
    int outputitem = Integer.parseInt(args[3]);
    if (craftname.equals("")) {
        sender.sendMessage("Name of Craft cannot be null");
        return false;
    }
    try {
        List<SoliniaCraft> existing = StateManager.getInstance().getConfigurationManager().getCrafts(item1, item2);
        if (existing.size() > 0) {
            sender.sendMessage("A recipe already exists that take these two items");
            return false;
        }
        SoliniaCraft craft = SoliniaCraftFactory.Create(craftname, item1, item2, outputitem, sender.isOp());
        sender.sendMessage("Created Craft: " + craft.getId());
    } catch (CoreStateInitException | SoliniaCraftCreationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) SoliniaCraft(com.solinia.solinia.Models.SoliniaCraft) CommandSender(org.bukkit.command.CommandSender) SoliniaCraftCreationException(com.solinia.solinia.Exceptions.SoliniaCraftCreationException)

Aggregations

SoliniaCraftCreationException (com.solinia.solinia.Exceptions.SoliniaCraftCreationException)2 SoliniaCraft (com.solinia.solinia.Models.SoliniaCraft)2 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)1 CommandSender (org.bukkit.command.CommandSender)1 Player (org.bukkit.entity.Player)1