ItemStack is;
double price = 1.0;
String[] args = data.split(";");
Shop shop = null;
if(loc == null) {
ShowCaseStandalone.slog(Level.INFO, "Showcase import: location is null, " + getClass().getName());
return null;
}
if(owner.equals("")){
ShowCaseStandalone.slog(Level.INFO, "Could not owner for shop, " + getClass().getName());
return null;
}
try {
is = Utilities.getItemStackFromString(mat + ":" + matdata);
} catch (IOException ioe) {
ShowCaseStandalone.slog(Level.INFO, "Could not load materials for shop");
ioe.printStackTrace();
return null;
}
//Based on shop type, I'm going to set basic parameters, then try to
//parse the data into those parameters. If anything fails, I'll go
//with the default parameters.
price = 1.0;
if (type.equalsIgnoreCase("infinite")) {
//data = String.valueOf(price)
//Try to parse, but ignore if I can't.
if(data != "")
try {
price = Double.parseDouble(data);
} catch (NumberFormatException nfe) {}
// new shop
shop = new SellShop(UUID.randomUUID(), owner, loc, is);
shop.setUnlimited(true);
} else if (type.equalsIgnoreCase("finite")) {
//data = itemAmount + ";" + pricePerItem; FINITE
if(args.length > 1)
try {
amount = Integer.parseInt(args[0]);
price = Double.parseDouble(args[1]);
} catch (Exception e) {}
// new shop
shop = new SellShop(UUID.randomUUID(), owner, loc, is);
} else if (type.equalsIgnoreCase("exchange")) {
amount = 0;
//data = Exchange-type;Exchange-data;buy-amount;exchange-amount;exchange-rate-left;exchange-rate-right
if(args.length >= 3)
try {
maxAmount = Integer.parseInt(args[2]);
} catch (Exception e) {}
// new shop
shop = new BuyShop(UUID.randomUUID(), owner, loc, is);
((BuyShop)shop).setMaxAmount(maxAmount);
} else if (type.equalsIgnoreCase("basic") || type.equalsIgnoreCase("tutorial")) {
amount = 0;
price = 0.0;
//No need to parse the data.
// new shop
shop = new DisplayShop(UUID.randomUUID(), owner, loc, is);
} else {
ShowCaseStandalone.slog(Level.INFO, "Could not get activity for shop, " + getClass().getName());
return null;
}
// add the rest of the data
shop.setAmount (amount );
shop.setItemStack (is );
shop.setPrice (price );
shop.setOwner (owner );
return shop;
}