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