Package com.kellerkindt.scs.shops

Examples of com.kellerkindt.scs.shops.Shop


  @EventHandler (ignoreCancelled=true, priority=EventPriority.HIGHEST)
  public void onShowCaseItemAddEvent(ShowCaseItemAddEvent sciae) {
    if (sciae.verify()) {
     
      Player    player  = sciae.getPlayer();
      Shop    shop  = sciae.getShop();
      int      amount  = sciae.getAmount();
     
      Throwable  cause  = null;
     
      if (!scs.canManage(player, shop, false)) {
        // not enough permissions
        cause  = new InsufficientPermissionException(Term.ERROR_INSUFFICIENT_PERMISSION_ADD_ITEM.get());
       
      } else if (shop instanceof DisplayShop) {
        // you cannot add items to a display shop
        cause  = new RuntimeException(Term.ERROR_ADD_ITEMS_DISPlAY.get());
       
      } else if (shop.isUnlimited()) {
        // you cannot add items to an unlimited shop
        cause  = new RuntimeException(Term.ERROR_ADD_ITEMS_UNLIMITED.get());
      }
     
      if (cause == null) {
View Full Code Here


  @EventHandler (ignoreCancelled=true, priority=EventPriority.HIGHEST)
  public void onShowCaseMemberAddEvent(ShowCaseMemberAddEvent scmae) {
    if (scmae.verify()) {
     
      Player  player  = scmae.getPlayer();
      Shop  shop  = scmae.getShop();
     
      // not an admin and not having the permission to manage the shop as owner
      if (!scs.isAdmin(player) && !scs.canManage(player, shop, true)) {
        // cancel the event
        scmae.setCancelled(true);
View Full Code Here

  @EventHandler (ignoreCancelled=true, priority=EventPriority.HIGHEST)
  public void onShowCaseCreateEvent(ShowCaseCreateEvent scce) {
    if (scce.verify()) {
     
      Player   player    = scce.getPlayer();
      Shop  shop    = scce.getShop();
      int    itemRemove  = shop.getAmount();
     
      double  cost    = scs.getCreatePrice    (shop.getClass());
      String  permCreate  = scs.getCreatePermission  (shop.getClass());
     
      if (shop instanceof DisplayShop) {
        // if you have the permission, you do not need a item to create the shop
        if (scs.isAdminOrHasPermission(player, Properties.permCreateDisplayNoItem)) {
          itemRemove = 0;
        } else {
          itemRemove = 1;
        }
      }
     
     
      //check the permissions
      if (!scs.isAdminOrHasPermission(player, permCreate)) {
        scce.setCancelled(true);
        scce.setCause(new InsufficientPermissionException(Term.ERROR_INSUFFICIENT_PERMISSION.get()));
      }
     
      // check money
      else if (cost > 0 && !scs.getBalanceHandler().hasEnough(player.getName(), cost)) {
        scce.setCancelled(true);
        scce.setCause(new InsufficientResourcesException(Term.ERROR_INSUFFICIENT_MONEY_CREATE.get()));
      }
     
      // check the inventory
      else if (itemRemove > 0) {
        int canRemove = ItemStackUtilities.countCompatibleItemStacks(player.getInventory(), shop.getItemStack(), scs.compareItemMeta(shop.getItemStack()));
       
        if (canRemove < itemRemove) {
          // cancel the event
          scce.setCancelled(true);
          scce.setCause(new InsufficientResourcesException(Term.ERROR_INSUFFICIENT_ITEMS_CREATE.get()));
         
        } else {
          // remove the items
          ItemStackUtilities.removeFromInventory(player.getInventory(), shop.getItemStack(), itemRemove, scs.compareItemMeta(shop.getItemStack()));
        }
       
      // check if there is already a showcase
      } else if (scs.getShopHandler().isShopBlock(shop.getBlock())) {

        scce.setCancelled(true);
        scce.setCause(new RuntimeException(Term.ERROR_ALREADY_SHOWCASE.get()));
      }
     
      // has the player to many shops
      else if (scs.getShopHandler().getShopAmount(scce.getPlayer().getName()) >= Properties.maxShopAmountPerPlayer && !scs.isAdmin(scce.getPlayer())) {
        scce.setCancelled(true);
        scce.setCause(new RuntimeException(Term.ERROR_SHOP_LIMIT_EXCEEDED.get()));
      }
     
      // check black list item
      else if ((shop instanceof SellShop && (Properties.sellBlackList == Properties.sellList.contains(shop.getItemStack().getData())))
          || (shop instanceof BuyShop && (Properties.buyBlackList == Properties.buyList.contains(shop.getItemStack().getData())))){
        scce.setCancelled(true);
        scce.setCause(new InsufficientPermissionException(Term.BLACKLIST_ITEM.get()));
      }
     
      // check black list block
      else if (Properties.blockList.contains(shop.getBlock().getType().getData())) {
        scce.setCancelled(true);
        scce.setCause(new InsufficientPermissionException(Term.BLACKLIST_BLOCK.get()));
      }
     
      // check black list world
      else if (Properties.blacklistedWorlds.contains(shop.getWorld())) {
        scce.setCancelled(true);
        scce.setCause(new InsufficientPermissionException(Term.BLACKLIST_WORLD.get()));
      }
    }
  }
View Full Code Here

    Action      action    = pie.getAction();
    Player      player    = pie.getPlayer();
    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) {
View Full Code Here

       
        // iterate through
        for (Block block : event.blockList()) {
         
          // get the shop
          Shop shop = scs.getShopHandler().getShop(block);
         
          // is valid?
          if (shop != null) {
            // delete
            scs.getShopHandler().removeShop(shop);
           
            // message to the owner
            scs.msgOwner(shop, Term.MESSAGE_EXPLODED.get(shop.getItemStack().getItemMeta().getDisplayName()));
          }
        }
       
      }
    }
View Full Code Here

  @EventHandler (ignoreCancelled=true, priority=EventPriority.HIGHEST)
  public void onShowCaseItemRemoveEvent(ShowCaseItemRemoveEvent scire) {
    if (scire.verify()) {
     
      Player  player  = scire.getPlayer();
      Shop  shop  = scire.getShop();
      int    amount  = scire.getAmount();

      Throwable  cause  = null;
     
      if (!scs.canManage(player, shop, false)) {
        // not enough permissions
        cause  = new InsufficientPermissionException(Term.ERROR_INSUFFICIENT_PERMISSION_GET_ITEM.get());
       
      } else if (shop instanceof DisplayShop) {
        // you cannot add items to a display shop
        cause  = new RuntimeException(Term.ERROR_GET_DISPLAY.get());
       
      } else if (shop.isUnlimited()) {
        // you cannot add items to an unlimited shop
        cause  = new RuntimeException(Term.ERROR_ADD_ITEMS_UNLIMITED.get());
      }
     
      // limit by shop size
      else if (amount > shop.getAmount()) {
        amount = shop.getAmount();
      }
     
      if (cause == null) {
        // remove the items
        amount = ItemStackUtilities.addToInventory(player.getInventory(), scire.getItemStack(), amount);
View Full Code Here

  @EventHandler (ignoreCancelled=true, priority=EventPriority.HIGHEST)
  public void onShowCaseRemoveEvent(ShowCaseRemoveEvent scre) {
    if (scre.verify()) {
   
      Player    player    = scre.getPlayer();
      Shop    shop    = scre.getShop();
      int      notAdded  = 0;
     
      Throwable  cause    = null;
     
      if (!scs.canManage(player, shop, true)) {
        // not enough permissions
        cause = new InsufficientPermissionException(Term.ERROR_INSUFFICIENT_PERMISSION_REM_SHOWCASE.get());
       
      } else {
        // add the items from the shop
        notAdded = shop.getAmount() - ItemStackUtilities.addToInventory(player.getInventory(), shop.getItemStack(), shop.getAmount());
       
        // add also the items of the exchange shop
        if (shop instanceof ExchangeShop) {
          ExchangeShop shopEx = (ExchangeShop)shop;
         
          notAdded += shopEx.getExchangeAmount() - ItemStackUtilities.addToInventory(player.getInventory(), shopEx.getExchangeItemStack(), shopEx.getExchangeAmount());
        }
       
        if (notAdded > 0) {
          /*
           *  reduce the amount of this shop by the
           *  added amount / set it to the not added amount
           */
          shop.setAmount(notAdded);
         
          // not enough room in the inventory
          cause = new InsufficientResourcesException(Term.ERROR_INSUFFICIENT_ROOM.get());
        }
      }
View Full Code Here

    // get the block information
    Sign  sign  = (Sign)event.getBlock().getState();
    Block  behind  = Utilities.getBlockBehind(sign);
     
    // get shop
    final Shop    fShop   = scs.getShopHandler().getShop(behind);
   
    // actually... not a shop-block
    if (fShop == null) {
      return;
    }
View Full Code Here

   * @param scie  ShowCaseInfoEvent with needed information about the shop and player
   */
  @EventHandler (ignoreCancelled=true, priority=EventPriority.MONITOR// monitor is to check the outcome (http://wiki.bukkit.org/Event_API_Reference)
  public void onShowCaseInfoEvent (ShowCaseInfoEvent scie) {
    Player  player  = scie.getPlayer();
    Shop  shop  = scie.getShop();
   
   
    if (shop instanceof DisplayShop) {
      scs.msgPlayer(player, Term.ITEM_ON_DISPLAY.get(MaterialNames.getItemName(shop.getItemStack())));
    }
   
    if (!shop.isActive()) {
      scs.msgPlayer(player, Term.INFO_1.get(shop.getClass().getSimpleName()) + ", "+Term.INFO_12.get()+", "+Term.INFO_9.get(shop.getOwner()));
      return;
    }
   
    // shop type + price + owner
    scs.msgPlayer(player, String.format("%-25s  %-20s  %s",
        Term.INFO_1.get(shop.getClass().getSimpleName()),
        Term.INFO_2.get(scs.formatCurrency(shop.getPrice())),
        Term.INFO_9.get(shop.getOwner())));
   
    // buy shop item
    if (shop instanceof BuyShop) {
      BuyShop shopBuy  = (BuyShop)shop;
     
      scs.msgPlayer(player, String.format("%-30s  %s",
          Term.INFO_4.get(MaterialNames.getItemName(shop.getItemStack())),
          Term.INFO_3.get(shop.isUnlimited() ? Term.INFO_UNLIMITED.get() : String.format("%d/%d", shopBuy.getAmount(), shopBuy.getMaxAmount()))));
    }
   
    // sell shop item
    else if (shop instanceof SellShop) {     
      scs.msgPlayer(player, String.format("%-30s %s",
          Term.INFO_4.get(MaterialNames.getItemName(shop.getItemStack())),
          Term.INFO_3.get(shop.isUnlimited() ? Term.INFO_UNLIMITED.get() : String.format("%d", shop.getAmount()))));
    }
   
    // exchange shop items + enchantments
    if (shop instanceof ExchangeShop) {
      ExchangeShop shopEx  = (ExchangeShop)shop;
     
      // normal stack
      if (shopEx.getItemStack().getEnchantments().size() > 0) {
        // just show the ItemStack
        scs.msgPlayer(player, String.format("&-30s %s",
            Term.INFO_4.get(MaterialNames.getItemName(shopEx.getItemStack())),
            Term.INFO_8.get("" + shopEx.getItemStack().getEnchantments().size())));
       
       
        // list enchantments
        for (Entry<Enchantment, Integer> entry : shopEx.getItemStack().getEnchantments().entrySet()) {
          scs.msgPlayer(player, "  - "+entry.getKey().getName() +" "+entry.getValue());
        }
       
      } else {
        // just show the ItemStack
        scs.msgPlayer(player, Term.INFO_4.get(MaterialNames.getItemName(shopEx.getItemStack())));
      }
     
      // exchange stack
      if (shopEx.getExchangeItemStack().getEnchantments().size() > 0) {
        // just show the ItemStack
        scs.msgPlayer(player, String.format("&-30s %s",
            Term.INFO_4.get(MaterialNames.getItemName(shopEx.getExchangeItemStack())),
            Term.INFO_8.get("" + shopEx.getExchangeItemStack().getEnchantments().size())));
       
       
        // list enchantments
        for (Entry<Enchantment, Integer> entry : shopEx.getExchangeItemStack().getEnchantments().entrySet()) {
          scs.msgPlayer(player, "  - "+entry.getKey().getName() +" "+entry.getValue());
        }
       
      } else {
        // just show the ItemStack
        scs.msgPlayer(player, Term.INFO_4.get(MaterialNames.getItemName(shopEx.getExchangeItemStack())));
      }
     
     
    // others enchantments
    } else if (shop.getItemStack().getEnchantments().size() > 0) {
      // enchantments here
      scs.msgPlayer(player, Term.INFO_8.get("" + shop.getItemStack().getEnchantments().size()));
     
      // list enchantments
      for (Entry<Enchantment, Integer> entry : shop.getItemStack().getEnchantments().entrySet()) {
        scs.msgPlayer(player, "  - "+entry.getKey().getName() +" "+entry.getValue());
      }
    }
  }
View Full Code Here

   */
  @EventHandler (ignoreCancelled=true, priority=EventPriority.MONITOR)
  public void onShowCaseInteractEvent (ShowCaseInteractEvent scie) {
   
    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);
View Full Code Here

TOP

Related Classes of com.kellerkindt.scs.shops.Shop

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.