Player player = scie.getPlayer();
Shop shop = scie.getShop();
Todo todo = scie.getTodo();
double amount = todo != null ? todo.Amount : 0;
ShowCaseEvent event = null;
// nothing to do here
if (todo == null) {
// just to be really really sure ^^
if (shop == null) {
return;
}
int quantity = player.isSneaking() ? scs.getSneakAmount(player) : 1;
// buy / sell / exchange
if (shop instanceof BuyShop) {
event = new ShowCasePlayerSellEvent(player, (BuyShop)shop, quantity);
} else if (shop instanceof SellShop) {
event = new ShowCasePlayerBuyEvent(player, (SellShop)shop, quantity);
} else if (shop instanceof ExchangeShop) {
event = new ShowCasePlayerExchangeEvent(player, (ExchangeShop)shop, quantity);
} else if (shop instanceof DisplayShop) {
event = new ShowCaseInfoEvent(player, shop);
}
} else {
switch (todo.Type) {
// add items
case ADD_ITEMS:
event = new ShowCaseItemAddEvent(player, shop, (int)amount, shop.getItemStack());
break;
// add a member
case ADD_MEMBER:
event = new ShowCaseMemberAddEvent(player, shop, todo.String);
event.setMsgSuccessfully(Term.MESSAGE_SUCCESSFULL_ADDED_MEMBER.get());
break;
// create a new shop
case CREATE:
event = new ShowCaseCreateEvent(player, shop);
event.setMsgSuccessfully(Term.MESSAGE_SUCCESSFULL_CREATED.get());
break;
// deletes a shop
case DESTROY:
event = new ShowCaseDeleteEvent(player, shop);
event.setMsgSuccessfully(Term.MESSAGE_SUCCESSFULL_DESTROYED.get());
break;
// remove items
case GET_ITEMS:
event = new ShowCaseItemRemoveEvent(player, shop, (int)amount, shop.getItemStack());
break;
// set the new limit of a shop
case LIMIT:
event = new ShowCaseLimitEvent(player, shop, (int)amount);
break;
// remove a shop
case REMOVE:
event = new ShowCaseRemoveEvent(player, shop);
event.setMsgSuccessfully(Term.MESSAGE_SUCCESSFULL_REMOVED.get());
break;
// removes a member
case REMOVE_MEMBER:
event = new ShowCaseMemberRemoveEvent(player, shop, todo.String);
event.setMsgSuccessfully(Term.MESSAGE_SUCCESSFULL_REMOVED_MEMBER.get());
break;
// sets the new owner of a shop
case SET_OWNER:
event = new ShowCaseOwnerSetEvent(player, shop, todo.String);
event.setMsgSuccessfully(Term.MESSAGE_SET_OWNER.get(todo.String));
break;
// sets the new price of a shop
case SET_PRICE:
event = new ShowCasePriceSetEvent(player, shop, amount);
break;
default:
scs.log(Level.SEVERE, "UNKNOWN TODO.TYPE - PLEASE CONTACT A DEVELOPER", false);
break;
}
}
if (event != null) {
// perform the event
scs.callShowCaseEvent(event);
// check for an error
if (event.isCancelled() && event.getCause() != null) {
// an error occurred
scs.msgPlayer(scie.getPlayer(), event.getCause().getMessage());
} else if (!event.isCancelled() && event.getMsgSuccessfully() != null) {
/// successfully
scs.msgPlayer(scie.getPlayer(), event.getMsgSuccessfully());
}
}
}