Exemple #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;
  }
Exemple #2
0
 public boolean canEntityTrespassPvp(Class<? extends Entity> entity) {
   for (SegmentEntity segment : segmentsEntities) {
     if (segment.getCheckClass().isAssignableFrom(entity) && segment.getType() == EntityType.PVP) {
       return true;
     }
   }
   return false;
 }
Exemple #3
0
 public EntityType getEntityType(Class<? extends Entity> entity) {
   for (SegmentEntity segment : segmentsEntities) {
     if (segment.getCheckClass().isAssignableFrom(entity)) {
       return segment.getType();
     }
   }
   return null;
 }
  public static void checkPVP(Entity entity, Resident res, Event event) {
    if (!event.isCancelable()) {
      return;
    }

    for (SegmentEntity segment : segmentsEntity.get(entity.getClass())) {
      if (!segment.shouldAttack(entity, res)) {
        event.setCanceled(true);
      }
    }
  }
Exemple #5
0
  // TODO: Add condition check
  public boolean checkEntity(Entity entity) {
    for (SegmentEntity segment : segmentsEntities) {
      if (segment.getCheckClass().isAssignableFrom(entity.getClass())) {
        if (segment.getType() == EntityType.TRACKED) {
          if (segment.checkCondition(entity)) {
            int range = segment.getRange(entity);
            Resident owner = segment.getOwner(entity);
            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(owner, 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(owner, segment, dim, rangeBox)) {
                return true;
              }
            }
          }
        }
      }
    }
    return false;
  }
  public static boolean check(Entity entity) {
    if (entity instanceof EntityLiving) {
      if (!getFlagValueAtLocation(
          FlagType.ENTITIES,
          entity.dimension,
          (int) Math.floor(entity.posX),
          (int) Math.floor(entity.posY),
          (int) Math.floor(entity.posZ))) {
        entity.setDead();
        return true;
      }
    }

    for (SegmentEntity segment : segmentsEntity.get(entity.getClass())) {
      if (!segment.shouldExist(entity)) {
        entity.setDead();
        return true;
      }
    }

    return false;
  }
Exemple #7
0
 public boolean isEntityOwnable(Class<? extends Entity> entity) {
   for (SegmentEntity segment : segmentsEntities) {
     if (segment.getCheckClass().isAssignableFrom(entity) && segment.hasOwner()) return true;
   }
   return false;
 }
 public static Resident getOwner(Entity entity) {
   for (SegmentEntity segment : segmentsEntity.get(entity.getClass())) {
     return segment.getOwner(entity);
   }
   return null;
 }