Package com.kellerkindt.scs.events

Examples of com.kellerkindt.scs.events.ShowCaseEvent


    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());
      }
     
     
    }
  }
View Full Code Here


    Block      block     = pie.getClickedBlock();

    Todo      todo    = scs.removeTodo(player);
    Shop       shopEvent  = scs.getShopHandler().getShop(pie.getClickedBlock());
    Shop      shopTodo  = todo != null ? todo.Shop : null;
    ShowCaseEvent  event    = null;
    String      msgSuccess  = null;
   
    if (shopEvent != null && action == Action.RIGHT_CLICK_BLOCK) {
      // interaction event
      event = new ShowCaseInteractEvent(player, shopEvent, todo, pie.getAction() == Action.RIGHT_CLICK_BLOCK);
   
     
    } else if (shopEvent != null && action == Action.LEFT_CLICK_BLOCK) {
      // info event
      event = new ShowCaseInfoEvent(player, shopEvent);
     
     
    } else if (todo != null && todo.Type == Type.CREATE && shopTodo != null) {
      // create event
      shopTodo.setLocation(block.getLocation());
      event     = new ShowCaseCreateEvent(player, shopTodo);
      msgSuccess  = Term.MESSAGE_SUCCESSFULL_CREATED.get();
     
     
    } else if (todo != null) {
      scs.msgPlayer(player, Term.ERROR_NOT_A_SHOP.get());
    }
   
   
   
    if (event != null) {     
      // dispatch event
      scs.callShowCaseEvent(event);
     
      // have to
      player.updateInventory();
     
      // send the error message
      if (event.isCancelled() && event.getCause() != null) {
        // an error occurred
        scs.msgPlayer(player, event.getCause().getMessage());

       
      } else if (!event.isCancelled() && msgSuccess != null) {
        // successfully
        scs.msgPlayer(player, msgSuccess);
      }
     
     
      /*
       *  cancel the current event so nothing else does work with the interaction,
       *  if the ShowCaseEvent was not cancelled
       */
      if (!event.isCancelled()) {
        pie.setCancelled(true);
      }
    }
  }
View Full Code Here

TOP

Related Classes of com.kellerkindt.scs.events.ShowCaseEvent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.