Beispiel #1
0
 @EventHandler(priority = EventPriority.HIGH)
 public void onSSPreTransactionEvent(SSPreTransactionEvent event) {
   if (event.isCancelled() || !event.canBeCancelled()) return;
   List<String> operation = SignShopConfig.getBlocks(event.getOperation());
   if (!hasPermit(event.getOwner(), operation, event.getPlayer().getWorld())) {
     event.getPlayer().sendMessage(SignShopConfig.getError("no_permit_owner", null));
     event.setCancelled(true);
   }
 }
 @EventHandler(priority = EventPriority.HIGH)
 public void onSSBuildEvent(SSCreatedEvent event) {
   if (event.isCancelled() || !event.canBeCancelled()) return;
   List<String> operation = SignShopConfig.getBlocks(event.getOperation());
   String sOperation = event.getOperation();
   if (!operation.contains("playerIsOp")
       && !event.getPlayer().hasPerm(("SignShop.Signs." + sOperation), false)
       && !event.getPlayer().hasPerm(("SignShop.Signs.*"), false)) {
     event.getPlayer().sendMessage(SignShopConfig.getError("no_permission", null));
     event.setCancelled(true);
   }
 }
 @EventHandler(priority = EventPriority.HIGH)
 public void onSSPreTransactionEvent(SSPreTransactionEvent event) {
   if (event.isCancelled() || !event.canBeCancelled()) return;
   String sOperation = event.getOperation();
   SignShopPlayer ssPlayer = event.getPlayer();
   if (ssPlayer.hasPerm(("SignShop.DenyUse." + sOperation), false)
       && !ssPlayer.hasPerm(("SignShop.Signs." + sOperation), false)
       && !ssPlayer.hasPerm(("SignShop.Admin." + sOperation), true)) {
     ssPlayer.sendMessage(SignShopConfig.getError("no_permission_use", null));
     event.setCancelled(true);
   }
 }
Beispiel #4
0
  @Override
  public Boolean setupOperation(SignShopArguments ssArgs) {
    if (ssArgs.getContainables().isEmpty()) {
      ssArgs
          .getPlayer()
          .get()
          .sendMessage(SignShopConfig.getError("chest_missing", ssArgs.getMessageParts()));
      return false;
    }
    ItemStack[] isTotalItems = getRecords(ssArgs.getContainables().get());

    if (isTotalItems.length == 0) {
      ssArgs
          .getPlayer()
          .get()
          .sendMessage(SignShopConfig.getError("chest_empty", ssArgs.getMessageParts()));
      return false;
    }
    ssArgs.getItems().set(isTotalItems);
    ssArgs.setMessagePart("!items", itemUtil.itemStackToString(ssArgs.getItems().get()));
    return true;
  }
Beispiel #5
0
  @Override
  public Boolean checkRequirements(SignShopArguments ssArgs, Boolean activeCheck) {
    ItemStack[] isTotalItems = getRecords(ssArgs.getContainables().get());

    if (isTotalItems.length == 0) {
      ssArgs
          .getPlayer()
          .get()
          .sendMessage(SignShopConfig.getError("chest_empty", ssArgs.getMessageParts()));
      return false;
    }

    return true;
  }
  /**
   * Attempts to take all of the items defined by isItemsToTake or a simple part (1/2 of all request
   * items, 1/4, etc.)
   *
   * @param isItemsToTake Items to take as a whole or an equal part of each individual stack
   * @return A map filled with the items that can be taken which may be the same as specified by
   *     isItemsToTake or a part. Returns an empty map in case of failure.
   */
  public HashMap<ItemStack[], Double> variableAmount(ItemStack[] isItemsToTake) {
    ItemStack[] isBackup = getBackupItemStack(isItemsToTake);
    HashMap<ItemStack[], Double> returnMap = new HashMap<ItemStack[], Double>();
    returnMap.put(isItemsToTake, 1.0d);
    Boolean fromOK = hasItems(isBackup);

    if (fromOK) {
      returnMap.put(isItemsToTake, 1.0d);
      return returnMap;
    } else if (!SignShopConfig.getAllowVariableAmounts() && !fromOK) {
      returnMap.put(isItemsToTake, 0.0d);
      return returnMap;
    }
    returnMap.put(isItemsToTake, 0.0d);
    double iCount = 0;
    double tempCount;
    int i = 0;
    HashMap<ItemStack, Integer> mItemsToTake = StackToMap(isBackup);
    HashMap<ItemStack, Integer> mInventory = StackToMap(inventory.getContents());
    ItemStack[] isActual = new ItemStack[mItemsToTake.size()];
    for (Map.Entry<ItemStack, Integer> entry : mItemsToTake.entrySet()) {
      if (iCount == 0 && mInventory.containsKey(entry.getKey()))
        iCount = ((double) mInventory.get(entry.getKey()) / (double) entry.getValue());
      else if (iCount != 0 && mInventory.containsKey(entry.getKey())) {
        tempCount = ((double) mInventory.get(entry.getKey()) / (double) entry.getValue());
        if (tempCount != iCount) return returnMap;
      } else return returnMap;

      isActual[i] = itemUtil.getBackupSingleItemStack(entry.getKey());
      isActual[i].setAmount(mInventory.get(entry.getKey()));

      i++;
    }
    returnMap.clear();
    returnMap.put(isActual, iCount);
    return returnMap;
  }
Beispiel #7
0
 private boolean hasPermit(SignShopPlayer ssPlayer, List<String> operation, World world) {
   return (!SignShopConfig.getEnablePermits()
       || operation.contains("playerIsOp")
       || ssPlayer.hasPerm("SignShop.Permit", world, true));
 }