Search in sources :

Example 1 with SoliniaCraft

use of com.solinia.solinia.Models.SoliniaCraft 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 SoliniaCraft

use of com.solinia.solinia.Models.SoliniaCraft in project solinia3-core by mixxit.

the class JsonCraftRepository method commit.

@Override
public void commit() {
    // TODO Auto-generated method stub
    GsonBuilder gsonbuilder = new GsonBuilder();
    // gsonbuilder.setPrettyPrinting();
    Gson gson = gsonbuilder.create();
    String jsonOutput = gson.toJson(Crafts.values(), new TypeToken<List<SoliniaCraft>>() {
    }.getType());
    try {
        File file = new File(filePath);
        if (!file.exists())
            file.createNewFile();
        FileOutputStream fileOut = new FileOutputStream(file);
        OutputStreamWriter outWriter = new OutputStreamWriter(fileOut);
        outWriter.append(jsonOutput);
        outWriter.close();
        fileOut.close();
        System.out.println("Commited " + Crafts.size() + " Crafts");
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) TypeToken(com.google.gson.reflect.TypeToken) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) Gson(com.google.gson.Gson) SoliniaCraft(com.solinia.solinia.Models.SoliniaCraft) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) File(java.io.File)

Example 3 with SoliniaCraft

use of com.solinia.solinia.Models.SoliniaCraft 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)

Example 4 with SoliniaCraft

use of com.solinia.solinia.Models.SoliniaCraft in project solinia3-core by mixxit.

the class CommandCraft method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player)) {
        return false;
    }
    Player player = (Player) sender;
    ItemStack primaryItem = player.getInventory().getItemInMainHand();
    if (primaryItem.getType().equals(Material.AIR)) {
        player.sendMessage(ChatColor.GRAY + "Empty item in primary hand. You must hold the item you want to use in your crafting recipe");
        return false;
    }
    ItemStack secondaryItem = player.getInventory().getItemInOffHand();
    if (secondaryItem.getType().equals(Material.AIR)) {
        player.sendMessage(ChatColor.GRAY + "Empty item in offhand. You must hold the item you want to use in your crafting recipe");
        return false;
    }
    if (primaryItem.getAmount() > 1) {
        player.sendMessage(ChatColor.GRAY + "Stack size in primary hand is too high (max 1)");
        return false;
    }
    if (secondaryItem.getAmount() > 1) {
        player.sendMessage(ChatColor.GRAY + "Stack size in secondary hand is too high (max 1)");
        return false;
    }
    if (!Utils.IsSoliniaItem(primaryItem)) {
        player.sendMessage("You can only create a new item from solinia items, not minecraft items");
        return true;
    }
    if (!Utils.IsSoliniaItem(secondaryItem)) {
        player.sendMessage("You can only create a new item from solinia items, not minecraft items");
        return true;
    }
    try {
        ISoliniaPlayer solPlayer = SoliniaPlayerAdapter.Adapt(player);
        ISoliniaItem primarysolItem = SoliniaItemAdapter.Adapt(primaryItem);
        ISoliniaItem secondarysolItem = SoliniaItemAdapter.Adapt(secondaryItem);
        List<SoliniaCraft> craft = StateManager.getInstance().getConfigurationManager().getCrafts(primarysolItem.getId(), secondarysolItem.getId());
        if (craft.size() < 1) {
            player.sendMessage("You do not seem to know how to make anything with these items");
            return true;
        }
        int createCount = 0;
        for (SoliniaCraft craftEntry : craft) {
            if (craftEntry.getClassId() > 0) {
                if (solPlayer.getClassObj() == null) {
                    player.sendMessage("You do not seem to know how to make anything with these items");
                    continue;
                }
                if (solPlayer.getClassObj().getId() != craftEntry.getClassId()) {
                    player.sendMessage("You do not seem to know how to make anything with these items");
                    continue;
                }
            }
            if (craftEntry.getSkilltype() != SkillType.None) {
                if (craftEntry.getMinSkill() > 0) {
                    SoliniaPlayerSkill skill = solPlayer.getSkill(craftEntry.getSkilltype().name().toUpperCase());
                    if (skill == null) {
                        player.sendMessage("You do not seem to know how to make anything with these items");
                        continue;
                    }
                    if (skill.getValue() < craftEntry.getMinSkill()) {
                        player.sendMessage("You do not seem to know how to make anything with these items");
                        continue;
                    }
                }
            }
            ISoliniaItem outputItem = StateManager.getInstance().getConfigurationManager().getItem(craftEntry.getOutputItem());
            if (outputItem != null) {
                player.getWorld().dropItemNaturally(player.getLocation(), outputItem.asItemStack());
                player.sendMessage("You fashion the items together to make something new!");
                createCount++;
                if (craftEntry.getSkilltype() != SkillType.None) {
                    solPlayer.tryIncreaseSkill(craftEntry.getSkilltype().name().toUpperCase(), 1);
                }
            }
        }
        if (createCount > 0) {
            player.getInventory().setItemInMainHand(null);
            player.getInventory().setItemInOffHand(null);
            player.updateInventory();
        }
    } catch (CoreStateInitException e) {
    } catch (SoliniaItemException e) {
        player.sendMessage("Item no longer exists");
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) SoliniaPlayerSkill(com.solinia.solinia.Models.SoliniaPlayerSkill) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) SoliniaCraft(com.solinia.solinia.Models.SoliniaCraft) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ItemStack(org.bukkit.inventory.ItemStack) SoliniaItemException(com.solinia.solinia.Exceptions.SoliniaItemException)

