示例#1
0
  /**
   * Edits the container and all of the children containers.
   *
   * @pre parameters != null
   * @pre canEditContainer( newContainer ) == true
   * @post if( checkCanEdit(container) ) { edit(container); }
   * @param oldContainer The original container
   * @param newContainer The new container values
   * @throws IllegalArgumentException if oldContainer == null or newContainer == null or
   *     newContainer.canEdit == false
   */
  public void editContainer(Container oldContainer, Container newContainer)
      throws IllegalArgumentException {

    if (oldContainer == null || newContainer == null || !canEditContainer(newContainer)) {
      throw new IllegalArgumentException();
    }

    System.out.println(" ------ Editing container --------");
    System.out.println("Before: " + oldContainer + "\nAfter:" + newContainer + "");

    if (oldContainer instanceof ProductGroup) {
      Container parent = oldContainer.getContainer(); // added for bug fix
      parent.getProductGroups().remove((ProductGroup) oldContainer);
      oldContainer.setName(newContainer.getName());
      ((ProductGroup) oldContainer)
          .setThreeMonthSupply(((ProductGroup) newContainer).getThreeMonthSupply());
      parent.getProductGroups().add((ProductGroup) oldContainer);
    } else {
      storageUnits.remove(oldContainer);
      oldContainer.setName(newContainer.getName());
      storageUnits.add((StorageUnit) oldContainer); // added for bug fix
    }

    containerDAO.update(new ContainerDTO(oldContainer));
    ChangeObject hint = getHintObject(oldContainer);
    setChanged();
    notifyObservers(hint);
  }
示例#2
0
 /**
  * Abstract Method, Checks to see if given productsName is unique among the list of ProductGroups.
  *
  * @pre container != null
  * @param groupName String name in question
  * @return True if all of the qualifications are met and false otherwise.
  */
 private boolean isUniqueProductGroupName(Container container) {
   assert container != null;
   if (container.getName() == null) {
     return false;
   }
   for (ProductGroup productGroup : container.getContainer().getProductGroups()) {
     if (container.getName().equals(productGroup.getName())) {
       return false;
     }
   }
   return true;
 }
  public boolean execute() {
    if (this.player == null) {
      return false;
    }

    if ((Economy.getEconomy() != null) && (this.cmdBlock.getEconomyPrice() > 0)) {
      if (!this.player.hasPermission("commandsign.costs.bypass")) {
        if (Economy.getEconomy().has(this.player, this.cmdBlock.getEconomyPrice())) {
          Economy.getEconomy().withdrawPlayer(this.player, this.cmdBlock.getEconomyPrice());
          String msg = Messages.get("usage.you_paied");
          msg =
              msg.replace("{PRICE}", Economy.getEconomy().format(this.cmdBlock.getEconomyPrice()));
          this.player.sendMessage(msg);
        } else {
          String err = Messages.get("usage.not_enough_money");
          err =
              err.replace("{PRICE}", Economy.getEconomy().format(this.cmdBlock.getEconomyPrice()));
          this.player.sendMessage(err);
          return false;
        }
      }
    }

    if (this.cmdBlock.getTimeBetweenPlayerUsage() > 0) {
      if (this.cmdBlock.hasPlayerRecentlyUsed(this.player)) {
        if (!player.hasPermission("commandsign.timer.bypass")) {
          this.player.sendMessage(Messages.get("usage.player_cooldown"));
          return false;
        }
      }
      this.cmdBlock.addUsage(this.player);
    }

    PermissionAttachment perms = Container.getContainer().getPlayerPermissions(this.player);
    for (String perm : this.cmdBlock.getPermissions()) {
      if (!this.player.hasPermission(perm)) {
        perms.setPermission(perm, true);
      }
    }

    for (String command : this.cmdBlock.getCommands()) {
      handleCommand(command);
    }

    for (String perm : this.cmdBlock.getPermissions()) {
      if (perms.getPermissions().containsKey(perm)) {
        perms.unsetPermission(perm);
      }
    }

    return true;
  }
示例#4
0
  /**
   * Deletes the container and all of the children containers.
   *
   * @pre Container.items() == 0, recursively, see condition below ***(can't assert that items == 0,
   *     have to trust)***
   * @pre container.exists() == true
   * @post delete(container), recursively
   * @param container Current container to be deleted
   * @throws IllegalArgumentException if container.container == null && container instanceof
   *     ProductGroup
   */
  public void deleteContainer(Container container) throws IllegalArgumentException {

    Container parent = container.getContainer();
    if (container instanceof ProductGroup) {
      if (parent == null) {
        throw new IllegalArgumentException();
      }
      Set<ProductGroup> productGroupList = container.getContainer().getProductGroups();
      productGroupList.remove(container);
    } else {
      storageUnits.remove(container);
    }
    ChangeObject hint;
    if (parent == null || parent.getProductGroups().isEmpty()) {
      hint = getHintObject(parent);
    } else {
      hint = getHintObject(parent.getProductGroups().iterator().next());
    }

    containerDAO.delete(new ContainerDTO(container));
    idToContainer.remove(container.getId());
    setChanged();
    notifyObservers(hint);
  }