Ejemplo n.º 1
0
 public static void addProtection(Protection protection) {
   for (Segment segment : protection.segments) {
     if (segment instanceof SegmentSpecialBlock) {
       segmentsSpecialBlock.add((SegmentSpecialBlock) segment);
     } else if (segment instanceof SegmentBlock) {
       segmentsBlock.add((SegmentBlock) segment);
     } else if (segment instanceof SegmentEntity) {
       segmentsEntity.add((SegmentEntity) segment);
     } else if (segment instanceof SegmentItem) {
       segmentsItem.add((SegmentItem) segment);
     } else if (segment instanceof SegmentTileEntity) {
       segmentsTile.add((SegmentTileEntity) segment);
     }
   }
 }
Ejemplo n.º 2
0
  public static boolean checkBlockBreak(Block block) {
    for (SegmentSpecialBlock segment : segmentsSpecialBlock.get(block.getClass())) {
      if (segment.isAlwaysBreakable()) {
        return true;
      }
    }

    return false;
  }
Ejemplo n.º 3
0
  public static boolean isOwnable(Class<? extends TileEntity> clazz) {
    for (SegmentTileEntity segment : segmentsTile.get(clazz)) {
      if (segment.retainsOwner()) {
        return true;
      }
    }

    return false;
  }
Ejemplo n.º 4
0
  public static void checkBreakWithItem(ItemStack stack, Resident res, BlockPos bp, Event ev) {
    if (!ev.isCancelable()) {
      return;
    }

    for (SegmentItem segment : segmentsItem.get(stack.getItem().getClass())) {
      if (!segment.shouldBreakBlock(stack, res, bp)) {
        ev.setCanceled(true);
      }
    }
  }
Ejemplo n.º 5
0
  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);
      }
    }
  }
Ejemplo n.º 6
0
  public static void checkBlockInteraction(
      Resident res, BlockPos bp, PlayerInteractEvent.Action action, Event ev) {
    if (!ev.isCancelable()) {
      return;
    }
    World world = MinecraftServer.getServer().worldServerForDimension(bp.getDim());
    Block block = world.getBlock(bp.getX(), bp.getY(), bp.getZ());

    for (SegmentBlock segment : segmentsBlock.get(block.getClass())) {
      if (!segment.shouldInteract(res, bp, action)) {
        ev.setCanceled(true);
      }
    }
  }
Ejemplo n.º 7
0
 public static void check(TileEntity te) {
   for (SegmentTileEntity segment : segmentsTile.get(te.getClass())) {
     if (!segment.shouldExist(te)) {
       ItemStack itemStack = new ItemStack(te.getBlockType(), 1, te.getBlockMetadata());
       NBTTagCompound nbt = new NBTTagCompound();
       te.writeToNBT(nbt);
       itemStack.setTagCompound(nbt);
       WorldUtils.dropAsEntity(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord, itemStack);
       te.getWorldObj().setBlock(te.xCoord, te.yCoord, te.zCoord, Blocks.air);
       te.invalidate();
       MyTown.instance.LOG.info("TileEntity {} was ATOMICALLY DISINTEGRATED!", te.toString());
       return;
     }
   }
 }
Ejemplo n.º 8
0
  public static void checkUsage(
      ItemStack stack,
      Resident res,
      PlayerInteractEvent.Action action,
      BlockPos bp,
      int face,
      Event ev) {
    if (!ev.isCancelable()) {
      return;
    }

    for (SegmentItem segment : segmentsItem.get(stack.getItem().getClass())) {
      if (!segment.shouldInteract(stack, res, action, bp, face)) {
        ev.setCanceled(true);
      }
    }
  }
Ejemplo n.º 9
0
  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;
  }
Ejemplo n.º 10
0
 public static Resident getOwner(Entity entity) {
   for (SegmentEntity segment : segmentsEntity.get(entity.getClass())) {
     return segment.getOwner(entity);
   }
   return null;
 }