Пример #1
0
  /** Checking item usage for right click on entity */
  public boolean checkEntityRightClick(ItemStack item, Resident res, Entity entity) {
    for (Iterator<SegmentEntity> it = segmentsEntities.iterator(); it.hasNext(); ) {
      SegmentEntity segment = it.next();
      if (segment.getType() == EntityType.PROTECT
          && segment.getCheckClass().isAssignableFrom(entity.getClass())) {
        int dim = entity.dimension;
        int x = (int) Math.floor(entity.posX);
        int y = (int) Math.floor(entity.posY);
        int z = (int) Math.floor(entity.posZ);

        if (!hasPermission(res, segment, dim, x, y, z)) {
          return true;
        }
      }
    }

    if (item == null) return false;

    for (Iterator<SegmentItem> it = segmentsItems.iterator(); it.hasNext(); ) {
      SegmentItem segment = it.next();
      if (segment.getType() == ItemType.RIGHT_CLICK_ENTITY
          && segment.getCheckClass().isAssignableFrom(item.getItem().getClass())) {
        try {
          if (segment.checkCondition(item)) {
            int range = segment.getRange(item);
            int dim = entity.dimension;
            int x = (int) Math.floor(entity.posX);
            int y = (int) Math.floor(entity.posY);
            int z = (int) Math.floor(entity.posZ);

            if (range == 0) {
              if (!hasPermission(res, segment, dim, x, y, z)) {
                return true;
              }
            } else {
              Volume rangeBox =
                  new Volume(x - range, y - range, z - range, x + range, y + range, z + range);
              if (!hasPermission(res, segment, dim, rangeBox)) {
                return true;
              }
            }
          }
        } catch (Exception ex) {
          MyTown.instance.LOG.error(
              "Failed to check item use on {} at the player {} ({}, {}, {} | Dim: {})",
              item.getDisplayName(),
              res.getPlayerName(),
              entity.posX,
              entity.posY,
              entity.posZ,
              entity.dimension);
          MyTown.instance.LOG.error(ExceptionUtils.getStackTrace(ex));
          if (ex instanceof GetterException || ex instanceof ConditionException) {
            this.disableSegment(it, segment, ex.getMessage());
          }
        }
      }
    }
    return false;
  }
Пример #2
0
 public boolean checkTileEntity(TileEntity te) {
   for (Iterator<SegmentTileEntity> it = segmentsTiles.iterator(); it.hasNext(); ) {
     SegmentTileEntity segment = it.next();
     if (segment.getCheckClass().isAssignableFrom(te.getClass())) {
       try {
         if (segment.checkCondition(te)) {
           Volume teBox =
               new Volume(
                   segment.getX1(te),
                   segment.getY1(te),
                   segment.getZ1(te),
                   segment.getX2(te),
                   segment.getY2(te),
                   segment.getZ2(te));
           int dim = te.getWorldObj().provider.dimensionId;
           Resident owner =
               segment.hasOwner() ? Protections.instance.getOwnerForTileEntity(te) : null;
           if (!hasPermission(owner, segment, dim, teBox)) {
             return true;
           }
         }
       } catch (Exception ex) {
         MyTown.instance.LOG.error(
             "Failed to check tile entity: {} ({}, {}, {}, Dim: {})",
             te.getClass().getSimpleName(),
             te.xCoord,
             te.yCoord,
             te.zCoord,
             te.getWorldObj().provider.dimensionId);
         MyTown.instance.LOG.error(ExceptionUtils.getStackTrace(ex));
         // Disabling protection if something errors.
         if (ex instanceof GetterException || ex instanceof ConditionException) {
           this.disableSegment(it, segment, ex.getMessage());
         } else {
           MyTown.instance.LOG.error("Skipping...");
         }
       }
       return false;
     }
   }
   return false;
 }
Пример #3
0
  /** Checking item usage for left or right click on block */
  public boolean checkItem(ItemStack item, ItemType type, Resident res, BlockPos bp, int face) {

    for (Iterator<SegmentItem> it = segmentsItems.iterator(); it.hasNext(); ) {
      SegmentItem segment = it.next();
      if (segment.getType() == type
          && segment.getCheckClass().isAssignableFrom(item.getItem().getClass())) {
        ForgeDirection direction = ForgeDirection.getOrientation(face);
        if (segment.isOnAdjacent()) {
          bp =
              new BlockPos(
                  bp.getX() + direction.offsetX,
                  bp.getY() + direction.offsetY,
                  bp.getZ() + direction.offsetZ,
                  bp.getDim());
        }
        if (!segment.isDirectionalClientUpdate()) {
          direction = null;
        }
        try {
          if (segment.checkCondition(item)) {
            int range = segment.getRange(item);
            int dim = bp.getDim();
            int x = bp.getX();
            int y = bp.getY();
            int z = bp.getZ();
            boolean isProtected;

            if (range == 0) {
              isProtected = !hasPermission(res, segment, dim, x, y, z);
            } else {
              Volume rangeBox =
                  new Volume(x - range, y - range, z - range, x + range, y + range, z + range);
              isProtected = !hasPermission(res, segment, dim, rangeBox);
            }

            if (isProtected) {
              if (segment.hasClientUpdate()) {
                sendClientUpdate(
                    segment.getClientUpdateCoords(),
                    bp,
                    (EntityPlayerMP) res.getPlayer(),
                    direction);
              }
              return true;
            }
          }
        } catch (Exception ex) {
          MyTown.instance.LOG.error(
              "Failed to check item use on {} at the player {} ({})",
              item.getDisplayName(),
              res.getPlayerName(),
              bp);
          MyTown.instance.LOG.error(ExceptionUtils.getStackTrace(ex));
          if (ex instanceof GetterException || ex instanceof ConditionException) {
            this.disableSegment(it, segment, ex.getMessage());
          }
        }
      }
    }
    return false;
  }