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;
}
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();
}
}
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;
}
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;
}
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;
}
Aggregations