Example 5 with SoliniaCraft

use of com.solinia.solinia.Models.SoliniaCraft in project solinia3-core by mixxit.

the class CommandEditCraft 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.editcraft")) {
            player.sendMessage("You do not have permission to access this command");
            return false;
        }
    }
    if (args.length < 1) {
        sender.sendMessage("Insufficient arguments: craftid");
        return false;
    }
    if (args.length == 0) {
        return false;
    }
    int craftid = Integer.parseInt(args[0]);
    if (args.length == 1) {
        try {
            SoliniaCraft craft = StateManager.getInstance().getConfigurationManager().getCraft(craftid);
            if (craft != null) {
                craft.sendCraftSettingsToSender(sender);
            } else {
                sender.sendMessage("Craft ID doesnt exist");
            }
            return true;
        } catch (CoreStateInitException e) {
            sender.sendMessage(e.getMessage());
        }
    }
    if (args.length < 3) {
        sender.sendMessage("Insufficient arguments: craftid setting value");
        return false;
    }
    String setting = args[1];
    String value = args[2];
    if (craftid < 1) {
        sender.sendMessage("Invalid craftid");
        return false;
    }
    try {
        if (StateManager.getInstance().getConfigurationManager().getCraft(craftid) == null) {
            sender.sendMessage("Cannot locate craft id: " + craftid);
            return false;
        }
        /*if (StateManager.getInstance().getConfigurationManager().getCraft(craftid).isOperatorCreated() && !sender.isOp())
			{
				sender.sendMessage("This craft was op created and you are not an op. Only ops can edit op craft items");
				return false;
			}*/
        StateManager.getInstance().getConfigurationManager().editCraft(craftid, setting, value);
        sender.sendMessage("Updating setting on Craft");
    } catch (InvalidCraftSettingException ne) {
        sender.sendMessage("Invalid craft setting: " + ne.getMessage());
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        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) InvalidCraftSettingException(com.solinia.solinia.Exceptions.InvalidCraftSettingException)

Aggregations

SoliniaCraft (com.solinia.solinia.Models.SoliniaCraft)6 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)3 Player (org.bukkit.entity.Player)3 Gson (com.google.gson.Gson)2 SoliniaCraftCreationException (com.solinia.solinia.Exceptions.SoliniaCraftCreationException)2 FileNotFoundException (java.io.FileNotFoundException)2 CommandSender (org.bukkit.command.CommandSender)2 GsonBuilder (com.google.gson.GsonBuilder)1 TypeToken (com.google.gson.reflect.TypeToken)1 InvalidCraftSettingException (com.solinia.solinia.Exceptions.InvalidCraftSettingException)1 SoliniaItemException (com.solinia.solinia.Exceptions.SoliniaItemException)1 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)1 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)1 SoliniaPlayerSkill (com.solinia.solinia.Models.SoliniaPlayerSkill)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1